01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.jca.cci.connection;
18:
19: import javax.naming.NamingException;
20: import javax.naming.Reference;
21: import javax.resource.ResourceException;
22: import javax.resource.cci.Connection;
23: import javax.resource.cci.ConnectionFactory;
24: import javax.resource.cci.ConnectionSpec;
25: import javax.resource.cci.RecordFactory;
26: import javax.resource.cci.ResourceAdapterMetaData;
27:
28: import org.springframework.beans.factory.InitializingBean;
29:
30: /**
31: * CCI {@link ConnectionFactory} implementation that delegates all calls
32: * to a given target {@link ConnectionFactory}.
33: *
34: * <p>This class is meant to be subclassed, with subclasses overriding only
35: * those methods (such as {@link #getConnection()}) that should not simply
36: * delegate to the target {@link ConnectionFactory}.
37: *
38: * @author Juergen Hoeller
39: * @since 1.2
40: * @see #getConnection
41: */
42: public class DelegatingConnectionFactory implements ConnectionFactory,
43: InitializingBean {
44:
45: private ConnectionFactory targetConnectionFactory;
46:
47: /**
48: * Set the target ConnectionFactory that this ConnectionFactory should delegate to.
49: */
50: public void setTargetConnectionFactory(
51: ConnectionFactory targetConnectionFactory) {
52: this .targetConnectionFactory = targetConnectionFactory;
53: }
54:
55: /**
56: * Return the target ConnectionFactory that this ConnectionFactory should delegate to.
57: */
58: public ConnectionFactory getTargetConnectionFactory() {
59: return this .targetConnectionFactory;
60: }
61:
62: public void afterPropertiesSet() {
63: if (getTargetConnectionFactory() == null) {
64: throw new IllegalArgumentException(
65: "Property 'targetConnectionFactory' is required");
66: }
67: }
68:
69: public Connection getConnection() throws ResourceException {
70: return getTargetConnectionFactory().getConnection();
71: }
72:
73: public Connection getConnection(ConnectionSpec connectionSpec)
74: throws ResourceException {
75: return getTargetConnectionFactory().getConnection(
76: connectionSpec);
77: }
78:
79: public RecordFactory getRecordFactory() throws ResourceException {
80: return getTargetConnectionFactory().getRecordFactory();
81: }
82:
83: public ResourceAdapterMetaData getMetaData()
84: throws ResourceException {
85: return getTargetConnectionFactory().getMetaData();
86: }
87:
88: public Reference getReference() throws NamingException {
89: return getTargetConnectionFactory().getReference();
90: }
91:
92: public void setReference(Reference reference) {
93: getTargetConnectionFactory().setReference(reference);
94: }
95:
96: }
|