1 55 56 package org.jboss.axis.client; 57 58 import org.jboss.axis.EngineConfiguration; 59 import org.jboss.axis.NotImplementedException; 60 import org.jboss.axis.configuration.EngineConfigurationFactoryFinder; 61 import org.jboss.axis.utils.ClassUtils; 62 63 import javax.naming.Context ; 64 import javax.naming.InitialContext ; 65 import javax.naming.Name ; 66 import javax.naming.NamingException ; 67 import javax.naming.RefAddr ; 68 import javax.naming.Reference ; 69 import javax.naming.spi.ObjectFactory ; 70 import javax.xml.namespace.QName ; 71 import javax.xml.rpc.ServiceException ; 72 import java.lang.reflect.Constructor ; 73 import java.net.URL ; 74 import java.util.Hashtable ; 75 import java.util.Map ; 76 import java.util.Properties ; 77 78 85 86 public class ServiceFactory extends javax.xml.rpc.ServiceFactory 87 implements ObjectFactory 88 { 89 public static final String SERVICE_CLASSNAME = "service classname"; 91 public static final String WSDL_LOCATION = "WSDL location"; 92 public static final String MAINTAIN_SESSION = "maintain session"; 93 public static final String SERVICE_NAMESPACE = "service namespace"; 94 public static final String SERVICE_LOCAL_PART = "service local part"; 95 96 private static EngineConfiguration defaultEngineConfig = null; 97 98 private static EngineConfiguration getDefaultEngineConfig() 99 { 100 if (defaultEngineConfig == null) 101 { 102 defaultEngineConfig = 103 EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig(); 104 } 105 return defaultEngineConfig; 106 } 107 108 117 public static Service getService(Map environment) 118 { 119 Service service = null; 120 InitialContext context = null; 121 122 EngineConfiguration configProvider = 123 (EngineConfiguration)environment.get(EngineConfiguration.PROPERTY_NAME); 124 125 if (configProvider == null) 126 configProvider = getDefaultEngineConfig(); 127 128 try 131 { 132 context = new InitialContext (); 133 } 134 catch (NamingException e) 135 { 136 } 137 138 if (context != null) 139 { 140 String name = (String )environment.get("jndiName"); 141 if (name == null) 142 { 143 name = "axisServiceName"; 144 } 145 146 try 149 { 150 service = (Service)context.lookup(name); 151 } 152 catch (NamingException e) 153 { 154 service = new Service(configProvider); 155 try 156 { 157 context.bind(name, service); 158 } 159 catch (NamingException e1) 160 { 161 } 163 } 164 } 165 else 166 { 167 service = new Service(configProvider); 168 } 169 170 return service; 171 } 172 173 public Object getObjectInstance(Object refObject, Name name, 174 Context nameCtx, Hashtable environment) throws Exception 175 { 176 Object instance = null; 177 if (refObject instanceof Reference ) 178 { 179 Reference ref = (Reference )refObject; 180 181 RefAddr addr = ref.get(SERVICE_CLASSNAME); 182 Object obj = null; 183 if (addr != null && (obj = addr.getContent()) instanceof String ) 186 { 187 instance = ClassUtils.forName((String )obj).newInstance(); 188 } 189 else 192 { 193 addr = ref.get(WSDL_LOCATION); 195 if (addr != null && (obj = addr.getContent()) instanceof String ) 196 { 197 URL wsdlLocation = new URL ((String )obj); 198 199 addr = ref.get(SERVICE_NAMESPACE); 201 if (addr != null 202 && (obj = addr.getContent()) instanceof String ) 203 { 204 String namespace = (String )obj; 205 addr = ref.get(SERVICE_LOCAL_PART); 206 if (addr != null 207 && (obj = addr.getContent()) instanceof String ) 208 { 209 String localPart = (String )obj; 210 QName serviceName = new QName (namespace, localPart); 211 212 Class [] formalArgs = new Class [] 214 {URL .class, QName .class}; 215 Object [] actualArgs = new Object [] 216 {wsdlLocation, serviceName}; 217 Constructor ctor = 218 Service.class.getDeclaredConstructor(formalArgs); 219 instance = ctor.newInstance(actualArgs); 220 } 221 } 222 } 223 } 224 addr = ref.get(MAINTAIN_SESSION); 227 if (addr != null && instance instanceof Service) 228 { 229 ((Service)instance).setMaintainSession(true); 230 } 231 } 232 return instance; 233 } 235 244 public javax.xml.rpc.Service createService(URL wsdlDocumentLocation, QName serviceName) throws ServiceException 245 { 246 return new Service(wsdlDocumentLocation, serviceName); 247 } 248 249 public javax.xml.rpc.Service loadService(Class aClass) throws ServiceException 250 { 251 throw new NotImplementedException(); 252 } 253 254 public javax.xml.rpc.Service loadService(URL url, Class aClass, Properties properties) throws ServiceException 255 { 256 throw new NotImplementedException(); 257 } 258 259 public javax.xml.rpc.Service loadService(URL url, QName qName, Properties properties) throws ServiceException 260 { 261 throw new NotImplementedException(); 262 } 263 264 275 public javax.xml.rpc.Service createService(QName serviceName) throws ServiceException 276 { 277 return new Service(serviceName); 278 } } 280 | Popular Tags |