QualifierWalker.java
5.16 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.kohsuke.rngom.rngparser.digested.DChoicePattern
* org.kohsuke.rngom.rngparser.digested.DContainerPattern
* org.kohsuke.rngom.rngparser.digested.DElementPattern
* org.kohsuke.rngom.rngparser.digested.DOptionalPattern
* org.kohsuke.rngom.rngparser.digested.DPattern
* org.kohsuke.rngom.rngparser.digested.DPatternVisitor
* org.kohsuke.rngom.rngparser.digested.DUnaryPattern
* org.kohsuke.rngom.rngparser.nc.NameClass
* org.kohsuke.rngom.rngparser.nc.SimpleNameClass
*/
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.model.SchemaInfo;
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.BasePatternWalker;
import com.adobe.xmp.schema.rng.parser.traverser.BasePropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.PropertyWithQualifierWalker;
import com.adobe.xmp.schema.rng.parser.traverser.SimplePropertyWalker;
import com.adobe.xmp.schema.rng.parser.utils.RNGUtils;
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.DElementPattern;
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.DUnaryPattern;
import org.kohsuke.rngom.rngparser.nc.NameClass;
import org.kohsuke.rngom.rngparser.nc.SimpleNameClass;
class QualifierWalker
extends BasePatternWalker {
private boolean isQualifierOptional = false;
QualifierWalker(PropertyInfo propInfo, Context context) {
this.relativeDepth = -1;
this.propertyInfo = propInfo;
this.context = context;
}
public Void onChoice(DChoicePattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
Integer n = this.relativeDepth;
Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
if (this.relativeDepth != 0) {
throw new RNGUnexpectedElementFoundException("UNexpected choice pattern found while describing property.");
}
DElementPattern rdfDesc = this.getRDFDescription(p);
if (rdfDesc == null) {
SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
p.accept((DPatternVisitor)sw);
return null;
}
DPattern child = this.getChild((DUnaryPattern)rdfDesc);
if (child == null) {
throw new RNGParseException("rdf:Description should have at least 1 child");
}
this.unwrapGroup(child);
return null;
}
public Void onElement(DElementPattern p) {
Integer n = this.relativeDepth;
Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
NameClass name = p.getName();
QName qName = null;
if (!(name instanceof SimpleNameClass)) {
throw new RNGUnexpectedElementFoundException("Expected simple name class");
}
SimpleNameClass sName = (SimpleNameClass)name;
qName = sName.name;
if (RNGUtils.isElementRDFValue(qName)) {
BasePropertyWalker basePropWalker = new BasePropertyWalker(this.propertyInfo, this.context);
this.getChild((DUnaryPattern)p).accept((DPatternVisitor)basePropWalker);
} else {
PropertyInfo info = new PropertyInfo("", "", this.context.getCurrentSchemaInfo());
info.setIsQualifier(true);
info.setMandatory(!this.isQualifierOptional);
this.isQualifierOptional = false;
PropertyWithQualifierWalker propertyWithQualifierWalker = new PropertyWithQualifierWalker(info, this.context);
p.accept((DPatternVisitor)propertyWithQualifierWalker);
this.propertyInfo.addChild(info);
}
return null;
}
public Void onOptional(DOptionalPattern p) {
super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
this.isQualifierOptional = true;
return this.onUnary((DUnaryPattern)p);
}
public DElementPattern getRDFDescription(DChoicePattern p) {
int count = p.countChildren();
if (count != 2) {
return null;
}
DElementPattern rdfDesc = null;
DPattern c = this.firstChild((DContainerPattern)p);
while (c != null) {
NameClass name;
super.handleAnnotation(c, this.context, this.propertyInfo);
if (c.isElement() && (name = ((DElementPattern)c).getName()) instanceof SimpleNameClass && RNGUtils.isElementRDFDesc(((SimpleNameClass)name).name)) {
rdfDesc = (DElementPattern)c;
break;
}
c = this.getNext(c);
}
return rdfDesc;
}
}