001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JEntityRemote.java 7900 2006-01-18 16:04:21Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.container;
025:
026: import java.rmi.Remote;
027: import java.rmi.RemoteException;
028:
029: import javax.ejb.EJBException;
030: import javax.ejb.EJBHome;
031: import javax.ejb.EJBObject;
032:
033: import org.objectweb.carol.rmi.exception.RmiUtility;
034:
035: import org.objectweb.jonas_ejb.lib.EJBInvocation;
036:
037: import org.objectweb.util.monolog.api.BasicLevel;
038:
039: /**
040: * Generic part of the EJBObject implementation
041: * @author Philippe Coq
042: * @author Philippe Durieux
043: */
044: public abstract class JEntityRemote extends JRemote implements Remote {
045:
046: protected JEntityFactory ebf;
047:
048: protected JEntitySwitch bs;
049:
050: /**
051: * constructor
052: * @param bf The Entity Factory
053: */
054: public JEntityRemote(JEntityFactory bf) throws RemoteException {
055: super (bf);
056: if (TraceEjb.isDebugIc()) {
057: TraceEjb.interp.log(BasicLevel.DEBUG, "");
058: }
059: this .ebf = bf;
060: }
061:
062: /**
063: * finish initialization
064: * @param bs The Entity Bean Switch
065: */
066: public void setEntitySwitch(JEntitySwitch bs) {
067: if (TraceEjb.isDebugIc()) {
068: TraceEjb.interp.log(BasicLevel.DEBUG, "");
069: }
070: this .bs = bs;
071: }
072:
073: // --------------------------------------------------------------------------
074: // EJBObject implementation
075: // remove() is implemented in the generated part.
076: // --------------------------------------------------------------------------
077:
078: /**
079: * @return the enterprise Bean's home interface.
080: */
081: public EJBHome getEJBHome() {
082: if (TraceEjb.isDebugIc()) {
083: TraceEjb.interp.log(BasicLevel.DEBUG, "");
084: }
085:
086: /*
087: * try/catch block is commented because the encapsulated code don't
088: * throw a RemoteException for the moment
089: * If the code changes and throws a such exception, let's think
090: * to uncomment it
091: *
092: * try {
093: */
094:
095: return ebf.getHome();
096:
097: /*
098: * } catch (RemoteException e) {
099: * // check if rmi exception mapping is needed - if yes the method rethrows it
100: * RmiUtility.rethrowRmiException(e);
101: * // if not, throws the exception just as it is
102: * throw e;
103: * }
104: */
105:
106: }
107:
108: /**
109: * @return the Primary Key for this EJBObject
110: * @throws EJBException Bean has no primary key yet.
111: */
112: public Object getPrimaryKey() {
113: if (TraceEjb.isDebugIc()) {
114: TraceEjb.interp.log(BasicLevel.DEBUG, "");
115: }
116: /*
117: * try/catch block is commented because the encapsulated code don't
118: * throw a RemoteException for the moment
119: * If the code changes and throws a such exception, let's think
120: * to uncomment it
121: *
122: * try {
123: */
124:
125: if (bs == null) {
126: throw new EJBException("No Primary Key yet");
127: }
128: return bs.getPrimaryKey();
129:
130: /*
131: * } catch (RemoteException e) {
132: * // check if rmi exception mapping is needed - if yes the method rethrows it
133: * RmiUtility.rethrowRmiException(e);
134: * // if not, throws the exception just as it is
135: * throw e;
136: * }
137: */
138:
139: }
140:
141: /**
142: * Tests if a given EJB is identical to the invoked EJB object.
143: * @param obj - An object to test for identity with the invoked object.
144: * @return True if the given EJB object is identical to the invoked object.
145: * @throws RemoteException Thrown when the method failed due to a
146: * system-level failure.
147: */
148: public boolean isIdentical(EJBObject obj) throws RemoteException {
149: if (TraceEjb.isDebugIc()) {
150: TraceEjb.interp.log(BasicLevel.DEBUG, "");
151: }
152:
153: try {
154:
155: boolean ret = false;
156:
157: if (obj != null) { // Get the home class name
158: String homeClassName = getEJBHome().getEJBMetaData()
159: .getHomeInterfaceClass().getName();
160: String objHomeClassName = obj.getEJBHome()
161: .getEJBMetaData().getHomeInterfaceClass()
162: .getName();
163:
164: // Tests the home equality and the primary key equality
165: ret = ((obj.equals(this )) || ((objHomeClassName
166: .equals(homeClassName)) && (obj.getPrimaryKey()
167: .equals(getPrimaryKey()))));
168: }
169:
170: return ret;
171:
172: } catch (RemoteException e) {
173: // check if rmi exception mapping is needed - if yes the method rethrows it
174: RmiUtility.rethrowRmiException(e);
175: // if not, throws the exception just as it is
176: throw e;
177: }
178:
179: }
180:
181: // ---------------------------------------------------------------
182: // other public methods, for internal use.
183: // ---------------------------------------------------------------
184:
185: /**
186: * preInvoke is called before any request.
187: * @param txa Transaction Attribute (Supports, Required, ...)
188: * @return A RequestCtx object
189: * @throws RemoteException
190: */
191: public RequestCtx preInvoke(int txa) throws RemoteException {
192: if (TraceEjb.isDebugIc()) {
193: TraceEjb.interp.log(BasicLevel.DEBUG, "");
194: }
195: return bf.preInvokeRemote(txa);
196: }
197:
198: /**
199: * Check if the access to the bean is authorized
200: * @param ejbInv object containing security signature of the method, args of
201: * method, etc
202: */
203: public void checkSecurity(EJBInvocation ejbInv) {
204: if (TraceEjb.isDebugIc()) {
205: TraceEjb.interp.log(BasicLevel.DEBUG, "");
206: }
207: bf.checkSecurity(ejbInv);
208: }
209:
210: /**
211: * postInvoke is called after any request.
212: * @param rctx The RequestCtx that was returned at preInvoke()
213: * @throws RemoteException
214: */
215: public void postInvoke(RequestCtx rctx) throws RemoteException {
216: if (TraceEjb.isDebugIc()) {
217: TraceEjb.interp.log(BasicLevel.DEBUG, "");
218: }
219: try {
220: bf.postInvokeRemote(rctx);
221: } finally {
222: bs.releaseICtx(rctx.currTx, rctx.sysExc != null);
223: }
224: }
225:
226: }
|