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.Iterator;
|
13
|
|
|
14
|
|
import org.jbind.xml.base.Compositor;
|
15
|
|
import org.jbind.xml.base.IRange;
|
16
|
|
import org.jbind.xml.base.IRef;
|
17
|
|
import org.jbind.xml.base.Range;
|
18
|
|
import org.jbind.xml.core.cmp.IComponentVisitor;
|
19
|
|
import org.jbind.xml.core.cmp.ISourceInfo;
|
20
|
|
import org.jbind.xml.core.content.IChoiceDecl;
|
21
|
|
import org.jbind.xml.core.content.IContentDesc;
|
22
|
|
import org.jbind.xml.core.content.IElemGroupDesc;
|
23
|
|
import org.jbind.xml.core.content.IUseState;
|
24
|
|
import org.jbind.xml.instance.use.ChoiceUseState;
|
25
|
|
import org.jbind.xml.msg.XmlException;
|
26
|
|
|
27
|
|
public class ChoiceDecl extends ElemGroupDecl implements IChoiceDecl {
|
28
|
|
|
29
|
496
|
public ChoiceDecl(ISourceInfo aSourceInfo, String aNamespace, String aName, IRange aRange) {
|
30
|
496
|
super(aSourceInfo, aNamespace, aName, aRange);
|
31
|
|
}
|
32
|
|
|
33
|
442
|
public IUseState createUseState(IUseState aParent) {
|
34
|
442
|
return new ChoiceUseState(this, aParent);
|
35
|
|
}
|
36
|
|
|
37
|
3
|
public String getDesc() {
|
38
|
3
|
return "choice group";
|
39
|
|
}
|
40
|
|
|
41
|
3377
|
public IRange getInnerRange(IRef aRef) {
|
42
|
3377
|
int min = 0;
|
43
|
3377
|
int max = 0;
|
44
|
3377
|
boolean isUnbounded = false;
|
45
|
3377
|
boolean first = true;
|
46
|
3377
|
for (Iterator i = iterContent(); i.hasNext(); ) {
|
47
|
14051
|
IContentDesc content = (IContentDesc)i.next();
|
48
|
14051
|
IRange r = content.getRange(aRef);
|
49
|
14051
|
if (first) {
|
50
|
3377
|
first = false;
|
51
|
3377
|
min = r.getMinOccurs();
|
52
|
3377
|
if (r.isUnbounded()) {
|
53
|
84
|
isUnbounded = true;
|
54
|
|
} else {
|
55
|
3293
|
max = r.getMaxOccurs();
|
56
|
|
}
|
57
|
|
} else {
|
58
|
10674
|
if (r.getMinOccurs() < min) {
|
59
|
350
|
min = r.getMinOccurs();
|
60
|
|
}
|
61
|
10674
|
if (r.isUnbounded()) {
|
62
|
262
|
isUnbounded = true;
|
63
|
|
} else {
|
64
|
10412
|
if (r.getMaxOccurs() > max) {
|
65
|
1091
|
max = r.getMaxOccurs();
|
66
|
|
}
|
67
|
|
}
|
68
|
|
}
|
69
|
|
}
|
70
|
3377
|
return isUnbounded ? new Range(min) : new Range(min, max);
|
71
|
|
}
|
72
|
|
|
73
|
266
|
public void accept(IComponentVisitor aVisitor) throws XmlException {
|
74
|
266
|
aVisitor.visitChoiceDeclStart(this);
|
75
|
266
|
visitSubComponents(aVisitor);
|
76
|
266
|
aVisitor.visitChoiceDeclEnd(this);
|
77
|
|
}
|
78
|
|
|
79
|
44
|
public IElemGroupDesc createReference(ISourceInfo aSourceInfo, IRange aRange) {
|
80
|
44
|
return new ElemGroupRef.ChoiceRef(aSourceInfo, aRange, this);
|
81
|
|
}
|
82
|
310
|
public IElemGroupDesc createGroup() {
|
83
|
310
|
return new ChoiceDecl(this, null, null, getRange());
|
84
|
|
}
|
85
|
2
|
public IElemGroupDesc createGroup(IRange aRange) {
|
86
|
2
|
return new ChoiceDecl(this, null, null, aRange);
|
87
|
|
}
|
88
|
|
|
89
|
1222
|
public Compositor getCompositor() {
|
90
|
1222
|
return Compositor.CHOICE;
|
91
|
|
}
|
92
|
|
|
93
|
310
|
public boolean isPointless(IElemGroupDesc aParent) {
|
94
|
310
|
return isPointlessChoice(aParent);
|
95
|
|
}
|
96
|
|
|
97
|
|
}
|
98
|
|
|