KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import org.objectweb.jac.aspects.distrans.persistence.PersistenceAC;
23 import org.objectweb.jac.core.ACManager;
24 import org.objectweb.jac.core.AspectComponent;
25 import org.objectweb.jac.core.NameRepository;
26 import org.objectweb.jac.core.Wrapper;
27 import org.objectweb.jac.core.rtti.ClassItem;
28 import org.objectweb.jac.core.rtti.ClassRepository;
29 import org.objectweb.jac.util.Log;
30 import org.objectweb.jac.util.Repository;
31
32 /**
33  * This AC implements some transactional behaviors for business methods.
34  * This AC relies:
35  * <ul>
36  * <li>on JOTM to perform distributed transactions</li>
37  * <li>on a AC implementing jac.aspects.distrans.persistence.PersistenceAC
38  * to store persistent data involved into the transactions</li>
39  * </ul>
40  *
41  * @author Lionel Seinturier <Lionel.Seinturier@lip6.fr>
42  * @version 1.0
43  */

44 public class DisTransAC extends AspectComponent {
45     
46     /** The PersistenceAC associated to this aspect. */
47     private PersistenceAC persistenceAC;
48
49     public DisTransAC() {
50         
51         /**
52          * Check whether a AC implementing
53          * jac.aspects.distrans.persistence.PersistenceItf has been woven.
54          * DisTransAC relies on it to store persistence data involved in the
55          * transaction.
56          */

57         persistenceAC = null;
58
59         ACManager acm = ACManager.getACM();
60         Object JavaDoc[] acs = acm.getObjects();
61         for (int i = 0; i < acs.length; i++) {
62             if ( acs[i] instanceof PersistenceAC )
63                 persistenceAC = (PersistenceAC)acs[i];
64         }
65         
66         if ( persistenceAC == null )
67             throw new RuntimeException JavaDoc(
68                 "An AC implementing jac.aspects.distrans.persistence.PersistenceItf is mandatory for DisTransAC to work"
69             );
70     }
71     
72     
73     /**
74      * Delimit a transaction.
75      * The transaction will begin before the method designated by the pointcut
76      * designated by the 3 first parameter, and will end after the pointcut
77      * designated by the 3 last ones.
78      *
79      * @param txid the transaction identifier
80      * @param beginCNE begin class name expression
81      * @param beginONE begin object name expression
82      * @param beginMNE begin method name expression
83      * @param endCNE end class name expression
84      * @param endONE end object name expression
85      * @param endMNE end method name expression
86      * @param decisionClassName the name of the class defining the method
87      * for deciding whether the transaction is to be commited
88      * or rollbacked.
89      * This must be a subclass of EndTransactionWrapper.
90      */

91     public void delimitTransaction(
92         String JavaDoc txid,
93         String JavaDoc beginCNE, String JavaDoc beginONE, String JavaDoc beginMNE,
94         String JavaDoc endCNE, String JavaDoc endONE, String JavaDoc endMNE,
95         String JavaDoc decisionClassName ) {
96             
97         BeginTransactionWrapper beginwrapper =
98             new BeginTransactionWrapper(this);
99         
100         ClassItem cl = classes.getClass(decisionClassName);
101         
102         Wrapper endwrapper = null;
103         try {
104             endwrapper = (Wrapper)
105                 cl.newInstance(
106                     new Class JavaDoc[]{AspectComponent.class},
107                     new Object JavaDoc[]{this}
108                 );
109         } catch (Exception JavaDoc e) {
110             Log.error("delimitTransaction: Failed to instanciate endwrapper "+decisionClassName);
111             e.printStackTrace();
112         }
113         pointcut(beginONE, beginCNE, beginMNE, beginwrapper, null);
114         pointcut(endONE, endCNE, endMNE, endwrapper, null);
115     }
116     
117         
118     /**
119      * The reference towards the JAC name repository.
120      * Needed by setFieldsValueFromDataSource().
121      */

122     private Repository names = NameRepository.get();
123
124     /**
125      * The reference towards the RTTI class repository.
126      */

127     private ClassRepository classes = ClassRepository.get();
128 }
129
Popular Tags