KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > formatter > CallerStack


1 /*
2  * CallerStack.java
3  *
4  * Created on 10. Juli 2003, 21:39
5  */

6
7 package org.jzonic.jlo.formatter;
8
9 /**
10  *
11  * @author Administrator
12  */

13 public class CallerStack extends SecurityManager JavaDoc {
14     
15     private static CallerStack cs = null;
16     
17     public CallerStack() {
18     }
19     
20     public static Class JavaDoc getCallerClass(Class JavaDoc clazz) {
21         if ( cs == null ) {
22             cs = new CallerStack();
23         }
24         Class JavaDoc[] stack = cs.getClassContext();
25         int idx = 0;
26         for ( int i = 0; i < stack.length;i++) {
27             if ( clazz.isAssignableFrom(stack[i]) || CallerStack.class.isAssignableFrom(stack[i])) {
28                 idx ++;
29             }
30         }
31         int index = stack.length;
32         if ( index > 0 ) {
33             index --;
34         }
35         if ( stack.length < idx ) {
36             idx = stack.length;
37         }
38         return stack[idx];
39     }
40     
41 }
42
Popular Tags