KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > stateful > StatefulContainerManagedTxPolicy


1 package org.openejb.core.stateful;
2
3 import javax.ejb.EnterpriseBean JavaDoc;
4
5 import org.openejb.ApplicationException;
6 import org.openejb.InvalidateReferenceException;
7 import org.openejb.core.transaction.TransactionContext;
8 import org.openejb.core.transaction.TransactionPolicy;
9
10 /**
11  * Wraps the TxPolicies for Stateful Session beans with container-managed
12  * transaction demarkation that do not implement the SessionSynchronization
13  * interface.
14  *
15  * The following method TxPolicies are wrapped regardless:
16  *
17  * TX_NEVER
18  * TX_NOT_SUPPORTED
19  *
20  * @author <a HREF="mailto=david.blevins@visi.com">David Blevins</a>
21  * @version $Revision: 1096 $ $Date: 2004-03-26 13:41:16 -0800 (Fri, 26 Mar 2004) $
22  */

23 public class StatefulContainerManagedTxPolicy extends org.openejb.core.transaction.TransactionPolicy {
24     
25     protected TransactionPolicy policy;
26
27     public StatefulContainerManagedTxPolicy(TransactionPolicy policy){
28         this.policy = policy;
29         this.container = policy.getContainer();
30         this.policyType = policy.policyType;
31         if(container instanceof org.openejb.Container &&
32            ((org.openejb.Container)container).getContainerType()!=org.openejb.Container.STATEFUL) {
33             throw new IllegalArgumentException JavaDoc();
34         }
35     }
36
37     public String JavaDoc policyToString() {
38         return policy.policyToString();
39     }
40     
41     public void beforeInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{
42         policy.beforeInvoke( instance, context );
43     }
44
45     public void afterInvoke(EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
46         policy.afterInvoke( instance, context );
47     }
48
49     public void handleApplicationException( Throwable JavaDoc appException, TransactionContext context) throws ApplicationException{
50         policy.handleApplicationException( appException, context );
51     }
52     
53     public void handleSystemException( Throwable JavaDoc sysException, EnterpriseBean JavaDoc instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{
54         try {
55             policy.handleSystemException( sysException, instance, context );
56         } catch ( ApplicationException e ){
57             throw new InvalidateReferenceException( e.getRootCause() );
58         }
59     }
60
61 }
62
63
Popular Tags