01: package com.mockrunner.mock.connector.spi;
02:
03: import java.io.PrintWriter;
04: import java.io.Serializable;
05: import java.util.Iterator;
06: import java.util.Set;
07:
08: import javax.resource.ResourceException;
09: import javax.resource.spi.ConnectionManager;
10: import javax.resource.spi.ConnectionRequestInfo;
11: import javax.resource.spi.ManagedConnection;
12: import javax.resource.spi.ManagedConnectionFactory;
13: import javax.security.auth.Subject;
14:
15: /**
16: * Mock implementation of <code>ManagedConnectionFactory</code>.
17: */
18: public class MockManagedConnectionFactory implements
19: ManagedConnectionFactory, Serializable {
20: private static final long serialVersionUID = 3257291348330558264L;
21:
22: private PrintWriter logWriter;
23: private ConnectionManager connectionManager;
24:
25: public Object createConnectionFactory() throws ResourceException {
26: return createConnectionFactory(null);
27: }
28:
29: public Object createConnectionFactory(
30: ConnectionManager connectionManager)
31: throws ResourceException {
32: this .connectionManager = connectionManager;
33: return this ;
34: }
35:
36: public ManagedConnection createManagedConnection(Subject subject,
37: ConnectionRequestInfo requestInfo) throws ResourceException {
38: Object managedConnection = null;
39: if (connectionManager == null) {
40: // TODO is this correct?
41: managedConnection = new MockManagedConnection()
42: .getConnection(subject, requestInfo);
43: } else {
44: managedConnection = connectionManager.allocateConnection(
45: this , requestInfo);
46: }
47: return (MockManagedConnection) managedConnection;
48: }
49:
50: public ManagedConnection matchManagedConnections(Set set,
51: Subject subject, ConnectionRequestInfo connectionRequestInfo)
52: throws ResourceException {
53: ManagedConnection managedConnection = null;
54: Iterator iterator = set.iterator();
55: if (iterator.hasNext()) {
56: // TODO also process subject and connectionrequestinfo
57: managedConnection = (ManagedConnection) iterator.next();
58: }
59: return managedConnection;
60: }
61:
62: public PrintWriter getLogWriter() throws ResourceException {
63: return logWriter;
64: }
65:
66: public void setLogWriter(PrintWriter logWriter)
67: throws ResourceException {
68: this.logWriter = logWriter;
69: }
70: }
|