1 45 package org.exolab.jms.net.orb; 46 47 import java.rmi.AccessException ; 48 import java.rmi.AlreadyBoundException ; 49 import java.rmi.NotBoundException ; 50 import java.util.HashMap ; 51 52 import org.exolab.jms.net.proxy.Proxy; 53 import org.exolab.jms.net.registry.Registry; 54 55 56 63 class RegistryImpl implements Registry { 64 65 68 public static final String PROXY = 69 RegistryImpl.class.getName() + "__Proxy"; 70 71 74 private HashMap _registry = new HashMap (); 75 76 79 private boolean _readOnly = false; 80 81 82 85 public RegistryImpl() { 86 } 87 88 95 public synchronized Proxy lookup(String name) throws NotBoundException { 96 Proxy proxy = (Proxy) _registry.get(name); 97 if (proxy == null) { 98 throw new NotBoundException (name); 99 } 100 return proxy; 101 } 102 103 112 public synchronized void bind(String name, Proxy proxy) 113 throws AccessException , AlreadyBoundException { 114 checkReadOnly(); 115 doBind(name, proxy); 116 } 117 118 126 public synchronized void unbind(String name) 127 throws AccessException , NotBoundException { 128 checkReadOnly(); 129 doUnbind(name); 130 } 131 132 139 protected synchronized void doBind(String name, Proxy proxy) 140 throws AlreadyBoundException { 141 if (_registry.containsKey(name)) { 142 throw new AlreadyBoundException (name); 143 } 144 _registry.put(name, proxy); 145 } 146 147 153 protected synchronized void doUnbind(String name) 154 throws NotBoundException { 155 Object proxy = _registry.remove(name); 156 if (proxy == null) { 157 throw new NotBoundException (name); 158 } 159 } 160 161 167 protected synchronized void setReadOnly(boolean readOnly) { 168 _readOnly = readOnly; 169 } 170 171 176 protected synchronized boolean getReadOnly() { 177 return _readOnly; 178 } 179 180 185 private void checkReadOnly() throws AccessException { 186 if (_readOnly) { 187 throw new AccessException ("Registry is read-only"); 188 } 189 } 190 191 } 192 | Popular Tags |