本文整理匯總了Java中org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR屬性的典型用法代碼示例。如果您正苦於以下問題:Java DOMException.INUSE_ATTRIBUTE_ERR屬性的具體用法?Java DOMException.INUSE_ATTRIBUTE_ERR怎麽用?Java DOMException.INUSE_ATTRIBUTE_ERR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.DOMException
的用法示例。
在下文中一共展示了DOMException.INUSE_ATTRIBUTE_ERR屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test1
public static void test1() {
IIOMetadataNode parent = new IIOMetadataNode("parent");
IIOMetadataNode elem = new IIOMetadataNode("elem");
MyAttrNode attrNode = new MyAttrNode("name", "value");
elem.setAttributeNode(attrNode);
attrNode.setOwnerElement(elem);
try {
parent.setAttributeNode(attrNode);
} catch (DOMException e) {
if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
throw new RuntimeException("Test 1 failed: " +
"Invalid exception code: " +
e.code);
}
return;
}
throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
示例2: setAttributeNode
public Attr setAttributeNode(Attr newAttr) throws DOMException {
Element owner = newAttr.getOwnerElement();
if (owner != null) {
if (owner == this) {
return null;
} else {
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
"Attribute is already in use");
}
}
IIOAttr attr;
if (newAttr instanceof IIOAttr) {
attr = (IIOAttr)newAttr;
attr.setOwnerElement(this);
} else {
attr = new IIOAttr(this,
newAttr.getName(),
newAttr.getValue());
}
Attr oldAttr = getAttributeNode(attr.getName());
if (oldAttr != null) {
removeAttributeNode(oldAttr);
}
attributes.add(attr);
return oldAttr;
}