KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jca > cci > connection > DelegatingConnectionFactory


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import javax.naming.Reference JavaDoc;
21 import javax.resource.ResourceException JavaDoc;
22 import javax.resource.cci.Connection JavaDoc;
23 import javax.resource.cci.ConnectionFactory JavaDoc;
24 import javax.resource.cci.ConnectionSpec JavaDoc;
25 import javax.resource.cci.RecordFactory JavaDoc;
26 import javax.resource.cci.ResourceAdapterMetaData JavaDoc;
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 JavaDoc, InitializingBean {
43
44     private ConnectionFactory JavaDoc targetConnectionFactory;
45
46
47     /**
48      * Set the target ConnectionFactory that this ConnectionFactory should delegate to.
49      */

50     public void setTargetConnectionFactory(ConnectionFactory JavaDoc targetConnectionFactory) {
51         this.targetConnectionFactory = targetConnectionFactory;
52     }
53
54     /**
55      * Return the target ConnectionFactory that this ConnectionFactory should delegate to.
56      */

57     public ConnectionFactory JavaDoc getTargetConnectionFactory() {
58         return this.targetConnectionFactory;
59     }
60
61
62     public void afterPropertiesSet() {
63         if (getTargetConnectionFactory() == null) {
64             throw new IllegalArgumentException JavaDoc("Property 'targetConnectionFactory' is required");
65         }
66     }
67
68
69     public Connection JavaDoc getConnection() throws ResourceException JavaDoc {
70         return getTargetConnectionFactory().getConnection();
71     }
72
73     public Connection JavaDoc getConnection(ConnectionSpec JavaDoc connectionSpec) throws ResourceException JavaDoc {
74         return getTargetConnectionFactory().getConnection(connectionSpec);
75     }
76
77     public RecordFactory JavaDoc getRecordFactory() throws ResourceException JavaDoc {
78         return getTargetConnectionFactory().getRecordFactory();
79     }
80
81     public ResourceAdapterMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
82         return getTargetConnectionFactory().getMetaData();
83     }
84
85     public Reference JavaDoc getReference() throws NamingException JavaDoc {
86         return getTargetConnectionFactory().getReference();
87     }
88
89     public void setReference(Reference JavaDoc reference) {
90         getTargetConnectionFactory().setReference(reference);
91     }
92
93 }
94
Popular Tags