01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: CMTSupportsTransactionInterceptor.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.transaction.interceptors;
25:
26: import javax.ejb.EJBException;
27: import javax.transaction.SystemException;
28: import javax.transaction.Transaction;
29:
30: import org.ow2.easybeans.api.EasyBeansInvocationContext;
31: import org.ow2.util.log.Log;
32: import org.ow2.util.log.LogFactory;
33:
34: /**
35: * Defines an interceptor for method using the SUPPORTS attribute.
36: * @author Florent Benoit
37: */
38: public class CMTSupportsTransactionInterceptor extends
39: AbsTransactionInterceptor {
40:
41: /**
42: * Logger.
43: */
44: private Log logger = LogFactory
45: .getLog(CMTSupportsTransactionInterceptor.class);
46:
47: /**
48: * Constructor.<br>
49: * Acquire the transaction manager.
50: */
51: public CMTSupportsTransactionInterceptor() {
52: super ();
53: }
54:
55: /**
56: * Execute transaction as specified with the SUPPORTS attribute.
57: * @param invocationContext context with useful attributes on the current
58: * invocation
59: * @return result of the next invocation (to chain interceptors)
60: * @throws Exception if interceptor fails
61: * @see <a href="http://www.jcp.org/en/jsr/detail?id=220">EJB 3.0
62: * specification ?12.6.2.3</a>
63: */
64: @Override
65: public Object intercept(
66: final EasyBeansInvocationContext invocationContext)
67: throws Exception {
68: logger.debug("Calling Supports TX interceptor");
69:
70: // Get current transaction
71: Transaction transaction;
72: try {
73: transaction = getTransactionManager().getTransaction();
74: } catch (SystemException se) {
75: throw new EJBException(
76: "Cannot get the current transaction on transaction manager.",
77: se);
78: }
79:
80: logger.debug("Transaction found = {0}", transaction);
81:
82: try {
83: return invocationContext.proceed();
84: } catch (Exception e) {
85:
86: // Chapter 14.3.1
87: // Runs in the context of the client
88: handleContextClientTransaction(invocationContext, e);
89:
90: // Shouldn't come here
91: return null;
92: }
93: }
94:
95: }
|