Source Code Cross Referenced for ConnectionSpecConnectionFactoryAdapter.java in  » J2EE » spring-framework-2.5 » org » springframework » jca » cci » connection » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.jca.cci.connection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.jca.cci.connection;
018:
019:        import javax.resource.ResourceException;
020:        import javax.resource.cci.Connection;
021:        import javax.resource.cci.ConnectionSpec;
022:
023:        /**
024:         * An adapter for a target CCI {@link javax.resource.cci.ConnectionFactory},
025:         * applying the given ConnectionSpec to every standard <code>getConnection()</code>
026:         * call, that is, implicitly invoking <code>getConnection(ConnectionSpec)</code>
027:         * on the target. All other methods simply delegate to the corresponding methods
028:         * of the target ConnectionFactory.
029:         *
030:         * <p>Can be used to proxy a target JNDI ConnectionFactory that does not have a
031:         * ConnectionSpec configured. Client code can work with the ConnectionFactory
032:         * without passing in a ConnectionSpec on every <code>getConnection()</code> call.
033:         *
034:         * <p>In the following example, client code can simply transparently work with
035:         * the preconfigured "myConnectionFactory", implicitly accessing
036:         * "myTargetConnectionFactory" with the specified user credentials.
037:         *
038:         * <pre class="code">
039:         * &lt;bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
040:         *   &lt;property name="jndiName" value="java:comp/env/cci/mycf"/&gt;
041:         * &lt;/bean>
042:         *
043:         * &lt;bean id="myConnectionFactory" class="org.springframework.jca.cci.connection.ConnectionSpecConnectionFactoryAdapter"&gt;
044:         *   &lt;property name="targetConnectionFactory" ref="myTargetConnectionFactory"/&gt;
045:         *   &lt;property name="connectionSpec"&gt;
046:         *     &lt;bean class="your.resource.adapter.ConnectionSpecImpl"&gt;
047:         *       &lt;property name="username" value="myusername"/&gt;
048:         *       &lt;property name="password" value="mypassword"/&gt;
049:         *     &lt;/bean&gt;
050:         *   &lt;/property&gt;
051:         * &lt;/bean&gt;</pre>
052:         *
053:         * <p>If the "connectionSpec" is empty, this proxy will simply delegate to the
054:         * standard <code>getConnection()</code> method of the target ConnectionFactory.
055:         * This can be used to keep a UserCredentialsConnectionFactoryAdapter bean definition
056:         * just for the <i>option</i> of implicitly passing in a ConnectionSpec if the
057:         * particular target ConnectionFactory requires it.
058:         *
059:         * @author Juergen Hoeller
060:         * @since 1.2
061:         * @see #getConnection
062:         */
063:        public class ConnectionSpecConnectionFactoryAdapter extends
064:                DelegatingConnectionFactory {
065:
066:            private ConnectionSpec connectionSpec;
067:
068:            private final ThreadLocal threadBoundSpec = new ThreadLocal();
069:
070:            /**
071:             * Set the ConnectionSpec that this adapter should use for retrieving Connections.
072:             * Default is none.
073:             */
074:            public void setConnectionSpec(ConnectionSpec connectionSpec) {
075:                this .connectionSpec = connectionSpec;
076:            }
077:
078:            /**
079:             * Set a ConnectionSpec for this proxy and the current thread.
080:             * The given ConnectionSpec will be applied to all subsequent
081:             * <code>getConnection()</code> calls on this ConnectionFactory proxy.
082:             * <p>This will override any statically specified "connectionSpec" property.
083:             * @param spec the ConnectionSpec to apply
084:             * @see #removeConnectionSpecFromCurrentThread
085:             */
086:            public void setConnectionSpecForCurrentThread(ConnectionSpec spec) {
087:                this .threadBoundSpec.set(spec);
088:            }
089:
090:            /**
091:             * Remove any ConnectionSpec for this proxy from the current thread.
092:             * A statically specified ConnectionSpec applies again afterwards.
093:             * @see #setConnectionSpecForCurrentThread
094:             */
095:            public void removeConnectionSpecFromCurrentThread() {
096:                this .threadBoundSpec.set(null);
097:            }
098:
099:            /**
100:             * Determine whether there is currently a thread-bound ConnectionSpec,
101:             * using it if available, falling back to the statically specified
102:             * "connectionSpec" property else.
103:             * @see #doGetConnection
104:             */
105:            public final Connection getConnection() throws ResourceException {
106:                ConnectionSpec threadSpec = (ConnectionSpec) this .threadBoundSpec
107:                        .get();
108:                if (threadSpec != null) {
109:                    return doGetConnection(threadSpec);
110:                } else {
111:                    return doGetConnection(this .connectionSpec);
112:                }
113:            }
114:
115:            /**
116:             * This implementation delegates to the <code>getConnection(ConnectionSpec)</code>
117:             * method of the target ConnectionFactory, passing in the specified user credentials.
118:             * If the specified username is empty, it will simply delegate to the standard
119:             * <code>getConnection()</code> method of the target ConnectionFactory.
120:             * @param spec the ConnectionSpec to apply
121:             * @return the Connection
122:             * @see javax.resource.cci.ConnectionFactory#getConnection(javax.resource.cci.ConnectionSpec)
123:             * @see javax.resource.cci.ConnectionFactory#getConnection()
124:             */
125:            protected Connection doGetConnection(ConnectionSpec spec)
126:                    throws ResourceException {
127:                if (getTargetConnectionFactory() == null) {
128:                    throw new IllegalStateException(
129:                            "targetConnectionFactory is required");
130:                }
131:                if (spec != null) {
132:                    return getTargetConnectionFactory().getConnection(spec);
133:                } else {
134:                    return getTargetConnectionFactory().getConnection();
135:                }
136:            }
137:
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.