01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.tomcat;
06:
07: import java.lang.reflect.Method;
08:
09: public class TomcatLoaderNaming {
10:
11: public static String getFullyQualifiedName(Object container) {
12: try {
13: Class c = container.getClass().getClassLoader().loadClass(
14: "org.apache.catalina.Container");
15: Method getName = c.getMethod("getName", new Class[] {});
16: Method getParent = c.getMethod("getParent", new Class[] {});
17:
18: StringBuffer rv = new StringBuffer();
19:
20: while (container != null) {
21: rv.insert(0, ":" + getName(getName, container));
22: container = getParent(getParent, container);
23: }
24:
25: if (rv.length() > 0) {
26: rv.delete(0, 1);
27: }
28:
29: return rv.toString();
30:
31: } catch (Exception e) {
32: throw new RuntimeException(e);
33: }
34: }
35:
36: private static String getName(Method m, Object o) throws Exception {
37: return (String) m.invoke(o, new Object[] {});
38: }
39:
40: private static Object getParent(Method m, Object o)
41: throws Exception {
42: return m.invoke(o, new Object[] {});
43: }
44:
45: }
|