1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.connector.impl;
24
25 import javax.naming.NamingException;
26 import javax.naming.Reference;
27 import javax.resource.NotSupportedException;
28 import javax.resource.ResourceException;
29 import javax.resource.cci.Connection;
30 import javax.resource.cci.ConnectionSpec;
31 import javax.resource.cci.RecordFactory;
32 import javax.resource.cci.ResourceAdapterMetaData;
33 import javax.resource.spi.ConnectionManager;
34 import javax.resource.spi.ManagedConnectionFactory;
35
36 import de.bea.domingo.connector.DomingoConnectionFactory;
37 import de.bea.domingo.i18n.ResourceManager;
38 import de.bea.domingo.i18n.Resources;
39
40 /***
41 * @author <a href=mailto:kurt.riede@bea.de>Kurt Riede</a>
42 */
43 public final class DomingoConnectionFactoryImpl implements DomingoConnectionFactory {
44
45 /*** serial version ID for serialization. */
46 private static final long serialVersionUID = 4554515970618320438L;
47
48 /*** Internationalized resources. */
49 private static final Resources RESOURCES = ResourceManager.getPackageResources(DomingoConnectionFactoryImpl.class);
50
51 /*** Reference to the managed connection factory. */
52 private final ManagedConnectionFactory managedConnectionFactory;
53
54 /*** Reference to the connection manager. */
55 private final ConnectionManager connectionManager;
56
57 private Reference reference;
58
59 /***
60 * Constructor.
61 *
62 * @param mcf the managed connection factory
63 * @param cm the connection manager
64 */
65 public DomingoConnectionFactoryImpl(final ManagedConnectionFactory mcf, final ConnectionManager cm) {
66 super();
67 this.managedConnectionFactory = mcf;
68 this.connectionManager = cm;
69 }
70
71 /***
72 * {@inheritDoc}
73 *
74 * @see de.bea.domingo.connector.DomingoConnectionFactory#getConnection()
75 */
76 public Connection getConnection() throws ResourceException {
77 throw new NotSupportedException(RESOURCES.getString("method.not.supported.instead.1",
78 "getConnection(ConnectionSpec spec)"));
79 }
80
81 /***
82 * {@inheritDoc}
83 *
84 * @see de.bea.domingo.connector.DomingoConnectionFactory#getConnection(javax.resource.cci.ConnectionSpec)
85 */
86 public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
87 if (!(connectionSpec instanceof DomingoConnectionSpec)) {
88 throw new NotSupportedException(RESOURCES.getString("connectionspec.mustbe.instanceof.1",
89 ConnectionSpec.class.getName()));
90 }
91 return (Connection) connectionManager.allocateConnection(managedConnectionFactory,
92 (DomingoConnectionSpec) connectionSpec);
93 }
94
95 /***
96 * {@inheritDoc}
97 *
98 * @see de.bea.domingo.connector.DomingoConnectionFactory#getRecordFactory()
99 */
100 public RecordFactory getRecordFactory() throws ResourceException {
101 throw new NotSupportedException(RESOURCES.getString("method.not.supported"));
102 }
103
104 /***
105 * {@inheritDoc}
106 *
107 * @see de.bea.domingo.connector.DomingoConnectionFactory#getMetaData()
108 */
109 public ResourceAdapterMetaData getMetaData() throws ResourceException {
110 return DomingoMetaData.getInstance();
111 }
112
113 /***
114 * {@inheritDoc}
115 *
116 * @see de.bea.domingo.connector.DomingoConnectionFactory#setReference(javax.naming.Reference)
117 */
118 public void setReference(Reference ref) {
119 reference = ref;
120 }
121
122 /***
123 * {@inheritDoc}
124 *
125 * @see de.bea.domingo.connector.DomingoConnectionFactory#getReference()
126 */
127 public Reference getReference() throws NamingException {
128 return reference;
129 }
130 }