01: /*
02: * CallerStack.java
03: *
04: * Created on 10. Juli 2003, 21:39
05: */
06:
07: package org.jzonic.jlo.formatter;
08:
09: /**
10: *
11: * @author Administrator
12: */
13: public class CallerStack extends SecurityManager {
14:
15: private static CallerStack cs = null;
16:
17: public CallerStack() {
18: }
19:
20: public static Class getCallerClass(Class clazz) {
21: if (cs == null) {
22: cs = new CallerStack();
23: }
24: Class[] stack = cs.getClassContext();
25: int idx = 0;
26: for (int i = 0; i < stack.length; i++) {
27: if (clazz.isAssignableFrom(stack[i])
28: || CallerStack.class.isAssignableFrom(stack[i])) {
29: idx++;
30: }
31: }
32: int index = stack.length;
33: if (index > 0) {
34: index--;
35: }
36: if (stack.length < idx) {
37: idx = stack.length;
38: }
39: return stack[idx];
40: }
41:
42: }
|