BasePatternWalker.java
8.91 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.kohsuke.rngom.rngparser.digested.DAnnotation
* org.kohsuke.rngom.rngparser.digested.DChoicePattern
* org.kohsuke.rngom.rngparser.digested.DContainerPattern
* org.kohsuke.rngom.rngparser.digested.DDataPattern
* org.kohsuke.rngom.rngparser.digested.DDefine
* org.kohsuke.rngom.rngparser.digested.DElementPattern
* org.kohsuke.rngom.rngparser.digested.DEmptyPattern
* org.kohsuke.rngom.rngparser.digested.DGrammarPattern
* org.kohsuke.rngom.rngparser.digested.DGroupPattern
* org.kohsuke.rngom.rngparser.digested.DInterleavePattern
* org.kohsuke.rngom.rngparser.digested.DListPattern
* org.kohsuke.rngom.rngparser.digested.DMixedPattern
* org.kohsuke.rngom.rngparser.digested.DNotAllowedPattern
* org.kohsuke.rngom.rngparser.digested.DOneOrMorePattern
* org.kohsuke.rngom.rngparser.digested.DOptionalPattern
* org.kohsuke.rngom.rngparser.digested.DPattern
* org.kohsuke.rngom.rngparser.digested.DPatternVisitor
* org.kohsuke.rngom.rngparser.digested.DPatternWalker
* org.kohsuke.rngom.rngparser.digested.DRefPattern
* org.kohsuke.rngom.rngparser.digested.DTextPattern
* org.kohsuke.rngom.rngparser.digested.DUnaryPattern
* org.kohsuke.rngom.rngparser.digested.DValuePattern
* org.kohsuke.rngom.rngparser.digested.DZeroOrMorePattern
*/
package com.adobe.xmp.schema.rng.parser.traverser;
import com.adobe.xmp.schema.rng.model.Context;
import com.adobe.xmp.schema.rng.model.PropertyInfo;
import com.adobe.xmp.schema.rng.parser.SchemaGenerationHandler;
import com.adobe.xmp.schema.rng.parser.annotation.AnnotationsFactory;
import com.adobe.xmp.schema.rng.parser.annotation.RNGAnnotation;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGUnexpectedElementFoundException;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import org.kohsuke.rngom.rngparser.digested.DAnnotation;
import org.kohsuke.rngom.rngparser.digested.DChoicePattern;
import org.kohsuke.rngom.rngparser.digested.DContainerPattern;
import org.kohsuke.rngom.rngparser.digested.DDataPattern;
import org.kohsuke.rngom.rngparser.digested.DDefine;
import org.kohsuke.rngom.rngparser.digested.DElementPattern;
import org.kohsuke.rngom.rngparser.digested.DEmptyPattern;
import org.kohsuke.rngom.rngparser.digested.DGrammarPattern;
import org.kohsuke.rngom.rngparser.digested.DGroupPattern;
import org.kohsuke.rngom.rngparser.digested.DInterleavePattern;
import org.kohsuke.rngom.rngparser.digested.DListPattern;
import org.kohsuke.rngom.rngparser.digested.DMixedPattern;
import org.kohsuke.rngom.rngparser.digested.DNotAllowedPattern;
import org.kohsuke.rngom.rngparser.digested.DOneOrMorePattern;
import org.kohsuke.rngom.rngparser.digested.DOptionalPattern;
import org.kohsuke.rngom.rngparser.digested.DPattern;
import org.kohsuke.rngom.rngparser.digested.DPatternVisitor;
import org.kohsuke.rngom.rngparser.digested.DPatternWalker;
import org.kohsuke.rngom.rngparser.digested.DRefPattern;
import org.kohsuke.rngom.rngparser.digested.DTextPattern;
import org.kohsuke.rngom.rngparser.digested.DUnaryPattern;
import org.kohsuke.rngom.rngparser.digested.DValuePattern;
import org.kohsuke.rngom.rngparser.digested.DZeroOrMorePattern;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
abstract class BasePatternWalker
extends DPatternWalker {
protected Context context;
protected PropertyInfo propertyInfo;
protected Integer relativeDepth;
BasePatternWalker() {
}
public Void onChoice(DChoicePattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - choice");
}
protected Void onContainer(DContainerPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element representing container");
}
public Void onData(DDataPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - data");
}
public Void onElement(DElementPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - element");
}
public Void onEmpty(DEmptyPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - empty");
}
public Void onGrammar(DGrammarPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - grammar");
}
public Void onInterleave(DInterleavePattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - interleave");
}
public Void onList(DListPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - list");
}
public Void onMixed(DMixedPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - mixed");
}
public Void onNotAllowed(DNotAllowedPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - notallowed");
}
public Void onOneOrMore(DOneOrMorePattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - oneormore");
}
public Void onOptional(DOptionalPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - optional");
}
public Void onRef(DRefPattern p) {
this.context.getSchemaGenerationHandler().startRefTraversal(p.getName());
this.handleAnnotation(p.getTarget(), this.context, this.propertyInfo);
Void x = (Void)p.getTarget().getPattern().accept((DPatternVisitor)this);
this.context.getSchemaGenerationHandler().endRefTraversal(p.getName());
return x;
}
public Void onText(DTextPattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - text");
}
public Void onValue(DValuePattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - value");
}
public Void onZeroOrMore(DZeroOrMorePattern p) {
throw new RNGUnexpectedElementFoundException("Unexpected element - zerormore");
}
protected Void onUnary(DUnaryPattern p) {
this.unwrapGroup(this.getChild(p));
return null;
}
protected void on(DPattern p) {
p.accept((DPatternVisitor)this);
}
protected void unwrapGroup(DPattern p) {
if (p instanceof DGroupPattern && p.getAnnotation() == DAnnotation.EMPTY) {
for (DPattern d : (DGroupPattern)p) {
this.on(d);
}
} else {
this.on(p);
}
}
void handleAnnotation(DPattern pattern, Context context, PropertyInfo propInfo) {
if (pattern == null) {
return;
}
DAnnotation annot = pattern.getAnnotation();
this.handleDecorators(annot, propInfo);
this.handleAnnotation(annot, context, propInfo);
}
protected void handleAnnotation(DDefine define, Context context, PropertyInfo propInfo) {
if (define == null) {
return;
}
DAnnotation annot = define.getAnnotation();
this.handleDecorators(annot, propInfo);
this.handleAnnotation(annot, context, propInfo);
}
private void handleAnnotation(DAnnotation annot, Context context, PropertyInfo propInfo) {
if (annot == null) {
return;
}
RNGAnnotation[] rngAnnotations = AnnotationsFactory.createAnnotationArray(annot);
if (rngAnnotations != null) {
for (RNGAnnotation rAnnot : rngAnnotations) {
if (rAnnot == null) continue;
rAnnot.setAnnotationData(context, propInfo);
}
}
}
private void handleDecorators(DAnnotation annot, PropertyInfo propInfo) {
if (annot == null || propInfo == null) {
return;
}
List children = annot.getChildren();
if (children == null || children.size() == 0) {
return;
}
for (Element el : children) {
if ("http://ns.adobe.com/xmp/schema/info/".equals(el.getNamespaceURI())) continue;
QName qname = new QName(el.getNamespaceURI(), el.getLocalName());
Map<String, String> decoratorValueMap = propInfo.getDecorator(qname);
NamedNodeMap nameNodeMap = el.getAttributes();
int length = nameNodeMap.getLength();
for (int i = 0; i < length; ++i) {
Node node = nameNodeMap.item(i);
decoratorValueMap.put(node.getNodeName(), node.getNodeValue());
}
}
}
protected DPattern getChild(DUnaryPattern pattern) {
DPattern child = pattern.getChild();
this.handleAnnotation(child, this.context, this.propertyInfo);
return child;
}
protected DPattern firstChild(DContainerPattern pattern) {
DPattern child = pattern.firstChild();
this.handleAnnotation(child, this.context, this.propertyInfo);
return child;
}
protected DPattern getNext(DPattern pattern) {
DPattern child = pattern.getNext();
this.handleAnnotation(child, this.context, this.propertyInfo);
return child;
}
}