1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.schema.cmp;
|
11
|
|
|
12
|
|
import java.util.ArrayList;
|
13
|
|
import java.util.Iterator;
|
14
|
|
import java.util.List;
|
15
|
|
import java.util.Map;
|
16
|
|
import java.util.TreeMap;
|
17
|
|
|
18
|
|
import org.jbind.xml.base.IRange;
|
19
|
|
import org.jbind.xml.base.IRef;
|
20
|
|
import org.jbind.xml.base.ISymbolspaces;
|
21
|
|
import org.jbind.xml.base.ProcessContentsType;
|
22
|
|
import org.jbind.xml.base.Range;
|
23
|
|
import org.jbind.xml.base.Ref;
|
24
|
|
import org.jbind.xml.base.RefComparator;
|
25
|
|
import org.jbind.xml.core.cmp.IComplexContentModel;
|
26
|
|
import org.jbind.xml.core.cmp.IUseStateIterator;
|
27
|
|
import org.jbind.xml.core.cmp.IWildcard;
|
28
|
|
import org.jbind.xml.core.content.IElemDesc;
|
29
|
|
import org.jbind.xml.core.content.IElemGroupDesc;
|
30
|
|
import org.jbind.xml.core.content.IElemWildcard;
|
31
|
|
import org.jbind.xml.instance.use.EmptyUseStateIterator;
|
32
|
|
import org.jbind.xml.instance.use.UseStateIterator;
|
33
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
34
|
|
import org.jbind.xml.msg.XmlException;
|
35
|
|
import org.jbind.xml.msg.XmlMessages;
|
36
|
|
|
37
|
|
public class ComplexContentModel extends ContentModel implements IComplexContentModel {
|
38
|
|
|
39
|
|
private boolean myIsMixed = false;
|
40
|
|
|
41
|
|
/**
|
42
|
|
* <i>(optional)</i>.
|
43
|
|
*/
|
44
|
|
private IElemGroupDesc myGroup = null;
|
45
|
|
|
46
|
|
private Map myElemRefOrDecls = new TreeMap(RefComparator.INSTANCE);
|
47
|
|
|
48
|
|
private List myElemWildcards = new ArrayList();
|
49
|
|
|
50
|
454
|
public ComplexContentModel() {}
|
51
|
|
|
52
|
454
|
public void setIsMixed(boolean aBoolean) {
|
53
|
454
|
myIsMixed = aBoolean;
|
54
|
|
}
|
55
|
|
|
56
|
|
|
57
|
431
|
public boolean isMixed() {
|
58
|
431
|
return myIsMixed;
|
59
|
|
}
|
60
|
|
|
61
|
|
|
62
|
1109
|
public IElemGroupDesc getGroup() {
|
63
|
1109
|
return myGroup;
|
64
|
|
}
|
65
|
|
|
66
|
|
|
67
|
446
|
public void setGroup(IElemGroupDesc aGroup) {
|
68
|
446
|
myGroup = aGroup;
|
69
|
|
}
|
70
|
|
|
71
|
|
|
72
|
0
|
public boolean isSimple() {
|
73
|
0
|
return false;
|
74
|
|
}
|
75
|
|
|
76
|
|
|
77
|
370
|
public boolean isEmpty() {
|
78
|
370
|
return null == myGroup;
|
79
|
|
}
|
80
|
|
|
81
|
|
|
82
|
784
|
public boolean isComplex() {
|
83
|
784
|
return true;
|
84
|
|
}
|
85
|
|
|
86
|
|
|
87
|
2626
|
public Iterator iterElements() {
|
88
|
2626
|
return myElemRefOrDecls.values().iterator();
|
89
|
|
}
|
90
|
|
|
91
|
440
|
public void validate(IConstraintViolations aViolations) {
|
92
|
440
|
if (null != myGroup) {
|
93
|
340
|
myGroup.collectElemDescs(myElemRefOrDecls, myElemWildcards, aViolations);
|
94
|
|
}
|
95
|
|
}
|
96
|
|
|
97
|
0
|
public int getMaxOccurs(IRef aRef) {
|
98
|
0
|
IRange r = getRange(aRef);
|
99
|
0
|
return r.isUnbounded() ? Integer.MAX_VALUE : r.getMaxOccurs();
|
100
|
|
}
|
101
|
|
|
102
|
2100
|
public IUseStateIterator createUseIterator() {
|
103
|
2100
|
IUseStateIterator res = null;
|
104
|
2100
|
if (null != myGroup) {
|
105
|
1859
|
res = new UseStateIterator(myGroup);
|
106
|
|
} else {
|
107
|
241
|
res = EmptyUseStateIterator.INSTANCE;
|
108
|
|
}
|
109
|
2100
|
return res;
|
110
|
|
}
|
111
|
|
|
112
|
2691
|
public IRange getRange(IRef aRef) {
|
113
|
2691
|
return (null != myGroup) ? myGroup.getRange(aRef) : Range.ZERO;
|
114
|
|
}
|
115
|
|
|
116
|
6
|
public IElemDesc getElemDesc(String aNamespace, String aName) throws XmlException {
|
117
|
6
|
IElemDesc res = null;
|
118
|
6
|
Ref ref = new Ref(aNamespace, ISymbolspaces.ELEMENT, aName);
|
119
|
6
|
res = (IElemDesc)myElemRefOrDecls.get(ref);
|
120
|
6
|
if (null == res) {
|
121
|
0
|
for (Iterator i = myElemWildcards.iterator(); i.hasNext(); ) {
|
122
|
0
|
IElemWildcard ew = (IElemWildcard)i.next();
|
123
|
0
|
IWildcard w = ew.getWildcard();
|
124
|
0
|
if (w.isAllowed(aNamespace)) {
|
125
|
0
|
res = (IElemDesc)Schemas.getInstance().getComponent(ref);
|
126
|
0
|
if (null == res) {
|
127
|
0
|
if (ProcessContentsType.STRICT.equals(w.getProcessContentsType())) {
|
128
|
0
|
throw new XmlException(XmlMessages.cvcWildcard2(ref, null));
|
129
|
|
} else {
|
130
|
0
|
res = ew;
|
131
|
|
}
|
132
|
|
}
|
133
|
|
}
|
134
|
|
}
|
135
|
|
}
|
136
|
6
|
return res;
|
137
|
|
}
|
138
|
|
|
139
|
4068
|
public boolean canContainText() {
|
140
|
4068
|
return myIsMixed;
|
141
|
|
}
|
142
|
|
|
143
|
2
|
public Iterator iterElemWildcards() {
|
144
|
2
|
return myElemWildcards.iterator();
|
145
|
|
}
|
146
|
|
}
|
147
|
|
|