1 45 package org.exolab.jms.net.socket; 46 47 import java.security.Principal ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 import org.exolab.jms.net.connector.ConnectionRequestInfo; 52 import org.exolab.jms.net.connector.ManagedConnection; 53 import org.exolab.jms.net.connector.ManagedConnectionAcceptor; 54 import org.exolab.jms.net.connector.ManagedConnectionFactory; 55 import org.exolab.jms.net.connector.ResourceException; 56 import org.exolab.jms.net.uri.URI; 57 import org.exolab.jms.net.uri.URIHelper; 58 59 60 67 public abstract class SocketManagedConnectionFactory 68 implements ManagedConnectionFactory { 69 70 80 public ManagedConnection matchManagedConnections(List connections, 81 Principal principal, 82 ConnectionRequestInfo info) 83 throws ResourceException { 84 ManagedConnection result = null; 85 86 if (info instanceof SocketRequestInfo) { 87 SocketRequestInfo requestInfo = (SocketRequestInfo) info; 88 URI uri = URIHelper.convertHostToAddress(requestInfo.getURI()); 89 URI altURI = requestInfo.getAlternativeURI(); 90 if (altURI != null) { 91 altURI = URIHelper.convertHostToAddress(altURI); 92 } 93 94 Iterator iterator = connections.iterator(); 95 while (iterator.hasNext()) { 96 SocketManagedConnection connection = 97 (SocketManagedConnection) iterator.next(); 98 if (connection.hasPrincipal(principal)) { 99 final URI remote = connection.getRemoteURI(); 100 final URI local = connection.getLocalURI(); 101 if (remote.equals(uri) || local.equals(uri) 102 || remote.equals(altURI) || local.equals(altURI)) { 103 result = connection; 104 break; 105 } 106 } 107 } 108 } 109 return result; 110 } 111 112 122 public ManagedConnectionAcceptor matchManagedConnectionAcceptors( 123 List acceptors, ConnectionRequestInfo info) 124 throws ResourceException { 125 ManagedConnectionAcceptor result = null; 126 127 if (info instanceof SocketRequestInfo) { 128 Iterator iterator = acceptors.iterator(); 129 while (iterator.hasNext()) { 130 SocketManagedConnectionAcceptor acceptor = 131 (SocketManagedConnectionAcceptor) iterator.next(); 132 if (info.equals(acceptor.getRequestInfo())) { 133 result = acceptor; 134 break; 135 } 136 } 137 } 138 return result; 139 } 140 } 141 | Popular Tags |