1 45 package org.exolab.jms.net.orb; 46 47 import java.lang.reflect.Constructor ; 48 import java.lang.reflect.InvocationTargetException ; 49 import java.rmi.ConnectIOException ; 50 import java.rmi.RemoteException ; 51 import java.rmi.StubNotFoundException ; 52 import java.rmi.AccessException ; 53 import java.rmi.server.ObjID ; 54 import java.security.Principal ; 55 import java.util.Map ; 56 57 import org.exolab.jms.net.connector.Connection; 58 import org.exolab.jms.net.connector.ConnectionFactory; 59 import org.exolab.jms.net.connector.ResourceException; 60 import org.exolab.jms.net.connector.SecurityException; 61 import org.exolab.jms.net.proxy.Delegate; 62 import org.exolab.jms.net.proxy.Proxy; 63 import org.exolab.jms.net.registry.Registry; 64 import org.exolab.jms.net.uri.InvalidURIException; 65 import org.exolab.jms.net.uri.URIHelper; 66 67 68 75 final class Locator { 76 77 80 private Locator() { 81 } 82 83 95 public static Registry getRegistry(Principal principal, String uri, 96 ConnectionFactory factory, 97 ClassLoader loader, Map properties) 98 throws InvalidURIException, RemoteException { 99 100 ObjID objId = new ObjID (ObjID.REGISTRY_ID); 101 String className = RegistryImpl.PROXY; 102 103 return (Registry) getProxy(objId, principal, uri, factory, className, 104 loader, properties); 105 } 106 107 121 public static Proxy getProxy(ObjID objId, Principal principal, String uri, 122 ConnectionFactory factory, 123 String className, ClassLoader loader, 124 Map properties) 125 throws InvalidURIException, RemoteException { 126 127 Proxy proxy; 128 129 Connection connection; 130 try { 131 connection = factory.getConnection(principal, 132 URIHelper.parse(uri), 133 properties); 134 } catch (SecurityException exception) { 135 throw new AccessException (exception.getMessage(), exception); 136 } catch (ResourceException exception) { 137 throw new ConnectIOException ("Failed to create connection", 138 exception); 139 } 140 141 UnicastDelegate delegate = new UnicastDelegate(objId, connection); 142 143 try { 144 Class proxyClass = loader.loadClass(className); 145 Constructor constructor = proxyClass.getConstructor( 146 new Class []{Delegate.class}); 147 proxy = (Proxy) constructor.newInstance(new Object []{delegate}); 148 } catch (ClassNotFoundException exception) { 149 throw new StubNotFoundException (exception.getMessage(), exception); 150 } catch (IllegalAccessException exception) { 151 throw new RemoteException (exception.getMessage(), exception); 152 } catch (InstantiationException exception) { 153 throw new RemoteException (exception.getMessage(), exception); 154 } catch (InvocationTargetException exception) { 155 Throwable target = exception.getTargetException(); 157 if (target != null) { 158 throw new RemoteException (exception.getMessage(), target); 159 } else { 160 throw new RemoteException (exception.getMessage(), exception); 161 } 162 } catch (NoSuchMethodException exception) { 163 throw new RemoteException (exception.getMessage(), exception); 164 } 165 return proxy; 166 } 167 168 } 169 | Popular Tags |