01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb;
23:
24: import java.io.PrintWriter;
25: import java.io.StringWriter;
26: import java.lang.reflect.Method;
27: import javax.management.MBeanServer;
28: import javax.management.ObjectName;
29: import javax.management.RuntimeOperationsException;
30:
31: import org.jboss.system.ServiceMBeanSupport;
32:
33: /** The ContainerRelectionMBean implementation.
34: * @author Scott.Stark@jboss.org
35: * @version $Revision: 57209 $
36: *
37: * <p><b>Revisions:</b>
38: * <p><b>2001030 Marc Fleury:</b>
39: * <ul>
40: * <li>I wonder if this class is needed now that we are moving to an MBean per EJB.
41: * <li>In the new design the target EJB (interceptors are detached) should do this logic.
42: * FIXME: integrate this logic in the target MBean per EJB
43: * </ul>
44: */
45: public class ContainerRelection extends ServiceMBeanSupport implements
46: ContainerRelectionMBean {
47: /** Lookup the mbean located under the object name ":service=Container,jndiName=<jndiName>"
48: and invoke the getHome and getRemote interfaces and dump the methods for each
49: in an html pre block.
50: */
51: public String inspectEJB(String jndiName) {
52: MBeanServer server = getServer();
53: StringBuffer buffer = new StringBuffer();
54: try {
55: buffer.append("<pre>");
56: ObjectName containerName = new ObjectName(
57: ":service=Container,jndiName=" + jndiName);
58: Class homeClass = (Class) server.invoke(containerName,
59: "getHome", null, null);
60: buffer.append("\nHome class = " + homeClass);
61: buffer.append("\nClassLoader: "
62: + homeClass.getClassLoader());
63: buffer.append("\nCodeSource: "
64: + homeClass.getProtectionDomain().getCodeSource());
65: buffer.append("\n- Methods:");
66: Method[] homeMethods = homeClass.getMethods();
67: for (int m = 0; m < homeMethods.length; m++)
68: buffer.append("\n--- " + homeMethods[m]);
69: Class remoteClass = (Class) server.invoke(containerName,
70: "getRemote", null, null);
71: buffer.append("\nRemote class = " + remoteClass);
72: buffer.append("\n- Methods:");
73: Method[] remoteMethods = remoteClass.getMethods();
74: for (int m = 0; m < remoteMethods.length; m++)
75: buffer.append("\n--- " + remoteMethods[m]);
76: buffer.append("\n</pre>\n");
77: } catch (Throwable e) {
78: if (e instanceof RuntimeOperationsException) {
79: RuntimeOperationsException roe = (RuntimeOperationsException) e;
80: e = roe.getTargetException();
81: }
82: StringWriter sw = new StringWriter();
83: PrintWriter pw = new PrintWriter(sw);
84: e.printStackTrace(pw);
85: buffer.append(sw.toString());
86: buffer.append("\n</pre>\n");
87: }
88: return buffer.toString();
89: }
90:
91: public String getName() {
92: return "ContainerRelection";
93: }
94:
95: }
|