SimplePropertyWalker.java
6.84 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
/*
* 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.DDataPattern$Param
* org.kohsuke.rngom.rngparser.digested.DPattern
* org.kohsuke.rngom.rngparser.digested.DTextPattern
* org.kohsuke.rngom.rngparser.digested.DValuePattern
*/
package com.adobe.xmp.schema.rng.parser.traverser;
import com.adobe.xmp.schema.rng.model.Context;
import com.adobe.xmp.schema.rng.model.DatatypeInfo;
import com.adobe.xmp.schema.rng.model.ParamInfo;
import com.adobe.xmp.schema.rng.model.ParamInfoGroup;
import com.adobe.xmp.schema.rng.model.ParamInfoImpl;
import com.adobe.xmp.schema.rng.model.PropertyInfo;
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.annotation.RNGLabelAnnotation;
import com.adobe.xmp.schema.rng.parser.constants.RNGSymbol;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGElementNotSupportedException;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
import com.adobe.xmp.schema.rng.parser.traverser.BasePatternWalker;
import java.util.List;
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.DPattern;
import org.kohsuke.rngom.rngparser.digested.DTextPattern;
import org.kohsuke.rngom.rngparser.digested.DValuePattern;
class SimplePropertyWalker
extends BasePatternWalker {
SimplePropertyWalker(PropertyInfo propertyInfo, Context context) {
this.relativeDepth = -1;
this.propertyInfo = propertyInfo;
this.context = context;
}
public Void onText(DTextPattern p) {
Integer n = this.relativeDepth;
Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
if (this.relativeDepth == 0) {
this.propertyInfo.setRawDataType(new DatatypeInfo("text", true));
return null;
}
return super.onText(p);
}
public Void onData(DDataPattern p) {
Integer n = this.relativeDepth;
Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
if (this.relativeDepth == 0) {
String type = p.getType();
this.propertyInfo.setRawDataType(new DatatypeInfo(type, true));
this.propertyInfo.setParamInfos(this.createParamInfoGroup(p));
return null;
}
return super.onData(p);
}
public Void onValue(DValuePattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
String type = p.getType();
this.propertyInfo.setRawDataType(new DatatypeInfo(type, true));
this.propertyInfo.setParamInfos(this.createParamInfoGroup(p));
return null;
}
public Void onChoice(DChoicePattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
ParamInfoGroup paramInfoGroup = this.createParamInfoGroup(p);
paramInfoGroup.setChoice(true);
this.propertyInfo.setParamInfos(paramInfoGroup);
return null;
}
private ParamInfoGroup createParamInfoGroup(DChoicePattern p) {
ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kOR);
DPattern c = this.firstChild((DContainerPattern)p);
while (c != null) {
super.handleAnnotation(c, this.context, this.propertyInfo);
ParamInfoGroup pg = null;
if (c instanceof DValuePattern) {
pg = this.createParamInfoGroup((DValuePattern)c);
} else if (c instanceof DDataPattern) {
pg = this.createParamInfoGroup((DDataPattern)c);
} else if (c instanceof DTextPattern) {
pg = this.createParamInfoGroup((DTextPattern)c);
} else if (c instanceof DChoicePattern) {
pg = this.createParamInfoGroup((DChoicePattern)c);
} else {
throw new RNGElementNotSupportedException("Only value, data, text and choice elements are supported as choices for simple property types");
}
paramInfoGroup.push(pg);
c = this.getNext(c);
}
return paramInfoGroup;
}
private ParamInfoGroup createParamInfoGroup(DValuePattern p) {
ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
RNGAnnotation[] annots = AnnotationsFactory.createAnnotationArray(p.getAnnotation());
String label = null;
if (annots != null) {
for (RNGAnnotation annot : annots) {
if (!(annot instanceof RNGLabelAnnotation)) continue;
RNGLabelAnnotation lAnnot = (RNGLabelAnnotation)annot;
label = lAnnot.getLabel();
}
}
paramInfoGroup.push(new ParamInfoImpl(RNGSymbol.constValue.name(), p.getValue(), p.getType(), label));
return paramInfoGroup;
}
private ParamInfoGroup createParamInfoGroup(DDataPattern p) {
ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
List pList = p.getParams();
if (pList.isEmpty()) {
ParamInfoImpl i = null;
if ("integer".equals(p.getType())) {
i = ParamInfoImpl.PARAM_ALL_INTEGER;
} else if ("double".equals(p.getType())) {
i = ParamInfoImpl.PARAM_ALL_DOUBLE;
} else if ("boolean".equals(p.getType())) {
i = ParamInfoImpl.PARAM_ALL_BOOLEAN;
} else if ("text".equals(p.getType())) {
i = ParamInfoImpl.PARAM_ALL_TEXT;
} else if ("date".equals(p.getType())) {
i = ParamInfoImpl.PARAM_ALL_TEXT;
} else {
throw new RNGParseException("Found unexpected data type as values for rng:choice.");
}
paramInfoGroup.push(i);
} else {
for (DDataPattern.Param param : pList) {
ParamInfoImpl i = new ParamInfoImpl(param.getName(), param.getValue());
paramInfoGroup.push(i);
}
}
return paramInfoGroup;
}
private ParamInfoGroup createParamInfoGroup(DTextPattern p) {
ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
ParamInfoImpl i = ParamInfoImpl.PARAM_ALL_TEXT;
paramInfoGroup.push(i);
return paramInfoGroup;
}
}