KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > soap > providers > EntityEJBProvider


1 package org.apache.soap.providers;
2
3 import java.io.* ;
4 import java.util.* ;
5 import java.rmi.Remote JavaDoc;
6 import javax.servlet.* ;
7 import javax.servlet.http.* ;
8 import org.apache.soap.* ;
9 import org.apache.soap.rpc.* ;
10 import org.apache.soap.server.* ;
11 import org.apache.soap.util.* ;
12 import org.apache.soap.encoding.soapenc.Base64;
13
14 import java.lang.reflect.*;
15 import javax.rmi.*;
16 import javax.ejb.*;
17 import javax.naming.*;
18 import javax.naming.Context JavaDoc.*;
19
20 public class EntityEJBProvider extends StatefulEJBProvider {
21   public EntityEJBProvider() {
22     super();
23   }
24
25   /**
26    * locate method comment.
27    */

28   public void locate(DeploymentDescriptor depDesc,
29                      Envelope env,
30                      Call origCall,
31                      String JavaDoc methodName,
32                      String JavaDoc targetObjectURI,
33                      SOAPContext reqContext) throws SOAPException {
34
35     HttpServlet servletRef = (HttpServlet) reqContext.getProperty( Constants.BAG_HTTPSERVLET );
36     HttpSession sessObj = (HttpSession) reqContext.getProperty( Constants.BAG_HTTPSESSION );
37
38     setDd(depDesc);
39     setCall(origCall);
40     setTargetObjectURI(origCall.getTargetObjectURI()) ;
41     setServlet(servletRef);
42     setSession(sessObj);
43     setMethodName(origCall.getMethodName());
44     setMethodParameters(origCall.getParams());
45
46     // Check if there is a key appended to the URI;
47
String JavaDoc fullURI = origCall.getFullTargetObjectURI();
48     ejbKey = StatefulEJBProvider.getUniqueId(fullURI);
49
50     if (ejbKey != null) {
51       setRemoteObjRef(deSerialize(ejbKey));
52       // We have obtained the necessary object.
53
return;
54     }
55
56     Hashtable props = depDesc.getProps();
57
58     String JavaDoc ContxtProviderURL = (String JavaDoc) props.get("ContextProviderURL");
59     String JavaDoc ContxtFactoryName = (String JavaDoc) props.get("FullContextFactoryName");
60
61     if ((ContxtProviderURL != null) || (ContxtFactoryName != null))
62       initialize(ContxtProviderURL, ContxtFactoryName);
63     else
64       initialize(CNTXT_PROVIDER_URL, CNTXT_FACTORY_NAME);
65
66     String JavaDoc homeInterfaceName = (String JavaDoc) props.get("FullHomeInterfaceName");
67     if (homeInterfaceName == null)
68       throw new SOAPException(Constants.FAULT_CODE_SERVER,
69                    "Error in Deployment Descriptor Property Settings");
70
71     // From the Deployment Descriptor get the JNDI lookup name that is inside
72
// the "java" element...
73
String JavaDoc jndiName = (String JavaDoc) props.get("JNDIName");
74     if ( jndiName == null ) jndiName = depDesc.getProviderClass();
75
76     if ((jndiName != null) && (getContxt() != null)) {
77       try {
78         // Use service name to locate EJB home object via the contxt
79
EJBHome home = (EJBHome) PortableRemoteObject.narrow(
80                                    getContxt().lookup(jndiName),
81                                    Class.forName(homeInterfaceName));
82
83         // Must check to see if the create method has any parameters associated
84
// with it.
85
// There are 2 scenarios:
86
// 1) if the method name in the call is create or find, then it will
87
// have parameters.
88
// 2) if the method name in the call is not create or find, and
89
// because no key is associated with this call, then we assume
90
// that we can call create without any additional parameters,
91
// and prepare to invoke the given method.
92

93         if ( getMethodName().equals("create") ||
94              getMethodName().startsWith("find") ) {
95           // The method is create, so let the invoke method deal with it;
96
// just give it the home interface.
97
setRemoteObjRef(home);
98           isCreate = true;
99           return;
100         } else {
101           // Method name is something other than create or find - so, the
102
// invoke command has another directive to process; we just perform
103
// a basic 'create' then.
104
Method createMethod = home.getClass().getMethod("create",
105                                                           new Class JavaDoc[0]);
106           setRemoteObjRef((EJBObject) createMethod.invoke((Object JavaDoc) home,
107                                                           new Object JavaDoc[0]));
108         }
109       } catch (Exception JavaDoc e) {
110         throw new SOAPException(Constants.FAULT_CODE_SERVER,
111                                 "Error in connecting to EJB", e);
112       }
113     }
114   }
115 }
116
Popular Tags