KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server Copyright (C) 1999 Bull S.A. Contact:
3  * jonas-team@objectweb.org This library is free software; you can redistribute
4  * it and/or modify it under the terms of the GNU Lesser General Public License
5  * as published by the Free Software Foundation; either version 2.1 of the
6  * License, or any later version. This library is distributed in the hope that
7  * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
8  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9  * Lesser General Public License for more details. You should have received a
10  * copy of the GNU Lesser General Public License along with this library; if
11  * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
12  * Boston, MA 02111-1307 USA
13  * --------------------------------------------------------------------------
14  * $Id: JServiceEndpointHome.java,v 1.10 2005/05/27 15:01:23 sauthieg Exp $
15  * --------------------------------------------------------------------------
16  */

17 package org.objectweb.jonas_ejb.container;
18
19 import java.rmi.RemoteException JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.NamingException JavaDoc;
27 import javax.naming.Reference JavaDoc;
28 import javax.naming.StringRefAddr JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30 import javax.xml.soap.SOAPBody JavaDoc;
31 import javax.xml.soap.SOAPElement JavaDoc;
32 import javax.xml.soap.SOAPEnvelope JavaDoc;
33 import javax.xml.soap.SOAPException JavaDoc;
34
35 import org.apache.axis.AxisFault;
36 import org.apache.axis.MessageContext;
37
38 import org.objectweb.jonas_ejb.deployment.api.MethodDesc;
39 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
40 import org.objectweb.jonas_ejb.lib.BeanNaming;
41 import org.objectweb.jonas_ejb.lib.EJBInvocation;
42
43 import org.objectweb.jonas.common.Log;
44
45 import org.objectweb.util.monolog.api.BasicLevel;
46 import org.objectweb.util.monolog.api.Logger;
47
48 /**
49  * This class is a factory for JServiceEndpoint objects.
50  * @author Philippe Durieux
51  */

52 public abstract class JServiceEndpointHome {
53
54     /**
55      * Logger, used also in the generated part.
56      */

57     protected static Logger logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX);
58     protected static Logger lognaming = Log.getLogger(Log.JONAS_NAMING_PREFIX);
59
60     protected SessionStatelessDesc dd;
61
62     protected JFactory bf;
63
64     // The static table of all JServiceEndpointHome objects
65
protected static Map JavaDoc sehomeList = new HashMap JavaDoc();
66
67     /**
68      * constructor
69      * @param dd The Session Deployment Decriptor
70      * @param bf The Session Factory
71      */

72     public JServiceEndpointHome(SessionStatelessDesc dd, JStatelessFactory bf) {
73         if (logger.isLoggable(BasicLevel.DEBUG)) {
74             logger.log(BasicLevel.DEBUG, "");
75         }
76         this.dd = dd;
77         this.bf = bf;
78     }
79
80     /**
81      * register this bean to JNDI (rebind) We register actually a Reference
82      * object.
83      */

84     protected void register() throws NamingException JavaDoc {
85         if (logger.isLoggable(BasicLevel.DEBUG)) {
86             logger.log(BasicLevel.DEBUG, "");
87         }
88         String JavaDoc name = dd.getJndiServiceEndpointName();
89
90         // Keep it in the static list for later retrieving.
91
sehomeList.put(name, this);
92
93         Reference JavaDoc ref = new Reference JavaDoc("org.objectweb.jonas_ejb.container.JServiceEndpointHome",
94                 "org.objectweb.jonas_ejb.container.HomeFactory", null);
95         ref.add(new StringRefAddr JavaDoc("bean.name", name));
96         bf.getInitialContext().rebind(name, ref);
97     }
98
99     /**
100      * unregister this bean in JNDI (unbind)
101      */

102     protected void unregister() throws NamingException JavaDoc {
103         if (logger.isLoggable(BasicLevel.DEBUG)) {
104             logger.log(BasicLevel.DEBUG, "");
105         }
106         String JavaDoc name = dd.getJndiServiceEndpointName();
107         // unregister in default InitialContext
108
bf.getInitialContext().unbind(name);
109         // remove from the static list
110
sehomeList.remove(name);
111     }
112
113     /**
114      * Get JServiceEndpointHome by its name
115      * used by HomeFactory to retrieve object from its reference.
116      * @param beanName The Bean JNDI local Name
117      * @return The Bean ServiceEndpointHome
118      */

119     public static JServiceEndpointHome getSEHome(String JavaDoc beanName) {
120         if (logger.isLoggable(BasicLevel.DEBUG)) {
121             logger.log(BasicLevel.DEBUG, "");
122         }
123         JServiceEndpointHome seh = (JServiceEndpointHome) sehomeList.get(beanName);
124         return seh;
125     }
126
127     /**
128      * unique create method
129      */

130     public JServiceEndpoint create() throws RemoteException JavaDoc {
131         if (TraceEjb.isDebugIc()) {
132             TraceEjb.interp.log(BasicLevel.DEBUG, "");
133         }
134         RequestCtx rctx = bf.preInvoke(MethodDesc.TX_NOT_SET);
135         bf.checkSecurity(null);
136         JStatelessSwitch bs = null;
137         try {
138             bs = (JStatelessSwitch) ((JStatelessFactory) bf).createEJB();
139         } catch (javax.ejb.AccessLocalException JavaDoc e) {
140             throw new EJBException JavaDoc("Security Exception thrown by an enterprise Bean", e);
141         } catch (EJBException JavaDoc e) {
142             rctx.sysExc = e;
143             throw e;
144         } catch (RuntimeException JavaDoc e) {
145             rctx.sysExc = e;
146             throw new EJBException JavaDoc("RuntimeException thrown by an enterprise Bean", e);
147         } catch (Error JavaDoc e) {
148             rctx.sysExc = e;
149             throw new EJBException JavaDoc("Error thrown by an enterprise Bean" + e);
150         } catch (RemoteException JavaDoc e) {
151             rctx.sysExc = e;
152             throw new EJBException JavaDoc("Remote Exception raised:", e);
153         } finally {
154             bf.postInvoke(rctx);
155         }
156         return bs.getServiceEndpoint();
157     }
158
159     /**
160      * Set the bean environment in current context
161      * @return previous Context
162      */

163     public Context JavaDoc setCompCtx() {
164         if (lognaming.isLoggable(BasicLevel.DEBUG)) {
165             lognaming.log(BasicLevel.DEBUG, "");
166         }
167         return bf.setComponentContext();
168     }
169
170     /**
171      * Restore old value
172      * @return previous Context
173      */

174     public void resetCompCtx(Context JavaDoc ctx) {
175         if (lognaming.isLoggable(BasicLevel.DEBUG)) {
176             lognaming.log(BasicLevel.DEBUG, "reset ctx:" + ctx);
177         }
178         bf.resetComponentContext(ctx);
179     }
180
181     /**
182      * Check security with the Meesage Context
183      */

184     public void checkSecurity(MessageContext msgContext) {
185
186         EJBInvocation ejb = new EJBInvocation();
187         String JavaDoc qname = null;
188         QName JavaDoc q = null;
189         try {
190             SOAPEnvelope JavaDoc env = msgContext.getMessage().getSOAPPart().getEnvelope();
191             SOAPBody JavaDoc body = env.getBody();
192             Iterator JavaDoc it = body.getChildElements();
193             SOAPElement JavaDoc operation = (SOAPElement JavaDoc) it.next();
194             qname = operation.getElementName().toString();
195
196             q = new QName JavaDoc(qname);
197             ejb.methodPermissionSignature = BeanNaming.getSignature(bf.getEJBName(), msgContext.getOperationByQName(q).getMethod());
198         } catch (AxisFault e ) {
199            // error during getting the operation from the message
200
// not possible to check the security
201
if (lognaming.isLoggable(BasicLevel.WARN))
202                 lognaming.log(BasicLevel.WARN, "can't retreive the operation from message...can not check the security");
203            return;
204         } catch (SOAPException JavaDoc e) {
205             // error during getting the operation from the message
206
// not possible to check the security
207
if (lognaming.isLoggable(BasicLevel.WARN))
208                  lognaming.log(BasicLevel.WARN, "can't retreive the operation from message...can not check the security");
209             return;
210         }
211
212         bf.checkSecurity(ejb);
213     }
214     /**
215      * @return A JServiceEndpoint that can be used by the JonasEJBProvider
216      */

217     public abstract JServiceEndpoint createServiceEndpointObject() throws RemoteException JavaDoc;
218
219
220 }
221
222
Popular Tags