1 7 package org.jboss.remoting.marshal; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 import org.jboss.logging.Logger; 12 import org.jboss.remoting.Client; 13 import org.jboss.remoting.InvokerLocator; 14 import org.jboss.remoting.marshal.serializable.SerializableMarshaller; 15 import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller; 16 17 22 public class MarshallerLoaderClient implements MarshallerLoaderConstants 23 { 24 protected final static Logger log = Logger.getLogger(MarshallerLoaderClient.class); 25 26 34 public static Marshaller getMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader) 35 { 36 37 Marshaller marshaller = null; 38 try 39 { 40 Marshaller loaderMarshaller = new SerializableMarshaller(); 41 UnMarshaller loaderUnMarshaller = new SerializableUnMarshaller(); 42 loaderUnMarshaller.setClassLoader(classByteLoader); 43 44 String marshallerMethodName = GET_MARSHALLER_METHOD; 45 Map metadata = new HashMap (); 46 metadata.put(InvokerLocator.DATATYPE, dataType); 47 Client loaderClient = new Client(loaderLocator); 48 loaderClient.setMarshaller(loaderMarshaller); 49 loaderClient.setUnMarshaller(loaderUnMarshaller); 50 51 Object obj = null; 52 obj = loaderClient.invoke(marshallerMethodName, metadata); 53 if(obj != null) 54 { 55 marshaller = (Marshaller) obj; 56 } 57 58 } 59 catch(Throwable e) 60 { 61 log.error("Error creating remoting client to connect to marhsaller loader.", e); 62 } 63 if(marshaller == null) 64 { 65 log.error("Can not load marshall for loader locator " + loaderLocator + "."); 66 } 67 68 return marshaller; 69 } 70 71 79 public static UnMarshaller getUnMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader) 80 { 81 82 UnMarshaller unmarshaller = null; 83 84 try 85 { 86 SerializableMarshaller loaderMarshaller = new SerializableMarshaller(); 87 SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller(); 88 loaderUnMarshaller.setClassLoader(classByteLoader); 89 90 String marshallerMethodName = GET_UNMARSHALLER_METHOD; 91 Map metadata = new HashMap (); 92 metadata.put(InvokerLocator.DATATYPE, dataType); 93 Client loaderClient = new Client(loaderLocator); 94 loaderClient.setMarshaller(loaderMarshaller); 95 loaderClient.setUnMarshaller(loaderUnMarshaller); 96 97 Object obj = null; 98 99 obj = loaderClient.invoke(marshallerMethodName, metadata); 100 if(obj != null) 101 { 102 unmarshaller = (UnMarshaller) obj; 103 } 104 } 105 catch(Throwable e) 106 { 107 log.error("Error creating remoting client to connecto to marhsaller loader.", e); 108 } 109 if(unmarshaller == null) 110 { 111 log.error("Can not load unmarshaller for loader locator " + loaderLocator + "."); 112 } 113 return unmarshaller; 114 } 115 } 116 | Popular Tags |