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.element;
|
11
|
|
|
12
|
|
import org.jbind.xml.base.IAttribute;
|
13
|
|
import org.jbind.xml.base.IRange;
|
14
|
|
import org.jbind.xml.base.Range;
|
15
|
|
import org.jbind.xml.core.cmp.IComponent;
|
16
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
17
|
|
import org.jbind.xml.msg.XmlException;
|
18
|
|
import org.jbind.xml.msg.XmlMessages;
|
19
|
|
import org.jbind.xml.schema.cmp.ElemWildcard;
|
20
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
21
|
|
import org.jbind.xml.schema.instantiation.IElementHelper;
|
22
|
|
|
23
|
|
public class AnyElement extends Any implements IAnyElement {
|
24
|
|
|
25
|
|
private boolean myIsUnbounded = false;
|
26
|
|
private int myMin = 0;
|
27
|
|
private int myMax = 1;
|
28
|
|
|
29
|
|
|
30
|
42
|
public AnyElement(CreationParams aCreationParams) {
|
31
|
42
|
super(aCreationParams);
|
32
|
|
}
|
33
|
|
|
34
|
50
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
35
|
50
|
IAttribute res = null;
|
36
|
50
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
37
|
50
|
if ("minOccurs".equals(an)) {
|
38
|
2
|
res = new IntAttribute(anACParams);
|
39
|
2
|
myMin = res.getInt();
|
40
|
48
|
} else if ("maxOccurs".equals(an)) {
|
41
|
16
|
if ("unbounded".equals(anACParams.value)) {
|
42
|
16
|
res = new Attribute(anACParams);
|
43
|
16
|
myIsUnbounded = true;
|
44
|
|
} else {
|
45
|
0
|
res = new IntAttribute(anACParams);
|
46
|
0
|
myMax = res.getInt();
|
47
|
|
}
|
48
|
|
} else {
|
49
|
32
|
res = super.doCreateAttribute(anACParams);
|
50
|
|
}
|
51
|
50
|
return res;
|
52
|
|
}
|
53
|
|
|
54
|
0
|
public boolean isUnbounded() {
|
55
|
0
|
return myIsUnbounded;
|
56
|
|
}
|
57
|
|
|
58
|
0
|
public int getMaxOccurs() {
|
59
|
0
|
return myMax;
|
60
|
|
}
|
61
|
|
|
62
|
0
|
public int getMinOccurs() {
|
63
|
0
|
return myMin;
|
64
|
|
}
|
65
|
|
|
66
|
42
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
67
|
42
|
super.validateElement(aHelper, aViolations);
|
68
|
42
|
if (myMin < 0) {
|
69
|
0
|
aViolations.add(XmlMessages.minOccursLessThan0(this));
|
70
|
|
}
|
71
|
42
|
if (!myIsUnbounded && (myMin > myMax)) {
|
72
|
0
|
aViolations.add(XmlMessages.minOccursGreaterThanMax(this));
|
73
|
|
}
|
74
|
|
}
|
75
|
|
|
76
|
35
|
public IComponent createComponent(IElementHelper aHelper, IConstraintViolations aViolations) {
|
77
|
35
|
IRange r = myIsUnbounded ? new Range(myMin) : new Range(myMin, myMax);
|
78
|
35
|
return new ElemWildcard(this, r, getWildcard());
|
79
|
|
}
|
80
|
|
|
81
|
|
}
|
82
|
|
|