KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > JEntityLocal


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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: JEntityLocal.java,v 1.11 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.EJBLocalHome JavaDoc;
30 import javax.ejb.EJBLocalObject JavaDoc;
31 import javax.ejb.RemoveException JavaDoc;
32
33 import org.objectweb.jonas_ejb.lib.EJBInvocation;
34
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * Generic part of the EJBLocalObject implementation
39  * @author Philippe Durieux
40  */

41 public abstract class JEntityLocal extends JLocal {
42
43     protected JEntityFactory bf;
44
45     protected JEntitySwitch bs;
46
47     /**
48      * constructor
49      * @param bf The Entity Factory
50      */

51     public JEntityLocal(JEntityFactory bf) {
52         super(bf);
53         if (TraceEjb.isDebugIc()) {
54             TraceEjb.interp.log(BasicLevel.DEBUG, "");
55         }
56         this.bf = bf;
57     }
58
59     /**
60      * finish initialization
61      * @param bs The Entity Bean Switch
62      */

63     public void setEntitySwitch(JEntitySwitch bs) {
64         if (TraceEjb.isDebugIc()) {
65             TraceEjb.interp.log(BasicLevel.DEBUG, "");
66         }
67         this.bs = bs;
68     }
69
70     // --------------------------------------------------------------------------
71
// EJBLocalObject implementation
72
// remove() is implemented in the generated part.
73
// --------------------------------------------------------------------------
74

75     /**
76      * Remove this instance.
77      * @throws RemoveException Instance could not be removed.
78      */

79     public abstract void remove() throws RemoveException JavaDoc;
80
81     /**
82      * @return the enterprise Bean's local home interface.
83      */

84     public EJBLocalHome JavaDoc getEJBLocalHome() {
85         if (TraceEjb.isDebugIc()) {
86             TraceEjb.interp.log(BasicLevel.DEBUG, "");
87         }
88         return bf.getLocalHome();
89     }
90
91     /**
92      * @return the Primary Key for this EJBLocalObject
93      */

94     public Object JavaDoc getPrimaryKey() {
95         if (TraceEjb.isDebugIc()) {
96             TraceEjb.interp.log(BasicLevel.DEBUG, "");
97         }
98         if (bs == null) {
99             throw new EJBException JavaDoc("No Primary Key yet");
100         }
101         return bs.getPrimaryKey();
102     }
103
104     /**
105      * Tests if a given EJB is identical to the invoked EJB object.
106      * @param obj - An object to test for identity with the invoked object.
107      * @return True if the given EJB object is identical to the invoked object.
108      * @throws EJBException: Thrown when the method failed due to a system-level
109      * failure.
110      */

111     public boolean isIdentical(EJBLocalObject JavaDoc obj) {
112         if (TraceEjb.isDebugIc()) {
113             TraceEjb.interp.log(BasicLevel.DEBUG, "");
114         }
115         boolean ret = false;
116         if (obj != null) {
117             // Get the home class name
118
String JavaDoc homeClassName = getEJBLocalHome().getClass().getName();
119             String JavaDoc objHomeClassName = obj.getEJBLocalHome().getClass().getName();
120
121             // Tests the home equality and the primary key equality
122
ret = ((objHomeClassName.equals(homeClassName)) && (obj.getPrimaryKey().equals(getPrimaryKey())));
123         }
124         return ret;
125     }
126
127     /**
128      * preInvoke is called before any request.
129      * @param txa Transaction Attribute (Supports, Required, ...)
130      * @return A RequestCtx object
131      * @throws EJBException
132      */

133     public RequestCtx preInvoke(int txa) {
134         if (TraceEjb.isDebugIc()) {
135             TraceEjb.interp.log(BasicLevel.DEBUG, "");
136         }
137         return bf.preInvoke(txa);
138     }
139
140     /**
141      * Check if the access to the bean is authorized
142      * @param ejbInv object containing security signature of the method, args of
143      * method, etc
144      */

145      public void checkSecurity(EJBInvocation ejbInv) {
146          if (TraceEjb.isDebugIc()) {
147              TraceEjb.interp.log(BasicLevel.DEBUG, "");
148          }
149          bf.checkSecurity(ejbInv);
150      }
151
152     /**
153      * postInvoke is called after any request.
154      * @param rctx The RequestCtx that was returned at preInvoke()
155      * @throws EJBException
156      */

157     public void postInvoke(RequestCtx rctx) {
158         if (TraceEjb.isDebugIc()) {
159             TraceEjb.interp.log(BasicLevel.DEBUG, "");
160         }
161         try {
162             bf.postInvoke(rctx);
163         } finally {
164             if (rctx.sysExc != null) {
165                 bs.discardICtx(rctx.currTx);
166             } else {
167                 bs.releaseICtx(rctx.currTx);
168             }
169         }
170     }
171 }
Popular Tags