01: package com.mockrunner.mock.connector.cci;
02:
03: import javax.naming.NamingException;
04: import javax.naming.Reference;
05: import javax.resource.ResourceException;
06: import javax.resource.cci.Connection;
07: import javax.resource.cci.ConnectionFactory;
08: import javax.resource.cci.ConnectionSpec;
09: import javax.resource.cci.RecordFactory;
10: import javax.resource.cci.ResourceAdapterMetaData;
11:
12: /**
13: * Mock implementation of <code>ConnectionFactory</code>
14: */
15: public class MockConnectionFactory implements ConnectionFactory {
16: private Connection connection;
17: private RecordFactory recordFactory;
18: private ResourceAdapterMetaData metaData;
19: private Reference reference;
20:
21: public MockConnectionFactory() {
22: metaData = new MockResourceAdapterMetaData();
23: recordFactory = new MockRecordFactory();
24: }
25:
26: public void setConnection(Connection connection) {
27: this .connection = connection;
28: }
29:
30: public Connection getConnection() throws ResourceException {
31: return connection;
32: }
33:
34: public MockConnection getMockConnection() {
35: if (connection instanceof MockConnection) {
36: return (MockConnection) connection;
37: }
38: return null;
39: }
40:
41: public Connection getConnection(ConnectionSpec cs)
42: throws ResourceException {
43: return connection;
44: }
45:
46: public RecordFactory getRecordFactory() throws ResourceException {
47: return recordFactory;
48: }
49:
50: public ResourceAdapterMetaData getMetaData()
51: throws ResourceException {
52: return metaData;
53: }
54:
55: public void setReference(Reference reference) {
56: this .reference = reference;
57: }
58:
59: public Reference getReference() throws NamingException {
60: return reference;
61: }
62:
63: /**
64: * Sets the resource adapter meta data. If you do not set an explicit
65: * <code>ResourceAdapterMetaData</code> object, a default {@link MockResourceAdapterMetaData}
66: * will be created.
67: * @param metaData the <code>ResourceAdapterMetaData</code>
68: */
69: public void setMetaData(ResourceAdapterMetaData metaData) {
70: this .metaData = metaData;
71: }
72:
73: /**
74: * Sets the record factory. If you do not set an explicit
75: * <code>RecordFactory</code>, a default {@link MockRecordFactory}
76: * will be created.
77: * @param recordFactory the <code>RecordFactory</code>
78: */
79: public void setRecordFactory(RecordFactory recordFactory) {
80: this.recordFactory = recordFactory;
81: }
82: }
|