1 7 package org.jboss.remoting.marshal; 8 9 import java.util.Map ; 10 import javax.management.MBeanServer ; 11 import org.jboss.logging.Logger; 12 import org.jboss.remoting.InvocationRequest; 13 import org.jboss.remoting.InvokerLocator; 14 import org.jboss.remoting.ServerInvocationHandler; 15 import org.jboss.remoting.ServerInvoker; 16 import org.jboss.remoting.callback.InvokerCallbackHandler; 17 import org.jboss.remoting.loading.ClassBytes; 18 import org.jboss.remoting.loading.ClassUtil; 19 20 26 public class MarshallerLoaderHandler implements ServerInvocationHandler, MarshallerLoaderConstants 27 { 28 private ServerInvoker invoker = null; 29 private MBeanServer server = null; 30 31 protected final static Logger log = Logger.getLogger(MarshallerLoaderHandler.class); 32 33 34 39 public void setMBeanServer(MBeanServer server) 40 { 41 this.server = server; 42 } 43 44 49 public void setInvoker(ServerInvoker invoker) 50 { 51 this.invoker = invoker; 52 } 53 54 62 public Object invoke(InvocationRequest invocation) 63 throws Throwable 64 { 65 Object ret = null; 66 67 Object param = invocation.getParameter(); 68 Map metadMap = invocation.getRequestPayload(); 69 String dataType = (String ) metadMap.get(InvokerLocator.DATATYPE); 70 71 log.debug("MarshallerLoaderHandler received invocation with param of " + param + " and data type of " + dataType); 72 73 if(GET_MARSHALLER_METHOD.equals(param)) 74 { 75 ret = MarshalFactory.getMarshaller(dataType); 76 } 77 else if(GET_UNMARSHALLER_METHOD.equals(param)) 78 { 79 ret = MarshalFactory.getUnMarshaller(dataType); 80 } 81 else if(LOAD_CLASS_METHOD.equals(param)) 82 { 83 String className = (String ) metadMap.get(CLASSNAME); 84 if(className != null) 85 { 86 ret = loadClassBytes(className, invoker.getClassLoader()); 87 } 88 else 89 { 90 log.error("Received invocation " + param + " to load class, but metadata map key " + CLASSNAME + 91 " contains a null value for the class name to load."); 92 } 93 } 94 else if(LOAD_MARSHALLER_METHOD.equals(param)) 95 { 96 Marshaller marshaller = MarshalFactory.getMarshaller(dataType); 98 if(marshaller != null) 99 { 100 String className = marshaller.getClass().getName(); 101 ret = loadClassBytes(className, invoker.getClassLoader()); 102 } 103 else 104 { 105 log.warn("Could not find registered marshaller for data type: " + dataType); 106 } 107 } 108 else if(LOAD_UNMARSHALLER_METHOD.equals(param)) 109 { 110 UnMarshaller unmarshaller = MarshalFactory.getUnMarshaller(dataType); 111 if(unmarshaller != null) 112 { 113 String className = unmarshaller.getClass().getName(); 114 ret = loadClassBytes(className, invoker.getClassLoader()); 115 } 116 else 117 { 118 log.warn("Could not find registered unmarshaller for data type: " + dataType); 119 } 120 } 121 else 122 { 123 log.warn("Received invocation with unknown parameter request: " + param); 124 } 125 126 127 return ret; 128 } 129 130 private Object loadClassBytes(String className, ClassLoader classLoader) 131 { 132 ClassBytes classBytes = null; 133 134 if(className != null) 135 { 136 byte[] classDefinition = ClassUtil.getClassBytes(className, classLoader); 137 classBytes = new ClassBytes(className, classDefinition); 138 } 139 return classBytes; 140 } 141 142 147 public void addListener(InvokerCallbackHandler callbackHandler) 148 { 149 } 151 152 157 public void removeListener(InvokerCallbackHandler callbackHandler) 158 { 159 } 161 } 162 | Popular Tags |