KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > transaction > TxNotSupported


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: TxNotSupported.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.core.transaction;
46
47 import javax.ejb.EnterpriseBean JavaDoc;
48
49 import org.openejb.ApplicationException;
50
51 /**
52  * 17.6.2.1 NotSupported
53  *
54  * The Container invokes an enterprise Bean method whose transaction attribute
55  * is set to NotSupported with an unspecified transaction context.
56  *
57  * If a client calls with a transaction context, the container suspends the
58  * association of the transaction context with the current thread before
59  * invoking the enterprise bean's business method. The container resumes the
60  * suspended association when the business method has completed. The suspended
61  * transaction context of the client is not passed to the resource managers or
62  * other enterprise Bean objects that are invoked from the business method.
63  *
64  * If the business method invokes other enterprise beans, the Container passes
65  * no transaction context with the invocation.
66  *
67  * Refer to Subsection 17.6.5 for more details of how the Container can
68  * implement this case.
69  *
70  * @author <a HREF="mailto=david.blevins@visi.com">David Blevins</a>
71  * @version $Revision: 1912 $ $Date: 2005-06-16 15:29:56 -0700 (Thu, 16 Jun 2005) $
72  */

73 public class TxNotSupported extends TransactionPolicy {
74     
75     public TxNotSupported(TransactionContainer container){
76         this();
77         this.container = container;
78     }
79
80     public TxNotSupported(){
81         policyType = NotSupported;
82     }
83     
84     public String JavaDoc policyToString() {
85         return "TX_NotSupported: ";
86     }
87
88     public void beforeInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{
89         
90         try {
91             // if no transaction ---> suspend returns null
92
context.clientTx = getTxMngr().suspend();
93         } catch ( javax.transaction.SystemException JavaDoc se ) {
94             throw new org.openejb.SystemException(se);
95         }
96         context.currentTx = null;
97     
98     }
99
100     public void afterInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
101
102         if ( context.clientTx != null ) {
103             try{
104                 getTxMngr( ).resume( context.clientTx );
105             }catch(javax.transaction.InvalidTransactionException JavaDoc ite){
106                 // TODO:3: Localize the message; add to Messages.java
107
logger.error("Could not resume the client's transaction, the transaction is no longer valid: "+ite.getMessage());
108             }catch(IllegalStateException JavaDoc e){
109                 // TODO:3: Localize the message; add to Messages.java
110
logger.error("Could not resume the client's transaction: "+e.getMessage());
111             }catch(javax.transaction.SystemException JavaDoc e){
112                 // TODO:3: Localize the message; add to Messages.java
113
logger.error("Could not resume the client's transaction: The transaction reported a system exception: "+e.getMessage());
114             }
115         }
116     }
117
118     
119     /**
120      * <B>Container's action</B>
121      *
122      * <P>
123      * Re-throw AppException
124      * </P>
125      *
126      * <B>Client's view</B>
127      *
128      * <P>
129      * Receives AppException.
130      *
131      * If the client executes in a transaction, the client's transaction is not
132      * marked for rollback, and client can continue its work.
133      * </P>
134      */

135     public void handleApplicationException( Throwable JavaDoc appException, TransactionContext context) throws ApplicationException{
136         // Re-throw AppException
137
throw new ApplicationException( appException );
138     }
139     
140     /**
141      * A system exception is any exception that is not an Application Exception.
142      *
143      * <B>Container's action</B>
144      *
145      * <P>
146      * <OL>
147      * <LI>
148      * Log the exception or error so that the System Administrator is alerted of
149      * the problem.
150      * </LI>
151      * <LI>
152      * Discard instance. The Container must not invoke any business methods or
153      * container callbacks on the instance.
154      * </LI>
155      * <LI>
156      * Throw RemoteException to remote client;
157      * throw EJBException to local client.
158      * </LI>
159      * </OL>
160      *
161      * </P>
162      *
163      * <B>Client's view</B>
164      *
165      * <P>
166      * Receives RemoteException or EJBException.
167      *
168      * If the client executes in a transaction, the client's transaction may or
169      * may not be marked for rollback.
170      * </P>
171      */

172     public void handleSystemException( Throwable JavaDoc sysException, EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
173         /* [1] Log the system exception or error *********/
174         logSystemException( sysException );
175
176         /* [2] Discard instance. *************************/
177         discardBeanInstance( instance, context.callContext);
178
179         /* [3] Throw RemoteException to client ***********/
180         throwExceptionToServer( sysException );
181     }
182
183 }
184
185
Popular Tags