KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > mock > MockManagedConnectionFactory


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.connector.mock;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.Collections JavaDoc;
25
26 import javax.resource.ResourceException JavaDoc;
27 import javax.resource.spi.ConnectionManager JavaDoc;
28 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
29 import javax.resource.spi.ManagedConnection JavaDoc;
30 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
31 import javax.resource.spi.ResourceAdapter JavaDoc;
32 import javax.security.auth.Subject JavaDoc;
33
34 /**
35  *
36  *
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  *
39  * */

40 public class MockManagedConnectionFactory implements ManagedConnectionFactory JavaDoc {
41
42     private MockResourceAdapter resourceAdapter;
43     private PrintWriter JavaDoc logWriter;
44
45     private final Set JavaDoc managedConnections = Collections.synchronizedSet(new HashSet JavaDoc());
46
47     private boolean reauthentication;
48
49     public String JavaDoc getOutboundStringProperty1() {
50         return outboundStringProperty1;
51     }
52
53     public void setOutboundStringProperty1(String JavaDoc outboundStringProperty1) {
54         this.outboundStringProperty1 = outboundStringProperty1;
55     }
56
57     public String JavaDoc getOutboundStringProperty2() {
58         return outboundStringProperty2;
59     }
60
61     public void setOutboundStringProperty2(String JavaDoc outboundStringProperty2) {
62         this.outboundStringProperty2 = outboundStringProperty2;
63     }
64
65     public String JavaDoc getOutboundStringProperty3() {
66         return outboundStringProperty3;
67     }
68
69     public void setOutboundStringProperty3(String JavaDoc outboundStringProperty3) {
70         this.outboundStringProperty3 = outboundStringProperty3;
71     }
72
73     public String JavaDoc getOutboundStringProperty4() {
74         return outboundStringProperty4;
75     }
76
77     public void setOutboundStringProperty4(String JavaDoc outboundStringProperty4) {
78         this.outboundStringProperty4 = outboundStringProperty4;
79     }
80
81     private String JavaDoc outboundStringProperty1;
82     private String JavaDoc outboundStringProperty2;
83     private String JavaDoc outboundStringProperty3;
84     private String JavaDoc outboundStringProperty4;
85
86     public void setResourceAdapter(ResourceAdapter JavaDoc resourceAdapter) throws ResourceException JavaDoc {
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 JavaDoc getResourceAdapter() {
93         return resourceAdapter;
94     }
95
96     public Object JavaDoc createConnectionFactory(ConnectionManager JavaDoc connectionManager) throws ResourceException JavaDoc {
97         return new MockConnectionFactory(this, connectionManager);
98     }
99
100     public Object JavaDoc createConnectionFactory() throws ResourceException JavaDoc {
101         return null;
102     }
103
104     public ManagedConnection JavaDoc createManagedConnection(Subject JavaDoc subject, ConnectionRequestInfo JavaDoc connectionRequestInfo) throws ResourceException JavaDoc {
105         MockManagedConnection managedConnection = new MockManagedConnection(this, subject, (MockConnectionRequestInfo) connectionRequestInfo);
106         managedConnections.add(managedConnection);
107         return managedConnection;
108     }
109
110     public ManagedConnection JavaDoc matchManagedConnections(Set JavaDoc connectionSet, Subject JavaDoc subject, ConnectionRequestInfo JavaDoc cxRequestInfo) throws ResourceException JavaDoc {
111         if (reauthentication) {
112             for (Iterator JavaDoc iterator = connectionSet.iterator(); iterator.hasNext();) {
113                 ManagedConnection JavaDoc managedConnection = (ManagedConnection JavaDoc) iterator.next();
114                 if (managedConnections.contains(managedConnection)) {
115                     return managedConnection;
116                 }
117             }
118         } else {
119             for (Iterator JavaDoc iterator = connectionSet.iterator(); iterator.hasNext();) {
120                 ManagedConnection JavaDoc managedConnection = (ManagedConnection JavaDoc) iterator.next();
121 // return managedConnection;
122
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 JavaDoc logWriter) throws ResourceException JavaDoc {
135         this.logWriter = logWriter;
136     }
137
138     public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc {
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 JavaDoc getManagedConnections() {
151         return managedConnections;
152     }
153 }
154
Popular Tags