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.Config;
|
15
|
|
import org.jbind.xml.base.Compositor;
|
16
|
|
import org.jbind.xml.base.IRange;
|
17
|
|
import org.jbind.xml.base.IRef;
|
18
|
|
import org.jbind.xml.base.Range;
|
19
|
|
import org.jbind.xml.core.cmp.IComponentVisitor;
|
20
|
|
import org.jbind.xml.core.cmp.ISourceInfo;
|
21
|
|
import org.jbind.xml.core.content.IAllDecl;
|
22
|
|
import org.jbind.xml.core.content.IContentDesc;
|
23
|
|
import org.jbind.xml.core.content.IElemGroupDesc;
|
24
|
|
import org.jbind.xml.core.content.IElemRefOrDecl;
|
25
|
|
import org.jbind.xml.core.content.IUseState;
|
26
|
|
import org.jbind.xml.instance.use.AllUseState;
|
27
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
28
|
|
import org.jbind.xml.msg.XmlException;
|
29
|
|
import org.jbind.xml.msg.XmlMessages;
|
30
|
|
|
31
|
|
public class AllDecl extends ElemGroupDecl implements IAllDecl {
|
32
|
|
|
33
|
1189
|
public AllDecl(ISourceInfo aSourceInfo, String aNamespace, String aName, IRange aRange) {
|
34
|
1189
|
super(aSourceInfo, aNamespace, aName, aRange);
|
35
|
|
}
|
36
|
|
|
37
|
28
|
public IUseState createUseState(IUseState aParent) {
|
38
|
28
|
return new AllUseState(this, aParent);
|
39
|
|
}
|
40
|
|
|
41
|
0
|
public String getDesc() {
|
42
|
0
|
return "all group";
|
43
|
|
}
|
44
|
|
|
45
|
245
|
public IRange getInnerRange(IRef aRef) {
|
46
|
245
|
int min = 0;
|
47
|
245
|
int max = 0;
|
48
|
245
|
boolean isUnbounded = false;
|
49
|
245
|
for (Iterator i = iterContent(); i.hasNext(); ) {
|
50
|
664
|
IContentDesc content = (IContentDesc)i.next();
|
51
|
664
|
IRange r = content.getRange(aRef);
|
52
|
664
|
min += r.getMinOccurs();
|
53
|
664
|
if (r.isUnbounded()) {
|
54
|
0
|
isUnbounded = true;
|
55
|
|
} else {
|
56
|
664
|
max += r.getMaxOccurs();
|
57
|
|
}
|
58
|
|
}
|
59
|
245
|
return isUnbounded ? new Range(min) : new Range(min, max);
|
60
|
|
}
|
61
|
|
|
62
|
19
|
public void validate(IConstraintViolations aViolations) {
|
63
|
19
|
super.validate(aViolations);
|
64
|
19
|
if (Config.instance.strictSchemaValidation()) {
|
65
|
0
|
for (Iterator i = iterContent(); i.hasNext(); ) {
|
66
|
0
|
IContentDesc c = (IContentDesc)i.next();
|
67
|
0
|
if (!(c instanceof IElemRefOrDecl) || c.getRange().isUnbounded() || (c.getRange().getMaxOccurs() > 1)) {
|
68
|
0
|
aViolations.add(XmlMessages.allGroupMustContainOnlySingleElements(c));
|
69
|
|
}
|
70
|
|
}
|
71
|
|
}
|
72
|
|
}
|
73
|
|
|
74
|
32
|
public void accept(IComponentVisitor aVisitor) throws XmlException {
|
75
|
32
|
aVisitor.visitAllDeclStart(this);
|
76
|
32
|
visitSubComponents(aVisitor);
|
77
|
32
|
aVisitor.visitAllDeclEnd(this);
|
78
|
|
}
|
79
|
|
|
80
|
0
|
public IElemGroupDesc createReference(ISourceInfo aSourceInfo, IRange aRange) {
|
81
|
0
|
return new ElemGroupRef.AllRef(aSourceInfo, aRange, this);
|
82
|
|
}
|
83
|
20
|
public IElemGroupDesc createGroup() {
|
84
|
20
|
return new AllDecl(this, null, null, getRange());
|
85
|
|
}
|
86
|
0
|
public IElemGroupDesc createGroup(IRange aRange) {
|
87
|
0
|
return new AllDecl(this, null, null, aRange);
|
88
|
|
}
|
89
|
|
|
90
|
22
|
public boolean isPointless(IElemGroupDesc aParent) {
|
91
|
22
|
return isPointlessAll(aParent);
|
92
|
|
}
|
93
|
|
|
94
|
863
|
public Compositor getCompositor() {
|
95
|
863
|
return Compositor.ALL;
|
96
|
|
}
|
97
|
|
}
|
98
|
|
|