本文整理汇总了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");
}
}