1 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 45 public class ContainerRelection extends ServiceMBeanSupport implements ContainerRelectionMBean 46 { 47 51 public String inspectEJB(String jndiName) 52 { 53 MBeanServer server = getServer(); 54 StringBuffer buffer = new StringBuffer (); 55 try 56 { 57 buffer.append("<pre>"); 58 ObjectName containerName = new ObjectName (":service=Container,jndiName="+jndiName); 59 Class homeClass = (Class ) 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 [] homeMethods = homeClass.getMethods(); 65 for(int m = 0; m < homeMethods.length; m ++) 66 buffer.append("\n--- "+homeMethods[m]); 67 Class remoteClass = (Class ) server.invoke(containerName, "getRemote", null, null); 68 buffer.append("\nRemote class = "+remoteClass); 69 buffer.append("\n- Methods:"); 70 Method [] 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 e) 76 { 77 if( e instanceof RuntimeOperationsException ) 78 { 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 { 93 return "ContainerRelection"; 94 } 95 96 } 97 | Popular Tags |