1 16 17 package org.apache.axis.providers.java; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.Handler; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.components.logger.LogFactory; 23 import org.apache.axis.utils.ClassUtils; 24 import org.apache.commons.logging.Log; 25 import org.omg.CORBA.ORB ; 26 import org.omg.CosNaming.NameComponent ; 27 import org.omg.CosNaming.NamingContext ; 28 import org.omg.CosNaming.NamingContextHelper ; 29 30 import java.lang.reflect.Method ; 31 import java.util.Properties ; 32 33 38 public class CORBAProvider extends RPCProvider 39 { 40 protected static Log log = 41 LogFactory.getLog(CORBAProvider.class.getName()); 42 43 private static final String DEFAULT_ORB_INITIAL_HOST = "localhost"; 44 private static final String DEFAULT_ORB_INITIAL_PORT = "900"; 45 46 protected static Log entLog = 50 LogFactory.getLog(Constants.ENTERPRISE_LOG_CATEGORY); 51 52 public static final String OPTION_ORB_INITIAL_HOST = "ORBInitialHost"; 53 public static final String OPTION_ORB_INITIAL_PORT = "ORBInitialPort"; 54 public static final String OPTION_NAME_ID = "NameID"; 55 public static final String OPTION_NAME_KIND = "NameKind"; 56 public static final String OPTION_INTERFACE_CLASSNAME = "InterfaceClassName"; 57 public static final String OPTION_HELPER_CLASSNAME = "HelperClassName"; 58 59 66 protected Object makeNewServiceObject(MessageContext msgContext, 67 String clsName) 68 throws Exception 69 { 70 String orbInitialHost = getStrOption(OPTION_ORB_INITIAL_HOST,msgContext.getService()); 72 if (orbInitialHost == null) 73 orbInitialHost = DEFAULT_ORB_INITIAL_HOST; 74 String orbInitialPort = getStrOption(OPTION_ORB_INITIAL_PORT,msgContext.getService()); 75 if (orbInitialPort == null) 76 orbInitialPort = DEFAULT_ORB_INITIAL_PORT; 77 String nameId = getStrOption(OPTION_NAME_ID,msgContext.getService()); 78 String nameKind = getStrOption(OPTION_NAME_KIND,msgContext.getService()); 79 String helperClassName = getStrOption(OPTION_HELPER_CLASSNAME,msgContext.getService()); 80 81 Properties orbProps = new Properties (); 83 orbProps.put("org.omg.CORBA.ORBInitialHost", orbInitialHost); 84 orbProps.put("org.omg.CORBA.ORBInitialPort", orbInitialPort); 85 ORB orb = ORB.init(new String [0], orbProps); 86 87 NamingContext root = NamingContextHelper.narrow(orb.resolve_initial_references("NameService")); 89 NameComponent nc = new NameComponent (nameId, nameKind); 90 NameComponent [] ncs = {nc}; 91 org.omg.CORBA.Object corbaObject = root.resolve(ncs); 92 93 Class helperClass = ClassUtils.forName(helperClassName); 94 Method narrowMethod = helperClass.getMethod("narrow", CORBA_OBJECT_CLASS); 96 Object targetObject = narrowMethod.invoke(null, new Object [] {corbaObject}); 97 98 return targetObject; 99 } 100 101 private static final Class [] CORBA_OBJECT_CLASS = new Class [] {org.omg.CORBA.Object .class}; 102 103 107 protected String getServiceClassNameOptionName() 108 { 109 return OPTION_INTERFACE_CLASSNAME; 110 } 111 112 122 protected String getStrOption(String optionName, Handler service) 123 { 124 String value = null; 125 if (service != null) 126 value = (String )service.getOption(optionName); 127 if (value == null) 128 value = (String )getOption(optionName); 129 return value; 130 } 131 } 132 | Popular Tags |