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.instance.use;
|
11
|
|
|
12
|
|
import org.jbind.xml.base.IHasLocation;
|
13
|
|
import org.jbind.xml.core.cmp.IUseStateIterator;
|
14
|
|
import org.jbind.xml.core.content.IContentDesc;
|
15
|
|
import org.jbind.xml.core.content.IElemDesc;
|
16
|
|
import org.jbind.xml.core.content.IElemRefOrDecl;
|
17
|
|
import org.jbind.xml.core.content.IElemUseState;
|
18
|
|
import org.jbind.xml.core.content.IUseState;
|
19
|
|
import org.jbind.xml.core.type.IAnyType;
|
20
|
|
import org.jbind.xml.msg.XmlException;
|
21
|
|
import org.jbind.xml.msg.XmlMessages;
|
22
|
|
|
23
|
|
public class UseStateIterator implements IUseStateIterator {
|
24
|
|
|
25
|
|
private IUseState myState = null;
|
26
|
|
private IElemRefOrDecl mySubstitutionHead = null;
|
27
|
|
|
28
|
1859
|
public UseStateIterator(IContentDesc aContent) {
|
29
|
1859
|
myState = aContent.createUseState(null);
|
30
|
|
}
|
31
|
|
|
32
|
2490
|
public IElemDesc getNextElemDesc(String aNamespace, String aName, IAnyType anOverloadingType, IHasLocation aHasLocation) throws XmlException {
|
33
|
2490
|
IElemUseState nextState = null;
|
34
|
|
|
35
|
2490
|
do {
|
36
|
3992
|
nextState = myState.getNextUseState(aNamespace, aName, anOverloadingType, aHasLocation);
|
37
|
3987
|
if (null == nextState) {
|
38
|
1528
|
if (myState.getUseCounter() < myState.getContentDesc().getRange().getMinOccurs()) {
|
39
|
15
|
throw new XmlException(XmlMessages.cmUnexpectedElement(aNamespace + "::" + aName, aHasLocation));
|
40
|
|
}
|
41
|
1513
|
IUseState parent = myState.getParent();
|
42
|
1513
|
if (null == parent) {
|
43
|
11
|
throw new XmlException(XmlMessages.cmUnexpectedElement(aNamespace + "::" + aName, aHasLocation));
|
44
|
|
}
|
45
|
1502
|
myState.reset();
|
46
|
1502
|
myState = parent;
|
47
|
|
}
|
48
|
3961
|
} while (null == nextState);
|
49
|
|
|
50
|
2459
|
myState = nextState;
|
51
|
|
|
52
|
2459
|
mySubstitutionHead = nextState.getSubstitutionHead();
|
53
|
|
|
54
|
2459
|
return nextState.getElemDesc();
|
55
|
|
}
|
56
|
|
|
57
|
|
/**
|
58
|
|
*
|
59
|
|
*/
|
60
|
1857
|
public void isValidEnd(IHasLocation aHasLocation) throws XmlException {
|
61
|
1857
|
for (IUseState s = myState; s != null; s = s.getParent()) {
|
62
|
3488
|
s.isValidEnd(aHasLocation);
|
63
|
|
}
|
64
|
|
}
|
65
|
|
|
66
|
2459
|
public IElemRefOrDecl getSubstitutionHead() {
|
67
|
2459
|
return mySubstitutionHead;
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|