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