1 45 package org.exolab.jms.net.connector; 46 47 import java.util.Map ; 48 49 import java.security.Principal ; 50 51 import org.exolab.jms.net.uri.URI; 52 import org.exolab.jms.net.uri.URIHelper; 53 import org.exolab.jms.net.util.Properties; 54 55 56 62 public abstract class AbstractConnectionFactory implements ConnectionFactory { 63 64 68 public static final String PROPERTY_PREFIX = "org.exolab.jms.net."; 69 70 73 private final String _connectScheme; 74 75 78 private final String _acceptScheme; 79 80 83 private final ManagedConnectionFactory _factory; 84 85 88 private final ConnectionManager _manager; 89 90 91 99 public AbstractConnectionFactory(String scheme, 100 ManagedConnectionFactory factory, 101 ConnectionManager manager) { 102 this(scheme, scheme, factory, manager); 103 } 104 105 113 public AbstractConnectionFactory(String connectScheme, 114 String acceptScheme, 115 ManagedConnectionFactory factory, 116 ConnectionManager manager) { 117 _connectScheme = connectScheme; 118 _acceptScheme = acceptScheme; 119 _factory = factory; 120 _manager = manager; 121 } 122 123 130 public boolean canConnect(URI uri) { 131 return _connectScheme.equals(uri.getScheme()); 132 } 133 134 143 public Connection getConnection(Principal principal, URI uri) 144 throws ResourceException { 145 return getConnection(principal, uri, null); 146 } 147 148 159 public Connection getConnection(Principal principal, URI uri, 160 Map properties) 161 throws ResourceException { 162 ConnectionRequestInfo info = 163 getConnectionRequestInfo(uri, properties); 164 if (principal == null) { 165 principal = URIHelper.getPrincipal(uri); 166 } 167 return _manager.allocateConnection(_factory, principal, info); 168 } 169 170 178 public boolean canAccept(URI uri) { 179 return _acceptScheme.equals(uri.getScheme()); 180 } 181 182 190 public void accept(URI uri) throws ResourceException { 191 accept(uri, null); 192 } 193 194 203 public void accept(URI uri, Map properties) throws ResourceException { 204 ConnectionRequestInfo info = getAcceptorRequestInfo(uri, properties); 205 _manager.accept(_factory, info); 206 } 207 208 219 protected abstract ConnectionRequestInfo getConnectionRequestInfo( 220 URI uri, Map properties) 221 throws ResourceException; 222 223 235 protected ConnectionRequestInfo getAcceptorRequestInfo( 236 URI uri, Map properties) 237 throws ResourceException { 238 return getConnectionRequestInfo(uri, properties); 239 } 240 241 246 protected ManagedConnectionFactory getManagedConnectionFactory() { 247 return _factory; 248 } 249 250 255 protected ConnectionManager getConnectionManager() { 256 return _manager; 257 } 258 259 266 protected Properties getProperties(Map properties) { 267 String prefix = PROPERTY_PREFIX + _connectScheme + "."; 268 return new Properties(properties, prefix); 269 } 270 271 } 272 | Popular Tags |