XMPNodeCopyVisitor.java
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xmp.core.impl;
import com.adobe.xmp.core.XMPArray;
import com.adobe.xmp.core.XMPNode;
import com.adobe.xmp.core.XMPNodeVisitor;
import com.adobe.xmp.core.XMPQualifiers;
import com.adobe.xmp.core.XMPSimple;
import com.adobe.xmp.core.XMPStruct;
import java.util.Stack;
class XMPNodeCopyVisitor
implements XMPNodeVisitor {
Stack<XMPNode> stack = new Stack();
private XMPNodeCopyVisitor() {
}
public XMPNodeCopyVisitor(XMPNode root) {
this();
this.stack.push(root);
}
public void visit(XMPSimple simple) {
XMPNode root = this.stack.peek();
XMPSimple nextRoot = null;
if (root instanceof XMPStruct) {
XMPStruct struct = (XMPStruct)root;
nextRoot = struct.setSimple(simple.getNamespace(), simple.getName(), simple.getValue());
this.handleQualifiers(simple, nextRoot);
} else if (root instanceof XMPArray) {
XMPArray array = (XMPArray)root;
nextRoot = array.appendSimple(simple.getValue());
this.handleQualifiers(simple, nextRoot);
}
}
public void visit(XMPStruct struct) {
XMPNode root = this.stack.peek();
XMPStruct nextRoot = null;
if (root instanceof XMPStruct) {
XMPStruct rootAsStruct = (XMPStruct)root;
nextRoot = rootAsStruct.setStruct(struct.getNamespace(), struct.getName());
} else if (root instanceof XMPArray) {
XMPArray rootAsArray = (XMPArray)root;
nextRoot = rootAsArray.appendStruct();
}
this.visitChildren(struct, nextRoot);
this.handleQualifiers(struct, nextRoot);
}
public void visit(XMPArray array) {
XMPNode root = this.stack.peek();
XMPArray nextRoot = null;
if (root instanceof XMPStruct) {
XMPStruct rootAsStruct = (XMPStruct)root;
nextRoot = rootAsStruct.setArray(array.getNamespace(), array.getName(), array.getForm());
} else if (root instanceof XMPArray) {
XMPArray rootAsArray = (XMPArray)root;
nextRoot = rootAsArray.appendArray(array.getForm());
}
this.visitChildren(array, nextRoot);
this.handleQualifiers(array, nextRoot);
}
private void visitChildren(XMPNode node, XMPNode nextRoot) {
for (XMPNode field : node) {
this.stack.push(nextRoot);
field.accept(this);
this.stack.pop();
}
}
private void handleQualifiers(XMPNode node, XMPNode nextRoot) {
if (node.hasQualifiers()) {
this.visitChildren(node.accessQualifiers(), nextRoot.accessQualifiers());
}
}
}