KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > axis > server > EJBHomeProvider


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: EJBHomeProvider.java,v 1.5.6.1 2005/03/02 14:19:51 tdiesler Exp $
9

10 package org.jboss.net.axis.server;
11
12 import org.jboss.axis.Handler;
13 import org.jboss.axis.MessageContext;
14 import org.jboss.axis.providers.java.RPCProvider;
15
16 import javax.ejb.EJBHome JavaDoc;
17 import javax.naming.InitialContext JavaDoc;
18
19 /**
20  * A JBoss-compatible Provider that exposes the methods of
21  * a beanīs home, such as a stateless session bean or an entity
22  * bean. It is working under the presumption that the right classloader
23  * has already been set by the invocation chain
24  * (@see org.jboss.net.axis.SetClassLoaderHandler).
25  * <br>
26  * <h3>Change History</h3>
27  * <ul>
28  * </ul>
29  * <br>
30  * <h3>To Do</h3>
31  * <ul>
32  * <li> jung, 22.03.02: Service-Reference serialisation. </li>
33  * </ul>
34  * @author <a HREF="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
35  * @created 22.03.2002
36  * @version $Revision: 1.5.6.1 $
37  */

38
39 public class EJBHomeProvider extends RPCProvider
40 {
41
42    private static final String JavaDoc beanNameOption = "beanJndiName";
43    private static final String JavaDoc homeInterfaceNameOption = "homeInterfaceName";
44
45    /** Creates new EJBProvider */
46    public EJBHomeProvider()
47    {
48    }
49
50    /**
51     * Return the object which implements the service. Makes the usual
52     * JNDI->lookup call wo the PortableRemoteDaDaDa for the sake of Corba.
53     * @param msgContext the message context
54     * @param clsName The JNDI name of the EJB home class
55     * @return an object that implements the service
56     */

57    protected Object JavaDoc getNewServiceObject(MessageContext msgContext, String JavaDoc clsName)
58            throws Exception JavaDoc
59    {
60       // Get the EJB Home object from JNDI
61
Object JavaDoc result = new InitialContext JavaDoc().lookup(clsName);
62
63       return result;
64    }
65
66    /**
67     * Return the option in the configuration that contains the service class
68     * name. In the EJB case, it is the JNDI name of the bean.
69     */

70    protected String JavaDoc getServiceClassNameOptionName()
71    {
72       return beanNameOption;
73    }
74
75    /**
76     * Get the class description for the EJB Remote Interface, which is what
77     * we are interested in exposing to the world (i.e. in WSDL).
78     *
79     * @param msgContext the message context
80     * @param beanJndiName the JNDI name of the EJB
81     * @return the class info of the EJB home interface
82     */

83    protected Class JavaDoc getServiceClass(MessageContext msgContext,
84                                    String JavaDoc beanJndiName) throws Exception JavaDoc
85    {
86       Handler serviceHandler = msgContext.getService();
87       Class JavaDoc interfaceClass = null;
88         
89       // First try to get the interface class from the configuation
90
String JavaDoc homeName =
91               (String JavaDoc)serviceHandler.getOption(homeInterfaceNameOption);
92       if (homeName != null)
93       {
94          interfaceClass = msgContext.getClassLoader().loadClass(homeName);
95       }
96       else
97       {
98          // we look into the metadata
99
EJBHome JavaDoc home = (EJBHome JavaDoc)getNewServiceObject(msgContext, beanJndiName);
100          interfaceClass = home.getEJBMetaData().getHomeInterfaceClass();
101       }
102             
103       // got it, return it
104
return interfaceClass;
105    }
106
107 }
Popular Tags