📄 ejbprovider.java
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.providers.java;import java.lang.reflect.Method;import java.lang.reflect.InvocationTargetException;import java.util.Properties;import javax.naming.Context;import javax.naming.InitialContext;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.Handler;import org.apache.axis.MessageContext;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.handlers.soap.SOAPService;import org.apache.axis.utils.ClassUtils;import org.apache.axis.utils.Messages;import org.apache.commons.logging.Log;/** * A basic EJB Provider * * @author Carl Woolf (cwoolf@macromedia.com) * @author Tom Jordahl (tomj@macromedia.com) * @author C?dric Chabanois (cchabanois@ifrance.com) */public class EJBProvider extends RPCProvider{ protected static Log log = LogFactory.getLog(EJBProvider.class.getName()); // The enterprise category is for stuff that an enterprise product might // want to track, but in a simple environment (like the AXIS build) would // be nothing more than a nuisance. protected static Log entLog = LogFactory.getLog(Constants.ENTERPRISE_LOG_CATEGORY); public static final String OPTION_BEANNAME = "beanJndiName"; public static final String OPTION_HOMEINTERFACENAME = "homeInterfaceName"; public static final String OPTION_REMOTEINTERFACENAME = "remoteInterfaceName"; public static final String OPTION_LOCALHOMEINTERFACENAME = "localHomeInterfaceName"; public static final String OPTION_LOCALINTERFACENAME = "localInterfaceName"; public static final String jndiContextClass = "jndiContextClass"; public static final String jndiURL = "jndiURL"; public static final String jndiUsername = "jndiUser"; public static final String jndiPassword = "jndiPassword"; protected static final Class[] empty_class_array = new Class[0]; protected static final Object[] empty_object_array = new Object[0]; private static InitialContext cached_context = null; /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////// Default methods from JavaProvider ancestor, overridden /////// for ejbeans /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /** * Return a object which implements the service. * * @param msgContext the message context * @param clsName The JNDI name of the EJB home class * @return an object that implements the service */ protected Object makeNewServiceObject(MessageContext msgContext, String clsName) throws Exception { String remoteHomeName = getStrOption(OPTION_HOMEINTERFACENAME, msgContext.getService()); String localHomeName = getStrOption(OPTION_LOCALHOMEINTERFACENAME, msgContext.getService()); String homeName = (remoteHomeName != null ? remoteHomeName:localHomeName); if (homeName == null) { // cannot find both remote home and local home throw new AxisFault( Messages.getMessage("noOption00", OPTION_HOMEINTERFACENAME, msgContext.getTargetService())); } // Load the Home class name given in the config file Class homeClass = ClassUtils.forName(homeName, true, msgContext.getClassLoader()); // we create either the ejb using either the RemoteHome or LocalHome object if (remoteHomeName != null) return createRemoteEJB(msgContext, clsName, homeClass); else return createLocalEJB(msgContext, clsName, homeClass); } /** * Create an EJB using a remote home object * * @param msgContext the message context * @param beanJndiName The JNDI name of the EJB remote home class * @param homeClass the class of the home interface * @return an EJB */ private Object createRemoteEJB(MessageContext msgContext, String beanJndiName, Class homeClass) throws Exception { // Get the EJB Home object from JNDI Object ejbHome = getEJBHome(msgContext.getService(), msgContext, beanJndiName); Object ehome = javax.rmi.PortableRemoteObject.narrow(ejbHome, homeClass); // Invoke the create method of the ejbHome class without actually // touching any EJB classes (i.e. no cast to EJBHome) Method createMethod = homeClass.getMethod("create", empty_class_array); Object result = createMethod.invoke(ehome, empty_object_array); return result; } /** * Create an EJB using a local home object * * @param msgContext the message context * @param beanJndiName The JNDI name of the EJB local home class * @param homeClass the class of the home interface * @return an EJB */ private Object createLocalEJB(MessageContext msgContext, String beanJndiName, Class homeClass) throws Exception { // Get the EJB Home object from JNDI Object ejbHome = getEJBHome(msgContext.getService(), msgContext, beanJndiName); // the home object is a local home object Object ehome; if (homeClass.isInstance(ejbHome)) ehome = ejbHome; else throw new ClassCastException( Messages.getMessage("badEjbHomeType")); // Invoke the create method of the ejbHome class without actually // touching any EJB classes (i.e. no cast to EJBLocalHome) Method createMethod = homeClass.getMethod("create", empty_class_array); Object result = createMethod.invoke(ehome, empty_object_array); return result; } /** * Tells if the ejb that will be used to handle this service is a remote * one */ private boolean isRemoteEjb(SOAPService service) { return getStrOption(OPTION_HOMEINTERFACENAME,service) != null; } /** * Tells if the ejb that will be used to handle this service is a local * one */ private boolean isLocalEjb(SOAPService service) { return (!isRemoteEjb(service)) && (getStrOption(OPTION_LOCALHOMEINTERFACENAME,service) != null); } /** * Return the option in the configuration that contains the service class * name. In the EJB case, it is the JNDI name of the bean. */ protected String getServiceClassNameOptionName() { return OPTION_BEANNAME; } /** * Get a String option by looking first in the service options, * and then at the Handler's options. This allows defaults to be * specified at the provider level, and then overriden for particular * services. * * @param optionName the option to retrieve * @return String the value of the option or null if not found in * either scope */ protected String getStrOption(String optionName, Handler service) { String value = null; if (service != null) value = (String)service.getOption(optionName); if (value == null) value = (String)getOption(optionName); return value; } /** * Get the remote interface of an ejb from its home class. * This function can only be used for remote ejbs * * @param beanJndiName the jndi name of the ejb * @param service the soap service * @param msgContext the message context (can be null) */ private Class getRemoteInterfaceClassFromHome(String beanJndiName, SOAPService service, MessageContext msgContext) throws Exception { // Get the EJB Home object from JNDI Object ejbHome = getEJBHome(service, msgContext, beanJndiName); String homeName = getStrOption(OPTION_HOMEINTERFACENAME, service); if (homeName == null) throw new AxisFault( Messages.getMessage("noOption00", OPTION_HOMEINTERFACENAME, service.getName())); // Load the Home class name given in the config file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -