001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.connector.mock;
017:
018: import java.io.PrintWriter;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.Set;
022: import java.util.Collections;
023:
024: import javax.resource.ResourceException;
025: import javax.resource.spi.ConnectionManager;
026: import javax.resource.spi.ConnectionRequestInfo;
027: import javax.resource.spi.ManagedConnection;
028: import javax.resource.spi.ManagedConnectionFactory;
029: import javax.resource.spi.ResourceAdapter;
030: import javax.security.auth.Subject;
031:
032: /**
033: *
034: *
035: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
036: *
037: * */
038: public class MockManagedConnectionFactory implements
039: ManagedConnectionFactory {
040:
041: private MockResourceAdapter resourceAdapter;
042: private PrintWriter logWriter;
043:
044: private final Set managedConnections = Collections
045: .synchronizedSet(new HashSet());
046:
047: private boolean reauthentication;
048:
049: public String getOutboundStringProperty1() {
050: return outboundStringProperty1;
051: }
052:
053: public void setOutboundStringProperty1(
054: String outboundStringProperty1) {
055: this .outboundStringProperty1 = outboundStringProperty1;
056: }
057:
058: public String getOutboundStringProperty2() {
059: return outboundStringProperty2;
060: }
061:
062: public void setOutboundStringProperty2(
063: String outboundStringProperty2) {
064: this .outboundStringProperty2 = outboundStringProperty2;
065: }
066:
067: public String getOutboundStringProperty3() {
068: return outboundStringProperty3;
069: }
070:
071: public void setOutboundStringProperty3(
072: String outboundStringProperty3) {
073: this .outboundStringProperty3 = outboundStringProperty3;
074: }
075:
076: public String getOutboundStringProperty4() {
077: return outboundStringProperty4;
078: }
079:
080: public void setOutboundStringProperty4(
081: String outboundStringProperty4) {
082: this .outboundStringProperty4 = outboundStringProperty4;
083: }
084:
085: private String outboundStringProperty1;
086: private String outboundStringProperty2;
087: private String outboundStringProperty3;
088: private String outboundStringProperty4;
089:
090: public void setResourceAdapter(ResourceAdapter resourceAdapter)
091: throws ResourceException {
092: assert this .resourceAdapter == null : "Setting ResourceAdapter twice";
093: assert resourceAdapter != null : "trying to set resourceAdapter to null";
094: this .resourceAdapter = (MockResourceAdapter) resourceAdapter;
095: }
096:
097: public ResourceAdapter getResourceAdapter() {
098: return resourceAdapter;
099: }
100:
101: public Object createConnectionFactory(
102: ConnectionManager connectionManager)
103: throws ResourceException {
104: return new MockConnectionFactory(this , connectionManager);
105: }
106:
107: public Object createConnectionFactory() throws ResourceException {
108: return null;
109: }
110:
111: public ManagedConnection createManagedConnection(Subject subject,
112: ConnectionRequestInfo connectionRequestInfo)
113: throws ResourceException {
114: MockManagedConnection managedConnection = new MockManagedConnection(
115: this , subject,
116: (MockConnectionRequestInfo) connectionRequestInfo);
117: managedConnections.add(managedConnection);
118: return managedConnection;
119: }
120:
121: public ManagedConnection matchManagedConnections(Set connectionSet,
122: Subject subject, ConnectionRequestInfo cxRequestInfo)
123: throws ResourceException {
124: if (reauthentication) {
125: for (Iterator iterator = connectionSet.iterator(); iterator
126: .hasNext();) {
127: ManagedConnection managedConnection = (ManagedConnection) iterator
128: .next();
129: if (managedConnections.contains(managedConnection)) {
130: return managedConnection;
131: }
132: }
133: } else {
134: for (Iterator iterator = connectionSet.iterator(); iterator
135: .hasNext();) {
136: ManagedConnection managedConnection = (ManagedConnection) iterator
137: .next();
138: // return managedConnection;
139: if (managedConnections.contains(managedConnection)) {
140: MockManagedConnection mockManagedConnection = (MockManagedConnection) managedConnection;
141: if ((subject == null ? mockManagedConnection
142: .getSubject() == null
143: : subject.equals(mockManagedConnection
144: .getSubject())
145: && (cxRequestInfo == null ? mockManagedConnection
146: .getConnectionRequestInfo() == null
147: : cxRequestInfo
148: .equals(mockManagedConnection
149: .getConnectionRequestInfo())))) {
150: return mockManagedConnection;
151: }
152: }
153: }
154: }
155: return null;
156: }
157:
158: public void setLogWriter(PrintWriter logWriter)
159: throws ResourceException {
160: this .logWriter = logWriter;
161: }
162:
163: public PrintWriter getLogWriter() throws ResourceException {
164: return logWriter;
165: }
166:
167: public boolean isReauthentication() {
168: return reauthentication;
169: }
170:
171: public void setReauthentication(boolean reauthentication) {
172: this .reauthentication = reauthentication;
173: }
174:
175: public Set getManagedConnections() {
176: return managedConnections;
177: }
178: }
|