1 16 17 package org.springframework.remoting.jaxrpc; 18 19 import java.net.URL ; 20 import java.util.Properties ; 21 22 import javax.xml.namespace.QName ; 23 import javax.xml.rpc.Service ; 24 import javax.xml.rpc.ServiceException ; 25 import javax.xml.rpc.ServiceFactory ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import org.springframework.beans.BeanUtils; 31 32 47 public class LocalJaxRpcServiceFactory { 48 49 50 protected final Log logger = LogFactory.getLog(getClass()); 51 52 private ServiceFactory serviceFactory; 53 54 private Class serviceFactoryClass; 55 56 private URL wsdlDocumentUrl; 57 58 private String namespaceUri; 59 60 private String serviceName; 61 62 private Class jaxRpcServiceInterface; 63 64 private Properties jaxRpcServiceProperties; 65 66 private JaxRpcServicePostProcessor[] servicePostProcessors; 67 68 69 75 public void setServiceFactory(ServiceFactory serviceFactory) { 76 this.serviceFactory = serviceFactory; 77 } 78 79 82 public ServiceFactory getServiceFactory() { 83 return this.serviceFactory; 84 } 85 86 93 public void setServiceFactoryClass(Class serviceFactoryClass) { 94 if (serviceFactoryClass != null && !ServiceFactory .class.isAssignableFrom(serviceFactoryClass)) { 95 throw new IllegalArgumentException ("'serviceFactoryClass' must implement [javax.xml.rpc.ServiceFactory]"); 96 } 97 this.serviceFactoryClass = serviceFactoryClass; 98 } 99 100 103 public Class getServiceFactoryClass() { 104 return this.serviceFactoryClass; 105 } 106 107 110 public void setWsdlDocumentUrl(URL wsdlDocumentUrl) { 111 this.wsdlDocumentUrl = wsdlDocumentUrl; 112 } 113 114 117 public URL getWsdlDocumentUrl() { 118 return this.wsdlDocumentUrl; 119 } 120 121 125 public void setNamespaceUri(String namespaceUri) { 126 this.namespaceUri = namespaceUri; 127 } 128 129 132 public String getNamespaceUri() { 133 return this.namespaceUri; 134 } 135 136 143 public void setServiceName(String serviceName) { 144 this.serviceName = serviceName; 145 } 146 147 150 public String getServiceName() { 151 return this.serviceName; 152 } 153 154 166 public void setJaxRpcServiceInterface(Class jaxRpcServiceInterface) { 167 this.jaxRpcServiceInterface = jaxRpcServiceInterface; 168 } 169 170 173 public Class getJaxRpcServiceInterface() { 174 return this.jaxRpcServiceInterface; 175 } 176 177 183 public void setJaxRpcServiceProperties(Properties jaxRpcServiceProperties) { 184 this.jaxRpcServiceProperties = jaxRpcServiceProperties; 185 } 186 187 190 public Properties getJaxRpcServiceProperties() { 191 return this.jaxRpcServiceProperties; 192 } 193 194 205 public void setServicePostProcessors(JaxRpcServicePostProcessor[] servicePostProcessors) { 206 this.servicePostProcessors = servicePostProcessors; 207 } 208 209 213 public JaxRpcServicePostProcessor[] getServicePostProcessors() { 214 return this.servicePostProcessors; 215 } 216 217 218 224 public Service createJaxRpcService() throws ServiceException { 225 ServiceFactory serviceFactory = getServiceFactory(); 226 if (serviceFactory == null) { 227 serviceFactory = createServiceFactory(); 228 } 229 230 Service service = createService(serviceFactory); 232 233 postProcessJaxRpcService(service); 235 236 return service; 237 } 238 239 244 protected QName getQName(String name) { 245 return (getNamespaceUri() != null ? new QName (getNamespaceUri(), name) : new QName (name)); 246 } 247 248 255 protected ServiceFactory createServiceFactory() throws ServiceException { 256 if (getServiceFactoryClass() != null) { 257 return (ServiceFactory ) BeanUtils.instantiateClass(getServiceFactoryClass()); 258 } 259 else { 260 return ServiceFactory.newInstance(); 261 } 262 } 263 264 273 protected Service createService(ServiceFactory serviceFactory) throws ServiceException { 274 if (getServiceName() == null && getJaxRpcServiceInterface() == null) { 275 throw new IllegalArgumentException ("Either 'serviceName' or 'jaxRpcServiceInterface' is required"); 276 } 277 278 if (getJaxRpcServiceInterface() != null) { 279 if (getWsdlDocumentUrl() != null || getJaxRpcServiceProperties() != null) { 282 return serviceFactory.loadService( 283 getWsdlDocumentUrl(), getJaxRpcServiceInterface(), getJaxRpcServiceProperties()); 284 } 285 return serviceFactory.loadService(getJaxRpcServiceInterface()); 286 } 287 288 QName serviceQName = getQName(getServiceName()); 290 if (getJaxRpcServiceProperties() != null) { 291 return serviceFactory.loadService(getWsdlDocumentUrl(), serviceQName, getJaxRpcServiceProperties()); 293 } 294 if (getWsdlDocumentUrl() != null) { 295 return serviceFactory.createService(getWsdlDocumentUrl(), serviceQName); 296 } 297 return serviceFactory.createService(serviceQName); 298 } 299 300 312 protected void postProcessJaxRpcService(Service service) { 313 JaxRpcServicePostProcessor[] postProcessors = getServicePostProcessors(); 314 if (postProcessors != null) { 315 for (int i = 0; i < postProcessors.length; i++) { 316 postProcessors[i].postProcessJaxRpcService(service); 317 } 318 } 319 } 320 321 } 322 | Popular Tags |