KickJava   Java API By Example, From Geeks To Geeks.

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


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: TxNever.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.6 Never
53  *
54  * The Container invokes an enterprise Bean method whose transaction attribute
55  * is set to Never without a transaction context defined by the EJB spec.
56  *
57  * The client is required to call without a transaction context.
58  *
59  * • If the client calls with a transaction context, the Container throws the
60  * java.rmi.RemoteException exception if the client is a remote client, or
61  * the javax.ejb.EJBException if the client is a local client.
62  * • If the client calls without a transaction context, the Container performs
63  * the same steps as described in the NotSupported case.
64  *
65  * @author <a HREF="mailto=david.blevins@visi.com">David Blevins</a>
66  * @version $Revision: 1912 $ $Date: 2005-06-16 15:29:56 -0700 (Thu, 16 Jun 2005) $
67  */

68 public class TxNever extends TransactionPolicy {
69     
70     public TxNever(TransactionContainer container){
71         this();
72         this.container = container;
73     }
74
75     public TxNever(){
76         policyType = Never;
77     }
78     
79     public String JavaDoc policyToString() {
80         return "TX_Never: ";
81     }
82
83     public void beforeInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{
84         
85         try {
86         
87             if ( getTxMngr().getTransaction() != null ){
88                 // TODO:3: Localize the message; add to Messages.java
89
throw new ApplicationException(new java.rmi.RemoteException JavaDoc("Transactions not supported"));
90             }
91         
92         } catch ( javax.transaction.SystemException JavaDoc se ) {
93             logger.error("Exception during getTransaction()", se);
94             throw new org.openejb.SystemException(se);
95         }
96     }
97
98     public void afterInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
99         // Nothing to do
100
}
101
102     
103     /**
104      * <B>Container's action</B>
105      *
106      * <P>
107      * Re-throw AppException
108      * </P>
109      *
110      * <B>Client's view</B>
111      *
112      * <P>
113      * Receives AppException.
114      *
115      * If the client executes in a transaction, the client's transaction is not
116      * marked for rollback, and client can continue its work.
117      * </P>
118      */

119     public void handleApplicationException( Throwable JavaDoc appException, TransactionContext context) throws ApplicationException{
120         // Re-throw AppException
121
throw new ApplicationException( appException );
122     }
123     
124     /**
125      * A system exception is any exception that is not an Application Exception.
126      *
127      * <B>Container's action</B>
128      *
129      * <P>
130      * <OL>
131      * <LI>
132      * Log the exception or error so that the System Administrator is alerted of
133      * the problem.
134      * </LI>
135      * <LI>
136      * Discard instance. The Container must not invoke any business methods or
137      * container callbacks on the instance.
138      * </LI>
139      * <LI>
140      * Throw RemoteException to remote client;
141      * throw EJBException to local client.
142      * </LI>
143      * </OL>
144      *
145      * </P>
146      *
147      * <B>Client's view</B>
148      *
149      * <P>
150      * Receives RemoteException or EJBException.
151      *
152      * If the client executes in a transaction, the client's transaction may or
153      * may not be marked for rollback.
154      * </P>
155      */

156     public void handleSystemException( Throwable JavaDoc sysException, EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
157         /* [1] Log the system exception or error *********/
158         logSystemException( sysException );
159
160         /* [2] Discard instance. *************************/
161         discardBeanInstance( instance, context.callContext);
162
163         /* [3] Throw RemoteException to client ***********/
164         throwExceptionToServer( sysException );
165     }
166
167 }
168
169
Popular Tags