KickJava   Java API By Example, From Geeks To Geeks.

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


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: JServiceEndpoint.java,v 1.9 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ejb.container;
26
27 import java.rmi.NoSuchObjectException JavaDoc;
28 import java.rmi.Remote JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.ejb.EJBException JavaDoc;
32 import javax.naming.NamingException JavaDoc;
33 import javax.rmi.PortableRemoteObject JavaDoc;
34 import javax.xml.rpc.ServiceException JavaDoc;
35 import javax.xml.rpc.handler.MessageContext JavaDoc;
36 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
37
38 import org.objectweb.jonas.common.Log;
39 import org.objectweb.jonas_ejb.deployment.api.MethodDesc;
40 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
41 import org.objectweb.jonas_ejb.lib.EJBInvocation;
42
43 import org.objectweb.util.monolog.api.BasicLevel;
44 import org.objectweb.util.monolog.api.Logger;
45
46 /**
47  * Implementation of the Service Endpoint Interface.
48  * The lifeCycle of this object is managed by the JOnASEJBProvider.
49  * Although this object implements Remote, it is accessed locally today.
50  * @author Guillaume Sauthier, Philippe Durieux
51  */

52 public class JServiceEndpoint extends PortableRemoteObject JavaDoc implements Remote JavaDoc, ServiceLifecycle JavaDoc {
53
54     /**
55      * Logger, used also in the generated part.
56      */

57     protected static Logger logger = null;
58
59     /**
60      * switch instance to use
61      */

62     protected JSessionSwitch bs;
63
64     /**
65      * bean factory
66      */

67     protected JStatelessFactory bf;
68
69     private MessageContext JavaDoc messageContext = null;
70
71     /**
72      * @throws java.rmi.RemoteException
73      */

74     public JServiceEndpoint(JStatelessFactory sf) throws RemoteException JavaDoc {
75         super();
76         logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX);
77         if (logger.isLoggable(BasicLevel.DEBUG)) {
78             logger.log(BasicLevel.DEBUG, "");
79         }
80         bf = sf;
81     }
82
83     // ---------------------------------------------------------------
84
// other public methods
85
// ---------------------------------------------------------------
86

87     /**
88      * Set the MessageContext in the StatelessContext
89      * @param msgctx Axis MessageContext
90      */

91     public void setMessageContext(MessageContext JavaDoc msgctx) {
92         messageContext = msgctx;
93     }
94
95     /**
96      * Get the messageContext
97      * @param mc JAX-RPC MessageContext
98      */

99     public MessageContext JavaDoc getMessageContext() {
100         return messageContext;
101     }
102
103     /**
104      * finish initialization
105      * @param bs The Session Switch
106      */

107     public void setSessionSwitch(JSessionSwitch bs) {
108         if (logger.isLoggable(BasicLevel.DEBUG)) {
109             logger.log(BasicLevel.DEBUG, "");
110         }
111         this.bs = bs;
112     }
113
114     /**
115      * preInvoke is called before any request.
116      * @param txa Transaction Attribute (Supports, Required, ...)
117      * @return A RequestCtx object
118      * @throws RemoteException preInvoke fail
119      */

120     public RequestCtx preInvoke(int txa) throws RemoteException JavaDoc {
121         if (logger.isLoggable(BasicLevel.DEBUG)) {
122             logger.log(BasicLevel.DEBUG, "");
123         }
124         return bf.preInvokeRemote(txa);
125     }
126
127     /**
128      * Check if the access to the bean is authorized
129      * @param ejbInv object containing security signature of the method, args of
130      * method, etc
131      */

132     public void checkSecurity(EJBInvocation ejbInv) {
133         if (logger.isLoggable(BasicLevel.DEBUG)) {
134             logger.log(BasicLevel.DEBUG, "");
135         }
136         bf.checkSecurity(ejbInv);
137     }
138
139     /**
140      * postInvoke is called after any request.
141      * @param rctx The RequestCtx that was returned at preInvoke()
142      * @throws RemoteException postInvoke fail
143      */

144     public void postInvoke(RequestCtx rctx) throws RemoteException JavaDoc {
145         if (logger.isLoggable(BasicLevel.DEBUG)) {
146             logger.log(BasicLevel.DEBUG, "");
147         }
148         try {
149             bf.postInvokeRemote(rctx);
150         } finally {
151             // put instance in the pool for future reuse.
152
bs.releaseICtx(rctx.currTx);
153         }
154     }
155
156     // --------------------------------------------------------------------
157
// ServiceLifeCycle implementation
158
// --------------------------------------------------------------------
159

160     /**
161      * Nothing to do here.
162      */

163     public void init(Object JavaDoc arg0) throws ServiceException JavaDoc {
164         if (logger.isLoggable(BasicLevel.DEBUG)) {
165             logger.log(BasicLevel.DEBUG, "");
166         }
167     }
168
169     /**
170      * remove the bean instance.
171      */

172     public void destroy() {
173         if (logger.isLoggable(BasicLevel.DEBUG)) {
174             logger.log(BasicLevel.DEBUG, "");
175         }
176         RequestCtx rctx = null;
177         try {
178             rctx = bf.preInvoke(MethodDesc.TX_NOT_SET);
179             bf.checkSecurity(null);
180         } catch (Exception JavaDoc e) {
181             logger.log(BasicLevel.ERROR, "preInvoke failed: ", e);
182             return;
183         }
184         try {
185             JSessionContext bctx = bs.getICtx(rctx.currTx);
186             bctx.setRemoved();
187         } catch (Exception JavaDoc e) {
188             rctx.sysExc = e;
189             logger.log(BasicLevel.ERROR, "EJB exception thrown:", e);
190         } catch (Error JavaDoc e) {
191             rctx.sysExc = e;
192             logger.log(BasicLevel.ERROR, "error thrown:", e);
193         } finally {
194             try {
195                 bf.postInvoke(rctx);
196             } catch (Exception JavaDoc e) {
197                 logger.log(BasicLevel.ERROR, "exception on postInvoke: ", e);
198             }
199         }
200
201     }
202
203 }
Popular Tags