KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > flow > java > ContinuationStack


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.flow.java;
17
18 import java.util.EmptyStackException JavaDoc;
19
20 /**
21  * Stack to store the frame information along the invocation trace.
22  *
23  * @author <a HREF="mailto:tcurdt@apache.org">Torsten Curdt</a>
24  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
25  * @version CVS $Id: ContinuationStack.java 30932 2004-07-29 17:35:38Z vgritsenko $
26  */

27 public class ContinuationStack implements java.io.Serializable JavaDoc {
28
29     private int[] istack;
30     private float[] fstack;
31     private double[] dstack;
32     private long[] lstack;
33     private Object JavaDoc[] astack;
34     private Object JavaDoc[] tstack;
35     private int iTop, fTop, dTop, lTop, aTop, tTop;
36
37     public ContinuationStack() {
38         istack = new int[10];
39         lstack = new long[5];
40         dstack = new double[5];
41         fstack = new float[5];
42         astack = new Object JavaDoc[10];
43         tstack = new Object JavaDoc[5];
44     }
45
46     public ContinuationStack(ContinuationStack parent) {
47         istack = new int[parent.istack.length];
48         lstack = new long[parent.lstack.length];
49         dstack = new double[parent.dstack.length];
50         fstack = new float[parent.fstack.length];
51         astack = new Object JavaDoc[parent.astack.length];
52         tstack = new Object JavaDoc[parent.tstack.length];
53         System.arraycopy(parent.istack, 0, istack, 0, parent.istack.length);
54         System.arraycopy(parent.lstack, 0, lstack, 0, parent.lstack.length);
55         System.arraycopy(parent.dstack, 0, dstack, 0, parent.dstack.length);
56         System.arraycopy(parent.fstack, 0, fstack, 0, parent.fstack.length);
57         System.arraycopy(parent.astack, 0, astack, 0, parent.astack.length);
58         System.arraycopy(parent.tstack, 0, tstack, 0, parent.tstack.length);
59         iTop = parent.iTop;
60         fTop = parent.fTop;
61         dTop = parent.dTop;
62         lTop = parent.lTop;
63         aTop = parent.aTop;
64         tTop = parent.tTop;
65     }
66
67     public double popDouble() {
68         if (dTop==0)
69             throw new EmptyStackException JavaDoc();
70         double d = dstack[--dTop];
71         //System.out.println("pop double "+d+" "+toString());
72
return d;
73     }
74
75     public float popFloat() {
76         if (fTop==0)
77             throw new EmptyStackException JavaDoc();
78         float f = fstack[--fTop];
79         //System.out.println("pop float "+f+" "+toString());
80
return f;
81     }
82
83     public int popInt() {
84         if (iTop==0)
85             throw new EmptyStackException JavaDoc();
86         int i = istack[--iTop];
87         //System.out.println("pop int "+i+" "+toString());
88
return i;
89     }
90
91     public long popLong() {
92         if (lTop==0)
93             throw new EmptyStackException JavaDoc();
94         long l = lstack[--lTop];
95         //System.out.println("pop long "+l+" "+toString());
96
return l;
97     }
98
99     public Object JavaDoc popObject() {
100         if (aTop==0)
101             throw new EmptyStackException JavaDoc();
102         Object JavaDoc o = astack[--aTop];
103         //System.out.println("pop object "+o+" "+toString());
104
return o;
105     }
106
107     public Object JavaDoc popReference() {
108         if (tTop==0)
109             throw new EmptyStackException JavaDoc();
110         Object JavaDoc o = tstack[--tTop];
111         //System.out.println("pop reference "+o+" "+toString());
112
return o;
113     }
114
115     public void pushDouble(double d) {
116         dstack[dTop++] = d;
117         //System.out.println("push double "+d+" "+toString());
118
if (dTop == dstack.length) {
119             double[] hlp = new double[dstack.length + 10];
120             System.arraycopy(dstack, 0, hlp, 0, dstack.length);
121             dstack = hlp;
122         }
123     }
124
125     public void pushFloat(float f) {
126         fstack[fTop++] = f;
127         //System.out.println("push float "+f+" "+toString());
128
if (fTop == fstack.length) {
129             float[] hlp = new float[fstack.length + 10];
130             System.arraycopy(fstack, 0, hlp, 0, fstack.length);
131             fstack = hlp;
132         }
133     }
134
135     public void pushInt(int i) {
136         istack[iTop++] = i;
137         //System.out.println("push int "+i+" "+toString());
138
if (iTop == istack.length) {
139             int[] hlp = new int[istack.length + 10];
140             System.arraycopy(istack, 0, hlp, 0, istack.length);
141             istack = hlp;
142         }
143     }
144
145     public void pushLong(long l) {
146         lstack[lTop++] = l;
147         //System.out.println("push long "+l+" "+toString());
148
if (lTop == lstack.length) {
149             long[] hlp = new long[lstack.length + 10];
150             System.arraycopy(lstack, 0, hlp, 0, lstack.length);
151             lstack = hlp;
152         }
153     }
154
155     public void pushObject(Object JavaDoc o) {
156         astack[aTop++] = o;
157         //System.out.println("push object "+o+" "+toString());
158
if (aTop == astack.length) {
159             Object JavaDoc[] hlp = new Object JavaDoc[astack.length + 10];
160             System.arraycopy(astack, 0, hlp, 0, astack.length);
161             astack = hlp;
162         }
163     }
164
165     public void pushReference(Object JavaDoc o) {
166         tstack[tTop++] = o;
167         //System.out.println("push reference "+o+" "+toString());
168
if (tTop == tstack.length) {
169             Object JavaDoc[] hlp = new Object JavaDoc[tstack.length + 10];
170             System.arraycopy(tstack, 0, hlp, 0, tstack.length);
171             tstack = hlp;
172         }
173     }
174
175     public String JavaDoc toString() {
176         return "i="+iTop +
177          ",l=" + lTop +
178          ",d=" + dTop +
179          ",f=" + fTop +
180          ",a=" + aTop +
181          ",t=" + tTop;
182     }
183 }
184
Popular Tags