本文整理匯總了Java中javax.imageio.metadata.IIOMetadataNode.setAttributeNode方法的典型用法代碼示例。如果您正苦於以下問題:Java IIOMetadataNode.setAttributeNode方法的具體用法?Java IIOMetadataNode.setAttributeNode怎麽用?Java IIOMetadataNode.setAttributeNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.metadata.IIOMetadataNode
的用法示例。
在下文中一共展示了IIOMetadataNode.setAttributeNode方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test1
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
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: test2
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
public static void test2() {
String name = "attr";
String oldValue = "old value";
String newValue = "new value";
Attr retAttr;
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
retAttr = parent.setAttributeNode(attrNode1);
retAttr = parent.setAttributeNode(attrNode2);
String actName = retAttr.getNodeName();
String actValue = retAttr.getValue();
if (!actName.equals(name) || !actValue.equals(oldValue)) {
throw new RuntimeException("Test 2 failed: Invalid attribute " +
"returned: " +
"(name: " + actName +
", value: " + actValue + ")");
}
}
示例3: test4
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
public static void test4() {
String name = "name";
String correctValue = "correct value";
String wrongValue = "wrong value";
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, wrongValue);
MyAttrNode attrNode2 = new MyAttrNode(name, correctValue);
parent.setAttributeNode(attrNode1);
parent.setAttributeNode(attrNode2);
Attr actAttr = parent.getAttributeNode(name);
String actValue = actAttr.getValue();
if (!actValue.equals(correctValue)) {
throw new RuntimeException("Test 4 failed: Return value is: " +
actValue);
}
}
示例4: test3
import javax.imageio.metadata.IIOMetadataNode; //導入方法依賴的package包/類
public static void test3() {
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode = new MyAttrNode("name", "value");
Attr retAttr = parent.setAttributeNode(attrNode);
if (retAttr != null) {
throw new RuntimeException("Test 3 failed: Return value is " +
"non-null");
}
}