1 17 18 package org.apache.geronimo.connector.mock; 19 20 import java.io.PrintWriter ; 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import java.util.Collections ; 25 26 import javax.resource.ResourceException ; 27 import javax.resource.spi.ConnectionManager ; 28 import javax.resource.spi.ConnectionRequestInfo ; 29 import javax.resource.spi.ManagedConnection ; 30 import javax.resource.spi.ManagedConnectionFactory ; 31 import javax.resource.spi.ResourceAdapter ; 32 import javax.security.auth.Subject ; 33 34 40 public class MockManagedConnectionFactory implements ManagedConnectionFactory { 41 42 private MockResourceAdapter resourceAdapter; 43 private PrintWriter logWriter; 44 45 private final Set managedConnections = Collections.synchronizedSet(new HashSet ()); 46 47 private boolean reauthentication; 48 49 public String getOutboundStringProperty1() { 50 return outboundStringProperty1; 51 } 52 53 public void setOutboundStringProperty1(String outboundStringProperty1) { 54 this.outboundStringProperty1 = outboundStringProperty1; 55 } 56 57 public String getOutboundStringProperty2() { 58 return outboundStringProperty2; 59 } 60 61 public void setOutboundStringProperty2(String outboundStringProperty2) { 62 this.outboundStringProperty2 = outboundStringProperty2; 63 } 64 65 public String getOutboundStringProperty3() { 66 return outboundStringProperty3; 67 } 68 69 public void setOutboundStringProperty3(String outboundStringProperty3) { 70 this.outboundStringProperty3 = outboundStringProperty3; 71 } 72 73 public String getOutboundStringProperty4() { 74 return outboundStringProperty4; 75 } 76 77 public void setOutboundStringProperty4(String outboundStringProperty4) { 78 this.outboundStringProperty4 = outboundStringProperty4; 79 } 80 81 private String outboundStringProperty1; 82 private String outboundStringProperty2; 83 private String outboundStringProperty3; 84 private String outboundStringProperty4; 85 86 public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException { 87 assert this.resourceAdapter == null: "Setting ResourceAdapter twice"; 88 assert resourceAdapter != null: "trying to set resourceAdapter to null"; 89 this.resourceAdapter = (MockResourceAdapter) resourceAdapter; 90 } 91 92 public ResourceAdapter getResourceAdapter() { 93 return resourceAdapter; 94 } 95 96 public Object createConnectionFactory(ConnectionManager connectionManager) throws ResourceException { 97 return new MockConnectionFactory(this, connectionManager); 98 } 99 100 public Object createConnectionFactory() throws ResourceException { 101 return null; 102 } 103 104 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException { 105 MockManagedConnection managedConnection = new MockManagedConnection(this, subject, (MockConnectionRequestInfo) connectionRequestInfo); 106 managedConnections.add(managedConnection); 107 return managedConnection; 108 } 109 110 public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { 111 if (reauthentication) { 112 for (Iterator iterator = connectionSet.iterator(); iterator.hasNext();) { 113 ManagedConnection managedConnection = (ManagedConnection ) iterator.next(); 114 if (managedConnections.contains(managedConnection)) { 115 return managedConnection; 116 } 117 } 118 } else { 119 for (Iterator iterator = connectionSet.iterator(); iterator.hasNext();) { 120 ManagedConnection managedConnection = (ManagedConnection ) iterator.next(); 121 if (managedConnections.contains(managedConnection)) { 123 MockManagedConnection mockManagedConnection = (MockManagedConnection) managedConnection; 124 if ((subject == null ? mockManagedConnection.getSubject() == null : subject.equals(mockManagedConnection.getSubject()) 125 && (cxRequestInfo == null ? mockManagedConnection.getConnectionRequestInfo() == null : cxRequestInfo.equals(mockManagedConnection.getConnectionRequestInfo())))) { 126 return mockManagedConnection; 127 } 128 } 129 } 130 } 131 return null; 132 } 133 134 public void setLogWriter(PrintWriter logWriter) throws ResourceException { 135 this.logWriter = logWriter; 136 } 137 138 public PrintWriter getLogWriter() throws ResourceException { 139 return logWriter; 140 } 141 142 public boolean isReauthentication() { 143 return reauthentication; 144 } 145 146 public void setReauthentication(boolean reauthentication) { 147 this.reauthentication = reauthentication; 148 } 149 150 public Set getManagedConnections() { 151 return managedConnections; 152 } 153 } 154 | Popular Tags |