BasePropertyWalker.java
7.54 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.xmp.schema.model.ArrayType
* com.adobe.xmp.schema.model.ArrayType$ArrayForm
* org.kohsuke.rngom.rngparser.digested.DChoicePattern
* org.kohsuke.rngom.rngparser.digested.DContainerPattern
* org.kohsuke.rngom.rngparser.digested.DDataPattern
* org.kohsuke.rngom.rngparser.digested.DElementPattern
* org.kohsuke.rngom.rngparser.digested.DGroupPattern
* org.kohsuke.rngom.rngparser.digested.DPattern
* org.kohsuke.rngom.rngparser.digested.DPatternVisitor
* org.kohsuke.rngom.rngparser.digested.DTextPattern
* org.kohsuke.rngom.rngparser.digested.DUnaryPattern
* org.kohsuke.rngom.rngparser.digested.DValuePattern
*/
package com.adobe.xmp.schema.rng.parser.traverser;
import com.adobe.xmp.schema.model.ArrayType;
import com.adobe.xmp.schema.rng.model.Context;
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.constants.RNGSymbol;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGUnexpectedElementFoundException;
import com.adobe.xmp.schema.rng.parser.traverser.ArrayPropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.BasePatternWalker;
import com.adobe.xmp.schema.rng.parser.traverser.QualifierWalker;
import com.adobe.xmp.schema.rng.parser.traverser.SimplePropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.StructPropertyWalker;
import com.adobe.xmp.schema.rng.parser.utils.RNGUtils;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
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.DElementPattern;
import org.kohsuke.rngom.rngparser.digested.DGroupPattern;
import org.kohsuke.rngom.rngparser.digested.DPattern;
import org.kohsuke.rngom.rngparser.digested.DPatternVisitor;
import org.kohsuke.rngom.rngparser.digested.DTextPattern;
import org.kohsuke.rngom.rngparser.digested.DUnaryPattern;
import org.kohsuke.rngom.rngparser.digested.DValuePattern;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
class BasePropertyWalker
extends BasePatternWalker {
BasePropertyWalker(PropertyInfo propertyInfo, Context context) {
this.relativeDepth = -1;
this.propertyInfo = propertyInfo;
this.context = context;
}
@Override
public Void onChoice(DChoicePattern p) {
ArrayType.ArrayForm arr;
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
int numChild = p.countChildren();
if (numChild == 1 && p.firstChild() instanceof DChoicePattern) {
return this.onChoice((DChoicePattern)p.firstChild());
}
boolean processed = false;
if (this.firstChild((DContainerPattern)p) instanceof DElementPattern && (arr = RNGUtils.getArrayForm(RNGUtils.getSimpleName((DElementPattern)this.firstChild((DContainerPattern)p)))) != null) {
this.propertyInfo.setArrayForm(arr);
ParamInfoGroup pg = new ParamInfoGroup(ParamInfoGroup.Operator.kOR);
for (DPattern d : p) {
super.handleAnnotation(d, this.context, this.propertyInfo);
if (d instanceof DElementPattern) {
Integer[] choice = this.getChoices((DElementPattern)d);
pg.push(new ParamInfoImpl(RNGSymbol.constValue.name(), choice));
continue;
}
throw new RNGUnexpectedElementFoundException("Expected an element pattern while defining closed choice of ordered array of integer.");
}
this.propertyInfo.setParamInfos(pg);
processed = true;
}
if (!processed) {
QualifierWalker qw = new QualifierWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)qw);
}
return null;
}
@Override
public Void onElement(DElementPattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
Integer n = this.relativeDepth;
Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
QName qName = RNGUtils.getSimpleName(p);
if (RNGUtils.getArrayForm(qName) != null) {
this.propertyInfo.setArrayForm(RNGUtils.getArrayForm(qName));
ArrayPropertyWalker arrayPropertyWalker = new ArrayPropertyWalker(this.propertyInfo, this.context);
this.getChild((DUnaryPattern)p).accept((DPatternVisitor)arrayPropertyWalker);
} else if (RNGUtils.isElementRDFDesc(qName)) {
StructPropertyWalker sw = new StructPropertyWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)sw);
} else {
throw new RNGUnexpectedElementFoundException("Expected a array or struct property definition.");
}
return null;
}
@Override
public Void onData(DDataPattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)sw);
return null;
}
@Override
public Void onText(DTextPattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)sw);
return null;
}
@Override
public Void onValue(DValuePattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)sw);
return null;
}
private void addChoicetoList(List<Integer> choices, DPattern d) {
DPattern child;
super.handleAnnotation(d, this.context, this.propertyInfo);
if (!(d instanceof DElementPattern)) {
return;
}
if (RNGUtils.isElementArrayStart(RNGUtils.getSimpleName((DElementPattern)d)) && (child = this.getChild((DUnaryPattern)((DElementPattern)d))) instanceof DValuePattern) {
DValuePattern value = (DValuePattern)child;
Object convertedValue = RNGUtils.convertSimpleRawValue(value.getValue(), value.getType());
if (convertedValue instanceof Integer) {
choices.add((Integer)convertedValue);
} else {
throw new RNGParseException("Only array of type integers are supported as choice values.");
}
}
}
private Integer[] getChoices(DElementPattern patt) {
ArrayList<Integer> choices = new ArrayList<Integer>();
QName name = RNGUtils.getSimpleName(patt);
ArrayType.ArrayForm arr = RNGUtils.getArrayForm(name);
if (arr == null) {
return null;
}
DPattern p = this.getChild((DUnaryPattern)patt);
if (p instanceof DGroupPattern) {
super.handleAnnotation(p, this.context, this.propertyInfo);
for (DPattern d : (DGroupPattern)p) {
this.addChoicetoList(choices, d);
}
} else if (p instanceof DElementPattern) {
this.addChoicetoList(choices, p);
}
return choices.toArray(new Integer[0]);
}
}