1 22 package org.jboss.ejb3; 23 24 import org.jboss.ejb3.embedded.resource.RARDeployment; 25 import org.jboss.kernel.Kernel; 26 import org.jboss.kernel.spi.registry.KernelRegistryEntry; 27 import org.jboss.logging.Logger; 28 29 import javax.management.ObjectName ; 30 import java.lang.reflect.Field ; 31 import java.lang.reflect.Method ; 32 33 36 public class MCClientKernelAbstraction implements ClientKernelAbstraction 37 { 38 private static final Logger log = Logger.getLogger(MCClientKernelAbstraction.class); 39 40 protected Kernel kernel; 41 42 public MCClientKernelAbstraction(Kernel kernel) 43 { 44 this.kernel = kernel; 45 } 46 47 public Object invoke(ObjectName objectName, String operationName, Object [] params, String [] signature) throws Exception 48 { 49 String name = objectName.getCanonicalName(); 50 KernelRegistryEntry entry = kernel.getRegistry().getEntry(name); 51 if (entry != null) 52 { 53 Object target = entry.getTarget(); 54 if (target instanceof RARDeployment) 55 { 56 RARDeployment deployment = (RARDeployment) target; 57 return deployment.invoke(operationName, params, signature); 58 } 59 else 60 { 61 Class [] types = new Class [signature.length]; 62 for (int i = 0; i < signature.length; ++i) 63 { 64 types[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]); 65 } 66 Method method = target.getClass().getMethod(operationName, types); 67 return method.invoke(target, params); 68 } 69 } 70 return null; 71 } 72 73 public Object getAttribute(ObjectName objectName, String attribute) throws Exception 74 { 75 String name = objectName.getCanonicalName(); 76 KernelRegistryEntry entry = kernel.getRegistry().getEntry(name); 77 if (entry != null) 78 { 79 Object target = entry.getTarget(); 80 Field field = target.getClass().getField(attribute); 81 return field.get(target); 82 } 83 return null; 84 } 85 } 86 | Popular Tags |