Source Code Cross Referenced for MuleManagedConnectionFactory.java in  » ESB » mule » org » mule » module » jca » 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 » ESB » mule » org.mule.module.jca 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MuleManagedConnectionFactory.java 10789 2008-02-12 20:04:43Z dfeist $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:
011:        package org.mule.module.jca;
012:
013:        import java.beans.PropertyChangeListener;
014:        import java.beans.PropertyChangeSupport;
015:        import java.io.IOException;
016:        import java.io.ObjectInputStream;
017:        import java.io.PrintWriter;
018:        import java.util.Iterator;
019:        import java.util.Set;
020:
021:        import javax.resource.ResourceException;
022:        import javax.resource.spi.ConnectionManager;
023:        import javax.resource.spi.ConnectionRequestInfo;
024:        import javax.resource.spi.ManagedConnection;
025:        import javax.resource.spi.ManagedConnectionFactory;
026:        import javax.resource.spi.security.PasswordCredential;
027:        import javax.security.auth.Subject;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        /**
033:         * <code>MuleManagedConnectionFactory</code> TODO
034:         */
035:
036:        public class MuleManagedConnectionFactory implements 
037:                ManagedConnectionFactory {
038:            /**
039:             * Serial version
040:             */
041:            private static final long serialVersionUID = -1460847590293644271L;
042:
043:            private transient PrintWriter out;
044:            private transient PropertyChangeSupport changes = new PropertyChangeSupport(
045:                    this );
046:
047:            // userName property value
048:            private String username = null;
049:
050:            // password property value
051:            private String password = null;
052:
053:            /**
054:             * logger used by this class
055:             */
056:            protected transient Log logger = LogFactory.getLog(this .getClass());
057:
058:            public MuleManagedConnectionFactory() {
059:                super ();
060:            }
061:
062:            private void readObject(ObjectInputStream in) throws IOException,
063:                    ClassNotFoundException {
064:                in.defaultReadObject();
065:                this .logger = LogFactory.getLog(this .getClass());
066:                this .changes = new PropertyChangeSupport(this );
067:                this .out = null;
068:            }
069:
070:            public int hashCode() {
071:                final int PRIME = 31;
072:                int result = 1;
073:                result = PRIME * result
074:                        + ((password == null) ? 0 : password.hashCode());
075:                return PRIME * result
076:                        + ((username == null) ? 0 : username.hashCode());
077:            }
078:
079:            public boolean equals(Object obj) {
080:                if (this  == obj) {
081:                    return true;
082:                }
083:
084:                if (obj == null) {
085:                    return false;
086:                }
087:
088:                if (this .getClass() != obj.getClass()) {
089:                    return false;
090:                }
091:
092:                final MuleManagedConnectionFactory other = (MuleManagedConnectionFactory) obj;
093:
094:                if (password == null) {
095:                    if (other.password != null) {
096:                        return false;
097:                    }
098:                } else if (!password.equals(other.password)) {
099:                    return false;
100:                }
101:
102:                if (username == null) {
103:                    if (other.username != null) {
104:                        return false;
105:                    }
106:                } else if (!username.equals(other.username)) {
107:                    return false;
108:                }
109:
110:                return true;
111:            }
112:
113:            /**
114:             * Creates a Connection Factory instance. The ConnectionFactory instance is
115:             * initialized with the passed ConnectionManager. In the managed scenario,
116:             * ConnectionManager is provided by the application server.
117:             * 
118:             * @param cxManager ConnectionManager to be associated with created EIS
119:             *            connection factory instance
120:             * @return EIS-specific Connection Factory instance
121:             * @throws javax.resource.ResourceException if the attempt to create a connection
122:             *             factory fails
123:             */
124:
125:            public Object createConnectionFactory(ConnectionManager cxManager)
126:                    throws ResourceException {
127:                try {
128:                    return new DefaultMuleConnectionFactory(this , cxManager,
129:                            null);
130:                } catch (Exception e) {
131:                    throw new ResourceException(e);
132:                }
133:            }
134:
135:            /**
136:             * Creates a Connection Factory instance. The Connection Factory instance is
137:             * initialized with a default ConnectionManager. In the non-managed scenario, the
138:             * ConnectionManager is provided by the resource adapter.
139:             * 
140:             * @return EIS-specific Connection Factory instance
141:             * @throws ResourceException if the attempt to create a connection factory fails
142:             */
143:
144:            public Object createConnectionFactory() throws ResourceException {
145:                return new DefaultMuleConnectionFactory(this , null, null);
146:            }
147:
148:            /**
149:             * ManagedConnectionFactory uses the security information (passed as Subject) and
150:             * additional ConnectionRequestInfo (which is specific to ResourceAdapter and
151:             * opaque to application server) to create this new connection.
152:             * 
153:             * @param subject caller's security information
154:             * @param cxRequestInfo additional resource adapter specific connection request
155:             *            information
156:             * @return ManagedConnection instance
157:             * @throws ResourceException if the attempt to create a connection fails
158:             */
159:
160:            public ManagedConnection createManagedConnection(Subject subject,
161:                    ConnectionRequestInfo cxRequestInfo)
162:                    throws ResourceException {
163:                return new MuleManagedConnection(this , subject, cxRequestInfo);
164:            }
165:
166:            /**
167:             * Returns a matched managed connection from the candidate set of connections.
168:             * ManagedConnectionFactory uses the security info (as in Subject) and
169:             * information provided through ConnectionRequestInfo and additional Resource
170:             * Adapter specific criteria to do matching. A MC that has the requested store is
171:             * returned as a match
172:             * 
173:             * @param connectionSet candidate connection set
174:             * @param subject caller's security information
175:             * @param cxRequestInfo additional resource adapter specific connection request
176:             *            information
177:             * @return ManagedConnection if resource adapter finds an acceptable match,
178:             *         otherwise null
179:             * @throws ResourceException if the match fails
180:             */
181:
182:            public ManagedConnection matchManagedConnections(Set connectionSet,
183:                    Subject subject, ConnectionRequestInfo cxRequestInfo)
184:                    throws ResourceException {
185:                PasswordCredential pc = RaHelper.getPasswordCredential(this ,
186:                        subject, cxRequestInfo);
187:
188:                Iterator it = connectionSet.iterator();
189:                while (it.hasNext()) {
190:                    Object obj = it.next();
191:                    if (obj instanceof  MuleManagedConnection) {
192:                        MuleManagedConnection mc = (MuleManagedConnection) obj;
193:                        PasswordCredential mcpc = mc.getPasswordCredential();
194:                        if (mcpc != null && pc != null && mcpc.equals(pc)) {
195:                            return mc;
196:                        }
197:                    }
198:                }
199:                return null;
200:            }
201:
202:            /**
203:             * Sets the log writer for this ManagedConnectionFactory instance. The log writer
204:             * is a character output stream to which all logging and tracing messages for
205:             * this ManagedConnectionfactory instance will be printed.
206:             * 
207:             * @param out an output stream for error logging and tracing
208:             * @throws ResourceException if the method fails
209:             */
210:
211:            public void setLogWriter(PrintWriter out) throws ResourceException {
212:                this .out = out;
213:            }
214:
215:            /**
216:             * Gets the log writer for this ManagedConnectionFactory instance.
217:             * 
218:             * @return PrintWriter an output stream for error logging and tracing
219:             * @throws ResourceException if the method fails
220:             */
221:
222:            public PrintWriter getLogWriter() throws ResourceException {
223:                return this .out;
224:            }
225:
226:            /**
227:             * Associate PropertyChangeListener with the ManagedConnectionFactory, in order
228:             * to notify about properties changes.
229:             * 
230:             * @param lis the PropertyChangeListener to be associated with the
231:             *            ManagedConnectionFactory
232:             */
233:
234:            public void addPropertyChangeListener(PropertyChangeListener lis) {
235:                changes.addPropertyChangeListener(lis);
236:            }
237:
238:            /**
239:             * Delete association of PropertyChangeListener with the
240:             * ManagedConnectionFactory.
241:             * 
242:             * @param lis the PropertyChangeListener to be removed
243:             */
244:
245:            public void removePropertyChangeListener(PropertyChangeListener lis) {
246:                changes.removePropertyChangeListener(lis);
247:            }
248:
249:            /**
250:             * Returns the value of the userName property.
251:             * 
252:             * @return the value of the userName property
253:             */
254:
255:            public String getUsername() {
256:                return this .username;
257:            }
258:
259:            /**
260:             * Sets the value of the userName property.
261:             * 
262:             * @param username String containing the value to be assigned to userName
263:             */
264:
265:            public void setUsername(String username) {
266:                this .username = username;
267:            }
268:
269:            /**
270:             * Returns the value of the password property.
271:             * 
272:             * @return the value of the password property
273:             */
274:
275:            public String getPassword() {
276:                return this .password;
277:            }
278:
279:            /**
280:             * Sets the value of the password property.
281:             * 
282:             * @param password String containing the value to be assigned to password
283:             */
284:
285:            public void setPassword(String password) {
286:                this.password = password;
287:            }
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.