1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.exolab.castor.xml.parsing;
17
18 import java.util.Stack;
19
20 import org.exolab.castor.xml.UnmarshalState;
21
22
23
24
25
26
27
28
29 public class UnmarshalStateStack {
30
31
32
33
34 private Stack<UnmarshalState> _unmarshalStates = new Stack<UnmarshalState>();
35
36
37
38
39 private Integer parentStateIndex = null;
40
41
42
43
44
45
46
47 public UnmarshalState getLastState() {
48 return _unmarshalStates.peek();
49 }
50
51
52
53
54
55
56 public UnmarshalState removeLastState() {
57 return _unmarshalStates.pop();
58 }
59
60
61
62
63
64
65 public boolean isEmpty() {
66 return _unmarshalStates.empty();
67 }
68
69
70
71
72
73
74 public void pushState(UnmarshalState state) {
75 _unmarshalStates.push(state);
76 }
77
78
79
80
81
82
83 public boolean hasAnotherParentState() {
84 if (parentStateIndex == null) {
85 parentStateIndex = _unmarshalStates.size() - 2;
86 }
87 return parentStateIndex >= 0;
88 }
89
90
91
92
93
94
95 public UnmarshalState removeParentState() {
96 Integer tmpParentIndex = parentStateIndex;
97 parentStateIndex--;
98 return _unmarshalStates.elementAt(tmpParentIndex);
99 }
100
101 public UnmarshalState peekAtState(Integer index) {
102 return _unmarshalStates.elementAt(index);
103 }
104
105 public UnmarshalState getFirstParentState() {
106 return _unmarshalStates.elementAt(getFirstParentStateIndex());
107 }
108
109 public Integer getFirstParentStateIndex() {
110 return (parentStateIndex == null) ? _unmarshalStates.size() -2 : parentStateIndex;
111 }
112
113 public Integer size() {
114 return _unmarshalStates.size();
115 }
116
117 public void resetParentState() {
118 this.parentStateIndex = null;
119 }
120
121 }