1 45 package org.exolab.jms.net.rmi; 46 47 import java.rmi.AlreadyBoundException ; 48 import java.rmi.NotBoundException ; 49 import java.rmi.RemoteException ; 50 import java.rmi.registry.Registry ; 51 52 import org.exolab.jms.net.connector.ResourceException; 53 import org.exolab.jms.net.uri.URI; 54 55 56 62 final class RegistryHelper { 63 64 67 private static final String BIND_SUFFIX = 68 RMIInvokerFactory.class.getName(); 69 70 71 74 private RegistryHelper() { 75 } 76 77 86 public static void bind(RMIInvokerFactory factory, URI uri, 87 Registry registry) throws ResourceException { 88 89 String name = getName(uri); 90 91 try { 92 registry.bind(name, factory); 93 } catch (AlreadyBoundException exception) { 94 throw new ResourceException("Binding exists for " + name, 95 exception); 96 } catch (RemoteException exception) { 97 throw new ResourceException("Failed to bind connection factory", 98 exception); 99 } 100 } 101 102 111 public static void unbind(RMIInvokerFactory factory, URI uri, 112 Registry registry) throws ResourceException { 113 String name = getName(uri); 114 try { 115 registry.unbind(name); 116 } catch (NotBoundException exception) { 117 throw new ResourceException("No binding exists for " + name, 118 exception); 119 } catch (RemoteException exception) { 120 throw new ResourceException("Failed to unbind connection factory", 121 exception); 122 } 123 } 124 125 132 public static String getName(URI uri) { 133 String path = uri.getPath(); 134 if (path == null) { 135 path = "/"; 136 } else if (!path.startsWith("/")) { 137 path = "/" + path; 138 } 139 if (!path.endsWith("/")) { 140 path += "/"; 141 } 142 143 return path + BIND_SUFFIX; 144 } 145 146 153 public static boolean hasBindings(Registry registry) 154 throws RemoteException { 155 String [] names = registry.list(); 156 return (names.length != 0); 157 } 158 159 } 160 | Popular Tags |