KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > ContainerRelection


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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 JavaDoc;
25 import java.io.StringWriter JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import javax.management.MBeanServer JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.RuntimeOperationsException JavaDoc;
30
31 import org.jboss.system.ServiceMBeanSupport;
32
33 /** The ContainerRelectionMBean implementation.
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 37459 $
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 ContainerRelectionMBean
46 {
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 JavaDoc inspectEJB(String JavaDoc jndiName)
52    {
53       MBeanServer JavaDoc server = getServer();
54       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
55       try
56       {
57          buffer.append("<pre>");
58          ObjectName JavaDoc containerName = new ObjectName JavaDoc(":service=Container,jndiName="+jndiName);
59          Class JavaDoc homeClass = (Class JavaDoc) server.invoke(containerName, "getHome", null, null);
60          buffer.append("\nHome class = "+homeClass);
61          buffer.append("\nClassLoader: "+homeClass.getClassLoader());
62          buffer.append("\nCodeSource: "+homeClass.getProtectionDomain().getCodeSource());
63          buffer.append("\n- Methods:");
64          Method JavaDoc[] homeMethods = homeClass.getMethods();
65          for(int m = 0; m < homeMethods.length; m ++)
66             buffer.append("\n--- "+homeMethods[m]);
67          Class JavaDoc remoteClass = (Class JavaDoc) server.invoke(containerName, "getRemote", null, null);
68          buffer.append("\nRemote class = "+remoteClass);
69          buffer.append("\n- Methods:");
70          Method JavaDoc[] remoteMethods = remoteClass.getMethods();
71          for(int m = 0; m < remoteMethods.length; m ++)
72             buffer.append("\n--- "+remoteMethods[m]);
73          buffer.append("\n</pre>\n");
74       }
75       catch(Throwable JavaDoc e)
76       {
77          if( e instanceof RuntimeOperationsException JavaDoc )
78          {
79             RuntimeOperationsException JavaDoc roe = (RuntimeOperationsException JavaDoc) e;
80             e = roe.getTargetException();
81          }
82          StringWriter JavaDoc sw = new StringWriter JavaDoc();
83          PrintWriter JavaDoc pw = new PrintWriter JavaDoc(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 JavaDoc getName()
92    {
93       return "ContainerRelection";
94    }
95    
96 }
97
Popular Tags