Source Code Cross Referenced for ManagedConnectionSupport.java in  » Workflow-Engines » wfmopen-2.1.1 » de » danet » an » util » ra » 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 » Workflow Engines » wfmopen 2.1.1 » de.danet.an.util.ra 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
004:         * All rights reserved.
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         * (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * $Id: ManagedConnectionSupport.java,v 1.1 2007/05/17 21:52:59 mlipp Exp $
021:         *
022:         * $Log: ManagedConnectionSupport.java,v $
023:         * Revision 1.1  2007/05/17 21:52:59  mlipp
024:         * Refactored resource adaptors.
025:         *
026:         */
027:        package de.danet.an.util.ra;
028:
029:        import java.io.PrintWriter;
030:        import java.security.Principal;
031:        import java.util.ArrayList;
032:        import java.util.Collections;
033:        import java.util.HashSet;
034:        import java.util.Iterator;
035:        import java.util.List;
036:        import java.util.Set;
037:
038:        import javax.resource.NotSupportedException;
039:        import javax.resource.ResourceException;
040:        import javax.resource.spi.ConnectionEvent;
041:        import javax.resource.spi.ConnectionEventListener;
042:        import javax.resource.spi.ConnectionRequestInfo;
043:        import javax.resource.spi.LocalTransaction;
044:        import javax.resource.spi.ManagedConnection;
045:        import javax.resource.spi.ManagedConnectionMetaData;
046:        import javax.security.auth.Subject;
047:        import javax.transaction.xa.XAResource;
048:
049:        /**
050:         * This class provides a base for implementing managed connections.
051:         *
052:         * @author mnl
053:         *
054:         */
055:        public abstract class ManagedConnectionSupport implements 
056:                ManagedConnection {
057:
058:            private Set connections = Collections
059:                    .synchronizedSet(new HashSet());
060:            private List listeners = Collections
061:                    .synchronizedList(new ArrayList());
062:            private PrintWriter logWriter;
063:            private ManagedConnectionMetaData metaData;
064:
065:            /**
066:             * Create a new instance with all attributes initialized
067:             * to defaults or the given values.
068:             * @param the managed connection factory
069:             * @param subject security context as JAAS subject 
070:             * 
071:             */
072:            public ManagedConnectionSupport(
073:                    ManagedConnectionFactorySupport mcf, Subject subject) {
074:                try {
075:                    this .logWriter = mcf.getLogWriter();
076:                } catch (ResourceException e) {
077:                    throw (IllegalArgumentException) (new IllegalArgumentException(
078:                            "Cannot get log writer: " + e.getMessage()))
079:                            .initCause(e);
080:                }
081:                String userName = null;
082:                if (subject != null && subject.getPrincipals() != null
083:                        && subject.getPrincipals().size() > 0) {
084:                    userName = ((Principal) subject.getPrincipals().iterator()
085:                            .next()).getName();
086:                }
087:                metaData = mcf.createMetaData(userName);
088:            }
089:
090:            /* (non-Javadoc)
091:             * @see javax.resource.spi.ManagedConnection#destroy()
092:             */
093:            public final void destroy() throws ResourceException {
094:                cleanup();
095:                connections = null;
096:                listeners = null;
097:                doDestroy();
098:            }
099:
100:            /**
101:             * Destroy any resources allocated by the derived class. This is
102:             * invoked after the cleanup done by <code>destroy</code> for this
103:             * class.
104:             */
105:            protected abstract void doDestroy();
106:
107:            /* (non-Javadoc)
108:             * @see javax.resource.spi.ManagedConnection#getConnection
109:             */
110:            public Object getConnection(Subject subject,
111:                    ConnectionRequestInfo cxRequestInfo)
112:                    throws ResourceException {
113:                ConnectionSupport connection = createConnection(subject,
114:                        cxRequestInfo);
115:                connection.setManagedConnection(this );
116:                connections.add(connection);
117:                return connection;
118:            }
119:
120:            /**
121:             * Create a connection. This method must be implemented by derived
122:             * classes. 
123:             * 
124:             * @param subject security context as JAAS subject
125:             * @param cxRequestInfo ConnectionRequestInfo instance
126:             * @return the connection implementation object
127:             * @see javax.resource.spi.ManagedConnection#getConnection
128:             */
129:            protected abstract ConnectionSupport createConnection(
130:                    Subject subject, ConnectionRequestInfo cxRequestInfo);
131:
132:            /**
133:             * Close the managed connection.
134:             */
135:            public void close(ConnectionSupport connection) {
136:                ConnectionEvent event = new ConnectionEvent(this ,
137:                        ConnectionEvent.CONNECTION_CLOSED);
138:                event.setConnectionHandle(connection);
139:                for (Iterator i = listeners.iterator(); i.hasNext();) {
140:                    ((ConnectionEventListener) i.next())
141:                            .connectionClosed(event);
142:                }
143:                connection.setManagedConnection(null);
144:                connections.remove(connection);
145:            }
146:
147:            /* (non-Javadoc)
148:             * @see javax.resource.spi.ManagedConnection#associateConnection(java.lang.Object)
149:             */
150:            public void associateConnection(Object newConnection)
151:                    throws ResourceException {
152:                ((ConnectionSupport) newConnection).setManagedConnection(this );
153:                connections.add(newConnection);
154:            }
155:
156:            /* (non-Javadoc)
157:             * @see javax.resource.spi.ManagedConnection#cleanup()
158:             */
159:            public void cleanup() throws ResourceException {
160:                for (Iterator i = connections.iterator(); i.hasNext();) {
161:                    ConnectionSupport con = (ConnectionSupport) i.next();
162:                    con.setManagedConnection(null);
163:                }
164:                connections.clear();
165:            }
166:
167:            /* (non-Javadoc)
168:             * @see javax.resource.spi.ManagedConnection#getLocalTransaction()
169:             */
170:            public LocalTransaction getLocalTransaction()
171:                    throws ResourceException {
172:                throw new NotSupportedException("Not supported.");
173:            }
174:
175:            /* (non-Javadoc)
176:             * @see javax.resource.spi.ManagedConnection#getXAResource()
177:             */
178:            public XAResource getXAResource() throws ResourceException {
179:                throw new NotSupportedException("Not supported.");
180:            }
181:
182:            /* (non-Javadoc)
183:             * @see javax.resource.spi.ManagedConnection#setLogWriter(java.io.PrintWriter)
184:             */
185:            public void setLogWriter(PrintWriter logWriter)
186:                    throws ResourceException {
187:                this .logWriter = logWriter;
188:            }
189:
190:            /* (non-Javadoc)
191:             * @see javax.resource.spi.ManagedConnection#getLogWriter()
192:             */
193:            public PrintWriter getLogWriter() throws ResourceException {
194:                return logWriter;
195:            }
196:
197:            /* (non-Javadoc)
198:             * @see javax.resource.spi.ManagedConnection#getMetaData()
199:             */
200:            public ManagedConnectionMetaData getMetaData()
201:                    throws ResourceException {
202:                return metaData;
203:            }
204:
205:            /* (non-Javadoc)
206:             * @see javax.resource.spi.ManagedConnection#addConnectionEventListener(javax.resource.spi.ConnectionEventListener)
207:             */
208:            public void addConnectionEventListener(
209:                    ConnectionEventListener listener) {
210:                listeners.add(listener);
211:            }
212:
213:            /* (non-Javadoc)
214:             * @see javax.resource.spi.ManagedConnection#removeConnectionEventListener(javax.resource.spi.ConnectionEventListener)
215:             */
216:            public void removeConnectionEventListener(
217:                    ConnectionEventListener listener) {
218:                listeners.remove(listener);
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.