KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > distrans > BeginTransactionWrapper


1 /*
2   Copyright (C) 2001-2003 Lionel Seinturier <Lionel.Seinturier@lip6.fr>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.distrans;
19
20
21
22 import javax.transaction.NotSupportedException JavaDoc;
23 import javax.transaction.SystemException JavaDoc;
24 import javax.transaction.UserTransaction JavaDoc;
25 import org.aopalliance.intercept.ConstructorInvocation;
26 import org.aopalliance.intercept.MethodInvocation;
27 import org.objectweb.jac.core.AspectComponent;
28 import org.objectweb.jac.core.Interaction;
29 import org.objectweb.jac.core.Wrapper;
30 import org.objectweb.jac.util.Log;
31
32 /**
33  * This wrapper delimits the begining of a transaction.
34  *
35  * @author Lionel Seinturier <Lionel.Seinturier@lip6.fr>
36  * @version 1.0
37  */

38 public class BeginTransactionWrapper extends Wrapper {
39
40     /** The transaction. */
41     private UserTransaction JavaDoc usertx;
42
43     /**
44      * @param ac the AC managing this wrapper
45      */

46     public BeginTransactionWrapper(AspectComponent ac) {
47         super(ac);
48         usertx = JOTMHelper.get().getUserTransaction();
49     }
50
51     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
52         Interaction interaction = (Interaction) invocation;
53         try {
54             return _begin(interaction);
55         } catch (Exception JavaDoc e) {
56             Log.error("Error while beginning transaction");
57             e.printStackTrace();
58         }
59         return null;
60     }
61
62     private Object JavaDoc _begin(Interaction interaction)
63         throws NotSupportedException JavaDoc, SystemException JavaDoc {
64
65         usertx.begin();
66
67         return proceed(interaction);
68     }
69
70     public Object JavaDoc construct(ConstructorInvocation invocation)
71         throws Throwable JavaDoc {
72         throw new Exception JavaDoc("This wrapper does not support constructor wrapping");
73     }
74 }
75
Popular Tags