Source Code Cross Referenced for MockManagedConnection.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » connector » mock » 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 » EJB Server geronimo » plugins » org.apache.geronimo.connector.mock 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.connector.mock;
017:
018:        import java.io.PrintWriter;
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.HashSet;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Set;
025:        import javax.resource.ResourceException;
026:        import javax.resource.spi.ConnectionEvent;
027:        import javax.resource.spi.ConnectionEventListener;
028:        import javax.resource.spi.ConnectionRequestInfo;
029:        import javax.resource.spi.LocalTransaction;
030:        import javax.resource.spi.ManagedConnection;
031:        import javax.resource.spi.ManagedConnectionMetaData;
032:        import javax.security.auth.Subject;
033:        import javax.transaction.xa.XAResource;
034:
035:        /**
036:         *
037:         *
038:         * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
039:         *
040:         * */
041:        public class MockManagedConnection implements  ManagedConnection {
042:
043:            private final MockManagedConnectionFactory managedConnectionFactory;
044:            private final MockXAResource mockXAResource;
045:            private Subject subject;
046:            private MockConnectionRequestInfo connectionRequestInfo;
047:
048:            private final Set connections = new HashSet();
049:            private final List connectionEventListeners = Collections
050:                    .synchronizedList(new ArrayList());
051:
052:            private boolean destroyed;
053:            private PrintWriter logWriter;
054:
055:            public MockManagedConnection(
056:                    MockManagedConnectionFactory managedConnectionFactory,
057:                    Subject subject,
058:                    MockConnectionRequestInfo connectionRequestInfo) {
059:                this .managedConnectionFactory = managedConnectionFactory;
060:                mockXAResource = new MockXAResource(this );
061:                this .subject = subject;
062:                this .connectionRequestInfo = connectionRequestInfo;
063:            }
064:
065:            public Object getConnection(Subject subject,
066:                    ConnectionRequestInfo connectionRequestInfo)
067:                    throws ResourceException {
068:                checkSecurityConsistency(subject, connectionRequestInfo);
069:                MockConnection mockConnection = new MockConnection(this ,
070:                        subject,
071:                        (MockConnectionRequestInfo) connectionRequestInfo);
072:                connections.add(mockConnection);
073:                return mockConnection;
074:            }
075:
076:            private void checkSecurityConsistency(Subject subject,
077:                    ConnectionRequestInfo connectionRequestInfo) {
078:                if (!managedConnectionFactory.isReauthentication()) {
079:                    assert subject == null ? this .subject == null : subject
080:                            .equals(this .subject);
081:                    assert connectionRequestInfo == null ? this .connectionRequestInfo == null
082:                            : connectionRequestInfo
083:                                    .equals(this .connectionRequestInfo);
084:                }
085:            }
086:
087:            public void destroy() throws ResourceException {
088:                destroyed = true;
089:                cleanup();
090:            }
091:
092:            public void cleanup() throws ResourceException {
093:                for (Iterator iterator = new HashSet(connections).iterator(); iterator
094:                        .hasNext();) {
095:                    MockConnection mockConnection = (MockConnection) iterator
096:                            .next();
097:                    mockConnection.close();
098:                }
099:                assert connections.isEmpty();
100:            }
101:
102:            public void associateConnection(Object connection)
103:                    throws ResourceException {
104:                assert connection != null;
105:                assert connection.getClass() == MockConnection.class;
106:                MockConnection mockConnection = (MockConnection) connection;
107:                checkSecurityConsistency(mockConnection.getSubject(),
108:                        mockConnection.getConnectionRequestInfo());
109:                mockConnection.reassociate(this );
110:                connections.add(mockConnection);
111:            }
112:
113:            public void addConnectionEventListener(
114:                    ConnectionEventListener listener) {
115:                connectionEventListeners.add(listener);
116:            }
117:
118:            public void removeConnectionEventListener(
119:                    ConnectionEventListener listener) {
120:                connectionEventListeners.remove(listener);
121:            }
122:
123:            public XAResource getXAResource() throws ResourceException {
124:                return mockXAResource;
125:            }
126:
127:            public LocalTransaction getLocalTransaction()
128:                    throws ResourceException {
129:                return new MockSPILocalTransaction();
130:            }
131:
132:            public ManagedConnectionMetaData getMetaData()
133:                    throws ResourceException {
134:                return null;
135:            }
136:
137:            public void setLogWriter(PrintWriter logWriter)
138:                    throws ResourceException {
139:                this .logWriter = logWriter;
140:            }
141:
142:            public PrintWriter getLogWriter() throws ResourceException {
143:                return logWriter;
144:            }
145:
146:            public Subject getSubject() {
147:                return subject;
148:            }
149:
150:            public MockConnectionRequestInfo getConnectionRequestInfo() {
151:                return connectionRequestInfo;
152:            }
153:
154:            public void removeHandle(MockConnection mockConnection) {
155:                connections.remove(mockConnection);
156:            }
157:
158:            public MockManagedConnectionFactory getManagedConnectionFactory() {
159:                return managedConnectionFactory;
160:            }
161:
162:            public Set getConnections() {
163:                return connections;
164:            }
165:
166:            public List getConnectionEventListeners() {
167:                return connectionEventListeners;
168:            }
169:
170:            public boolean isDestroyed() {
171:                return destroyed;
172:            }
173:
174:            public void closedEvent(MockConnection mockConnection) {
175:                ConnectionEvent connectionEvent = new ConnectionEvent(this ,
176:                        ConnectionEvent.CONNECTION_CLOSED);
177:                connectionEvent.setConnectionHandle(mockConnection);
178:                for (Iterator iterator = new ArrayList(connectionEventListeners)
179:                        .iterator(); iterator.hasNext();) {
180:                    ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator
181:                            .next();
182:                    connectionEventListener.connectionClosed(connectionEvent);
183:                }
184:            }
185:
186:            public void errorEvent(MockConnection mockConnection) {
187:                ConnectionEvent connectionEvent = new ConnectionEvent(this ,
188:                        ConnectionEvent.CONNECTION_ERROR_OCCURRED);
189:                connectionEvent.setConnectionHandle(mockConnection);
190:                for (Iterator iterator = new ArrayList(connectionEventListeners)
191:                        .iterator(); iterator.hasNext();) {
192:                    ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator
193:                            .next();
194:                    connectionEventListener
195:                            .connectionErrorOccurred(connectionEvent);
196:                }
197:            }
198:
199:            public void localTransactionStartedEvent(
200:                    MockConnection mockConnection) {
201:                ConnectionEvent connectionEvent = new ConnectionEvent(this ,
202:                        ConnectionEvent.LOCAL_TRANSACTION_STARTED);
203:                connectionEvent.setConnectionHandle(mockConnection);
204:                for (Iterator iterator = new ArrayList(connectionEventListeners)
205:                        .iterator(); iterator.hasNext();) {
206:                    ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator
207:                            .next();
208:                    connectionEventListener
209:                            .localTransactionStarted(connectionEvent);
210:                }
211:            }
212:
213:            public void localTransactionCommittedEvent(
214:                    MockConnection mockConnection) {
215:                ConnectionEvent connectionEvent = new ConnectionEvent(this ,
216:                        ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
217:                connectionEvent.setConnectionHandle(mockConnection);
218:                for (Iterator iterator = new ArrayList(connectionEventListeners)
219:                        .iterator(); iterator.hasNext();) {
220:                    ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator
221:                            .next();
222:                    connectionEventListener
223:                            .localTransactionCommitted(connectionEvent);
224:                }
225:            }
226:
227:            public void localTransactionRolledBackEvent(
228:                    MockConnection mockConnection) {
229:                ConnectionEvent connectionEvent = new ConnectionEvent(this ,
230:                        ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
231:                connectionEvent.setConnectionHandle(mockConnection);
232:                for (Iterator iterator = new ArrayList(connectionEventListeners)
233:                        .iterator(); iterator.hasNext();) {
234:                    ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator
235:                            .next();
236:                    connectionEventListener
237:                            .localTransactionRolledback(connectionEvent);
238:                }
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.