01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.core.aspects.portlet;
23:
24: import org.jboss.portal.common.invocation.InvocationException;
25: import org.jboss.portal.common.transaction.Transactions;
26: import org.jboss.portal.core.portlet.info.CorePortletInfo;
27: import org.jboss.portal.portlet.container.PortletContainer;
28: import org.jboss.portal.portlet.container.PortletContainerInvoker;
29: import org.jboss.portal.portlet.invocation.PortletInterceptor;
30: import org.jboss.portal.portlet.invocation.PortletInvocation;
31:
32: /**
33: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
34: * @version $Revision: 8786 $
35: */
36: public class TransactionInterceptor extends PortletInterceptor {
37:
38: protected Object invoke(PortletInvocation invocation)
39: throws Exception, InvocationException {
40: // The default type is that it does not propagate
41: Transactions.Type txType = Transactions.TYPE_NOT_SUPPORTED;
42:
43: // Override tx type if found
44: PortletContainer container = (PortletContainer) invocation
45: .getAttribute(PortletInvocation.INVOCATION_SCOPE,
46: PortletContainerInvoker.PORTLET_CONTAINER);
47: CorePortletInfo info = (CorePortletInfo) container.getInfo();
48: if (info != null) {
49: txType = info.getTxType();
50: }
51:
52: //
53: if (txType == Transactions.TYPE_NOT_SUPPORTED) {
54: return invokeNotSupported(invocation);
55: } else if (txType == Transactions.TYPE_NEVER) {
56: return invokeNever(invocation);
57: } else if (txType == Transactions.TYPE_MANDATORY) {
58: return invokeMandatory(invocation);
59: } else if (txType == Transactions.TYPE_SUPPORTS) {
60: return invokeSupports(invocation);
61: } else if (txType == Transactions.TYPE_REQUIRED) {
62: return invokeRequired(invocation);
63: } else if (txType == Transactions.TYPE_REQUIRES_NEW) {
64: return invokeRequiresNew(invocation);
65: } else {
66: throw new InvocationException("Should not happen");
67: }
68: }
69:
70: protected Object invokeNotSupported(PortletInvocation invocation)
71: throws Exception, InvocationException {
72: return invocation.invokeNext();
73: }
74:
75: protected Object invokeNever(PortletInvocation invocation)
76: throws Exception, InvocationException {
77: return invocation.invokeNext();
78: }
79:
80: protected Object invokeMandatory(PortletInvocation invocation)
81: throws Exception, InvocationException {
82: return invocation.invokeNext();
83: }
84:
85: protected Object invokeSupports(PortletInvocation invocation)
86: throws Exception, InvocationException {
87: return invocation.invokeNext();
88: }
89:
90: protected Object invokeRequired(PortletInvocation invocation)
91: throws Exception, InvocationException {
92: return invocation.invokeNext();
93: }
94:
95: protected Object invokeRequiresNew(PortletInvocation invocation)
96: throws Exception, InvocationException {
97: return invocation.invokeNext();
98: }
99: }
|