1 45 package org.exolab.jms.net.rmi; 46 47 import java.security.Principal ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 import org.exolab.jms.net.connector.Authenticator; 52 import org.exolab.jms.net.connector.ConnectionFactory; 53 import org.exolab.jms.net.connector.ConnectionManager; 54 import org.exolab.jms.net.connector.ConnectionRequestInfo; 55 import org.exolab.jms.net.connector.ManagedConnection; 56 import org.exolab.jms.net.connector.ManagedConnectionAcceptor; 57 import org.exolab.jms.net.connector.ManagedConnectionFactory; 58 import org.exolab.jms.net.connector.ResourceException; 59 import org.exolab.jms.net.uri.URI; 60 import org.exolab.jms.net.uri.URIHelper; 61 62 63 70 public class RMIManagedConnectionFactory implements ManagedConnectionFactory { 71 72 79 public ConnectionFactory createConnectionFactory(ConnectionManager manager) 80 throws ResourceException { 81 return new RMIConnectionFactory(this, manager); 82 } 83 84 92 public ManagedConnection createManagedConnection(Principal principal, 93 ConnectionRequestInfo info) 94 throws ResourceException { 95 if (!(info instanceof RMIRequestInfo)) { 96 throw new ResourceException("Argument 'info' must be of type " 97 + RMIRequestInfo.class.getName()); 98 } 99 return new RMIManagedConnection(principal, (RMIRequestInfo) info); 100 } 101 102 110 public ManagedConnectionAcceptor createManagedConnectionAcceptor( 111 Authenticator authenticator, ConnectionRequestInfo info) 112 throws ResourceException { 113 114 if (!(info instanceof RMIRequestInfo)) { 115 throw new ResourceException("Argument 'info' must be of type " 116 + RMIRequestInfo.class.getName()); 117 } 118 RMIRequestInfo rmiInfo = (RMIRequestInfo) info; 119 return new RMIManagedConnectionAcceptor(authenticator, rmiInfo); 120 } 121 122 132 public ManagedConnection matchManagedConnections(List connections, 133 Principal principal, 134 ConnectionRequestInfo info) 135 throws ResourceException { 136 ManagedConnection result = null; 137 138 if (info instanceof RMIRequestInfo) { 139 RMIRequestInfo requestInfo = (RMIRequestInfo) info; 140 URI uri = URIHelper.convertHostToAddress(requestInfo.getURI()); 141 142 Iterator iterator = connections.iterator(); 143 while (iterator.hasNext()) { 144 RMIManagedConnection connection = 145 (RMIManagedConnection) iterator.next(); 146 if (connection.hasPrincipal(principal) 147 && uri.equals(connection.getRemoteURI())) { 148 result = connection; 149 break; 150 } 151 } 152 } 153 return result; 154 } 155 156 166 public ManagedConnectionAcceptor matchManagedConnectionAcceptors( 167 List acceptors, ConnectionRequestInfo info) 168 throws ResourceException { 169 ManagedConnectionAcceptor result = null; 170 171 if (info instanceof RMIRequestInfo) { 172 RMIRequestInfo requestInfo = (RMIRequestInfo) info; 173 URI uri = URIHelper.convertHostToAddress(requestInfo.getURI()); 174 Iterator iterator = acceptors.iterator(); 175 while (iterator.hasNext()) { 176 RMIManagedConnectionAcceptor acceptor = 177 (RMIManagedConnectionAcceptor) iterator.next(); 178 if (uri.equals(acceptor.getURI())) { 179 result = acceptor; 180 break; 181 } 182 } 183 } 184 return result; 185 } 186 187 } 188 | Popular Tags |