1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.remoting.jaxrpc;
  17. import java.net.URL;
  18. import javax.xml.namespace.QName;
  19. import javax.xml.rpc.Service;
  20. import javax.xml.rpc.ServiceException;
  21. import javax.xml.rpc.ServiceFactory;
  22. import org.apache.commons.logging.Log;
  23. import org.apache.commons.logging.LogFactory;
  24. import org.springframework.beans.BeanUtils;
  25. /**
  26. * Factory for locally defined JAX-RPC Service references.
  27. * Uses a JAX-RPC ServiceFactory underneath.
  28. * @author Juergen Hoeller
  29. * @since 15.12.2003
  30. * @see javax.xml.rpc.ServiceFactory
  31. * @see javax.xml.rpc.Service
  32. */
  33. public class LocalJaxRpcServiceFactory {
  34. protected final Log logger = LogFactory.getLog(getClass());
  35. private Class serviceFactoryClass;
  36. private URL wsdlDocumentUrl;
  37. private String namespaceUri;
  38. private String serviceName;
  39. /**
  40. * Set the ServiceFactory class to use, for example
  41. * "org.apache.axis.client.ServiceFactory".
  42. * <p>Does not need to be set if the JAX-RPC implementation has registered
  43. * itself with the JAX-RPC system property "SERVICEFACTORY_PROPERTY".
  44. * @see javax.xml.rpc.ServiceFactory
  45. */
  46. public void setServiceFactoryClass(Class serviceFactoryClass) {
  47. if (serviceFactoryClass != null && !ServiceFactory.class.isAssignableFrom(serviceFactoryClass)) {
  48. throw new IllegalArgumentException("serviceFactoryClass must implement javax.xml.rpc.ServiceFactory");
  49. }
  50. this.serviceFactoryClass = serviceFactoryClass;
  51. }
  52. /**
  53. * Return the ServiceFactory class to use, or null if default.
  54. */
  55. public Class getServiceFactoryClass() {
  56. return serviceFactoryClass;
  57. }
  58. /**
  59. * Set the URL of the WSDL document that describes the service.
  60. */
  61. public void setWsdlDocumentUrl(URL wsdlDocumentUrl) {
  62. this.wsdlDocumentUrl = wsdlDocumentUrl;
  63. }
  64. /**
  65. * Return the URL of the WSDL document that describes the service.
  66. */
  67. public URL getWsdlDocumentUrl() {
  68. return wsdlDocumentUrl;
  69. }
  70. /**
  71. * Set the namespace URI of the service.
  72. * Corresponds to the WSDL "targetNamespace".
  73. */
  74. public void setNamespaceUri(String namespaceUri) {
  75. this.namespaceUri = namespaceUri;
  76. }
  77. /**
  78. * Return the namespace URI of the service.
  79. */
  80. public String getNamespaceUri() {
  81. return namespaceUri;
  82. }
  83. /**
  84. * Set the name of the service.
  85. * Corresponds to the "wsdl:service" name.
  86. */
  87. public void setServiceName(String serviceName) {
  88. this.serviceName = serviceName;
  89. }
  90. /**
  91. * Return the name of the service.
  92. */
  93. public String getServiceName() {
  94. return serviceName;
  95. }
  96. /**
  97. * Return a QName for the given name,* relative to the namespace URI
  98. * of this factory, if given.
  99. * @see #setNamespaceUri
  100. */
  101. public QName getQName(String name) {
  102. return (this.namespaceUri != null) ? new QName(this.namespaceUri, name) : new QName(this.serviceName);
  103. }
  104. /**
  105. * Create a JAX-RPC ServiceFactory, either of the specified class
  106. * or the default.
  107. * @see #setServiceFactoryClass
  108. */
  109. public ServiceFactory createServiceFactory() throws ServiceException {
  110. if (this.serviceFactoryClass != null) {
  111. return (ServiceFactory) BeanUtils.instantiateClass(this.serviceFactoryClass);
  112. }
  113. else {
  114. return ServiceFactory.newInstance();
  115. }
  116. }
  117. /**
  118. * Create a JAX-RPC Service according to the parameters of this factory.
  119. * @see #setServiceName
  120. * @see #setWsdlDocumentUrl
  121. */
  122. public Service createJaxRpcService() throws ServiceException {
  123. if (this.serviceName == null) {
  124. throw new IllegalArgumentException("serviceName is required");
  125. }
  126. ServiceFactory serviceFactory = createServiceFactory();
  127. QName serviceQName = getQName(this.serviceName);
  128. return (this.wsdlDocumentUrl != null) ?
  129. serviceFactory.createService(this.wsdlDocumentUrl, serviceQName) :
  130. serviceFactory.createService(serviceQName);
  131. }
  132. }