2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 import java.util.Stack;
23 * A stack to store the parameters of a call, as well as the call stack.
26 public class CallVerificationStack extends Stack<Object> {
29 * --------------------------------------------------------------------
31 * --------------------------------------------------------------------
34 private static final long serialVersionUID = 1L;
37 private static final CallVerificationStack _instance = new CallVerificationStack();
40 * --------------------------------------------------------------------
42 * --------------------------------------------------------------------
45 // the call stack, store StackTraceElement
46 private final Stack<StackTraceElement> callStack = new Stack<StackTraceElement>();
49 * -------------------------------------------------------------------
51 * -------------------------------------------------------------------
55 * Can't be instantiated.
57 private CallVerificationStack() {
62 * -------------------------------------------------------------------
64 * -------------------------------------------------------------------
68 * Gets the singleton instance.
70 * @return the singleton instance
72 public static CallVerificationStack getInstance() {
77 * Pushes the call stack.
79 private void pushCallStack() {
80 StackTraceElement[] eles = (new Throwable()).getStackTrace();
82 for (i = 1; i < eles.length; i++) {
83 if (!eles[i].getClassName().equals(this.getClass().getName())) {
87 this.callStack.push(eles[i]);
91 * Gets the "current" calling class name.
93 * @return the "current" calling class name
95 public String getCurrentSourceClass() {
96 return this.callStack.peek().getClassName();
100 * Gets the "current" calling method name.
102 * @return the "current" calling method name
104 public String getCurrentSourceMethod() {
105 return this.callStack.peek().getMethodName();
109 * Clear the parameter stack and the call stack.
113 public void clear() {
114 this.callStack.clear();
119 public Object push(Object o) {
121 return super.push(o);
125 * Pushes a boolean onto the top of this stack.
130 public void push(boolean val) {
131 this.push(new BaseTypeWrapper(val));
135 * Pushes a char onto the top of this stack.
140 public void push(char val) {
141 this.push(new BaseTypeWrapper(val));
145 * Pushes a double onto the top of this stack.
150 public void push(double val) {
151 this.push(new BaseTypeWrapper(val));
155 * Pushes a float onto the top of this stack.
160 public void push(float val) {
161 this.push(new BaseTypeWrapper(val));
165 * Pushes an int onto the top of this stack.
170 public void push(int val) {
171 this.push(new BaseTypeWrapper(val));
175 * Pushes a long onto the top of this stack.
180 public void push(long val) {
181 this.push(new BaseTypeWrapper(val));
185 * Pushes a short onto the top of this stack.
190 public void push(short val) {
191 this.push(new BaseTypeWrapper(val));
200 public Object pop() {
201 this.callStack.pop();
210 public boolean popBoolean() {
211 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
212 Boolean value = (Boolean) wrapper.getValue();
213 return value.booleanValue();
221 public char popChar() {
222 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
223 Character value = (Character) wrapper.getValue();
224 return value.charValue();
232 public double popDouble() {
233 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
234 Double value = (Double) wrapper.getValue();
235 return value.doubleValue();
243 public float popFloat() {
244 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
245 Float value = (Float) wrapper.getValue();
246 return value.floatValue();
254 public int popInt() {
255 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
256 Integer value = (Integer) wrapper.getValue();
257 return value.intValue();
265 public long popLong() {
266 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
267 Long value = (Long) wrapper.getValue();
268 return value.longValue();
276 public short popShort() {
277 BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
278 Short value = (Short) wrapper.getValue();
279 return value.shortValue();
283 * Wrapper of base types.
285 class BaseTypeWrapper {
287 // the internal value
288 private Object value;
291 * Constructs a wrapper object for the base type <code> boolean </code> .
293 public BaseTypeWrapper(boolean val) {
294 this.value = new Boolean(val);
298 * Constructs a wrapper object for the base type <code> c </code> .
300 public BaseTypeWrapper(byte val) {
301 this.value = new Byte(val);
305 * Constructs a wrapper object for the base type <code> char </code> .
307 public BaseTypeWrapper(char val) {
308 this.value = new Character(val);
312 * Constructs a wrapper object for the base type <code> double </code> .
314 public BaseTypeWrapper(double val) {
315 this.value = new Double(val);
319 * Constructs a wrapper object for the base type <code> float </code> .
321 public BaseTypeWrapper(float val) {
322 this.value = new Float(val);
326 * Constructs a wrapper object for the base type <code> int </code> .
328 public BaseTypeWrapper(int val) {
329 this.value = new Integer(val);
333 * Constructs a wrapper object for the base type <code> long </code> .
335 public BaseTypeWrapper(long val) {
336 this.value = new Long(val);
340 * Constructs a wrapper object for the base type <code> short </code> .
342 public BaseTypeWrapper(short val) {
343 this.value = new Short(val);
347 * Gets the internal value.
349 public Object getValue() {