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.InvokerLocator; 13 import org.jboss.remoting.transport.Connector; 14 15 20 public class MarshallLoaderFactory 21 { 22 protected final static Logger log = Logger.getLogger(MarshallLoaderFactory.class); 23 24 32 public static Connector createMarshallLoader(InvokerLocator locator) 33 { 34 Connector marshallerConnector = null; 35 try 36 { 37 marshallerConnector = new MarshallLoaderConnector(); 38 marshallerConnector.setInvokerLocator(locator.getLocatorURI()); 39 marshallerConnector.start(); 40 41 MarshallerLoaderHandler loader = new MarshallerLoaderHandler(); 42 marshallerConnector.addInvocationHandler("loader", loader); 43 } 44 catch(Exception e) 45 { 46 log.error("Can not create marshaller loader.", e); 47 if(marshallerConnector != null) 48 { 49 try 50 { 51 marshallerConnector.stop(); 52 marshallerConnector.destroy(); 53 } 54 catch(Exception e1) 55 { 56 log.error("Error cleaning up marshaller loader connector.", e1); 57 } 58 } 59 } 60 return marshallerConnector; 61 } 62 63 71 public static InvokerLocator convertLocator(InvokerLocator locator) 72 { 73 InvokerLocator loaderLocator = null; 74 75 if(locator != null) 76 { 77 Map params = locator.getParameters(); 78 if(params != null) 79 { 80 String sPort = (String ) params.get(InvokerLocator.LOADER_PORT); 81 if(sPort != null) 82 { 83 try 84 { 85 int port = Integer.parseInt(sPort); 86 String transport = "socket"; 89 String host = locator.getHost(); 90 String path = locator.getPath(); 91 Map metadata = new HashMap (); 92 metadata.putAll(locator.getParameters()); 93 metadata.remove(InvokerLocator.LOADER_PORT); 95 metadata.remove(InvokerLocator.MARSHALLER); 96 metadata.remove(InvokerLocator.UNMARSHALLER); 97 metadata.remove(InvokerLocator.DATATYPE); 98 metadata.remove(InvokerLocator.DATATYPE_CASED); 99 loaderLocator = new InvokerLocator(transport, host, port, path, metadata); 100 } 101 catch(NumberFormatException e) 102 { 103 log.error("Got loader port (" + sPort + ") from locator uri, but was not an number."); 104 } 105 } 106 } 107 } 108 return loaderLocator; 109 } 110 } | Popular Tags |