KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > client > ServiceFactoryImpl


1 /**
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.client;
8
9 // $Id: ServiceFactoryImpl.java,v 1.7.4.2 2005/06/17 22:33:06 tdiesler Exp $
10

11 import org.jboss.logging.Logger;
12 import org.jboss.util.NotImplementedException;
13 import org.jboss.webservice.deployment.ServiceDescription;
14 import org.jboss.webservice.metadata.jaxrpcmapping.JavaWsdlMapping;
15 import org.jboss.webservice.metadata.jaxrpcmapping.JavaWsdlMappingFactory;
16 import org.jboss.webservice.metadata.wsdl.WSDL11DefinitionFactory;
17
18 import javax.wsdl.Definition;
19 import javax.xml.namespace.QName JavaDoc;
20 import javax.xml.rpc.Service JavaDoc;
21 import javax.xml.rpc.ServiceException JavaDoc;
22 import javax.xml.rpc.ServiceFactory JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 /**
27  * The javax.xml.rpc.ServiceFactory is a factory for the creation of instances of the type javax.xml.rpc.Service.
28  * <p/>
29  * This class follows the abstract static factory design pattern.
30  * This enables a J2SE based client to create a Service instance in a portable
31  * manner without using the constructor of the Service implementation class.
32  *
33  * @author Thomas.Diesler@jboss.org
34  * @version 1.1
35  */

36 public class ServiceFactoryImpl extends ServiceFactory JavaDoc
37 {
38    // provide logging
39
private final Logger log = Logger.getLogger(ServiceFactoryImpl.class);
40
41    /**
42     * Create an instance of the generated service implementation class for a given service interface, if available.
43     *
44     * @param serviceInterface Service interface
45     * @return A Service
46     * @throws ServiceException If there is any error while creating the specified service, including the case where a
47     * generated service implementation class cannot be located
48     */

49    public Service JavaDoc loadService(Class JavaDoc serviceInterface) throws ServiceException JavaDoc
50    {
51       throw new NotImplementedException();
52    }
53
54    /**
55     * Create an instance of the generated service implementation class for a given service interface, if available.
56     * An implementation may use the provided wsdlDocumentLocation and properties to help locate the generated implementation class.
57     * If no such class is present, a ServiceException will be thrown.
58     *
59     * @param wsdlDocumentLocation URL for the WSDL document location for the service or null
60     * @param serviceInterface Service interface
61     * @param props A set of implementation-specific properties to help locate the generated service implementation class
62     * @return A Service
63     * @throws ServiceException If there is any error while creating the specified service, including the case where a
64     * generated service implementation class cannot be located
65     */

66    public Service JavaDoc loadService(URL JavaDoc wsdlDocumentLocation, Class JavaDoc serviceInterface, Properties JavaDoc props) throws ServiceException JavaDoc
67    {
68       throw new NotImplementedException();
69    }
70
71    /**
72     * Create an instance of the generated service implementation class for a given service, if available.
73     * The service is uniquely identified by the wsdlDocumentLocation and serviceName arguments.
74     * An implementation may use the provided properties to help locate the generated implementation class.
75     * If no such class is present, a ServiceException will be thrown.
76     *
77     * @param wsdlDocumentLocation URL for the WSDL document location for the service or null
78     * @param serviceName Qualified name for the service
79     * @param props A set of implementation-specific properties to help locate the generated service implementation class
80     * @return A Service
81     * @throws ServiceException If there is any error while creating the specified service, including the case where a generated service implementation class cannot be located
82     */

83    public Service JavaDoc loadService(URL JavaDoc wsdlDocumentLocation, QName JavaDoc serviceName, Properties JavaDoc props) throws ServiceException JavaDoc
84    {
85       throw new NotImplementedException();
86    }
87
88    /**
89     * Create a <code>Service</code> instance.
90     *
91     * @param serviceName QName for the service
92     * @return Service.
93     * @throws ServiceException If any error in creation of the specified service
94     */

95    public Service JavaDoc createService(QName JavaDoc serviceName) throws ServiceException JavaDoc
96    {
97       return new ServiceImpl(serviceName);
98    }
99
100    /**
101     * Create a <code>Service</code> instance.
102     *
103     * @param wsdlDocumentLocation URL for the WSDL document location
104     * @param serviceName QName for the service.
105     * @return Service.
106     * @throws ServiceException If any error in creation of the
107     * specified service
108     */

109    public Service JavaDoc createService(URL JavaDoc wsdlDocumentLocation, QName JavaDoc serviceName) throws ServiceException JavaDoc
110    {
111       ServiceImpl service = new ServiceImpl(wsdlDocumentLocation, serviceName);
112
113       try
114       {
115          WSDL11DefinitionFactory factory = WSDL11DefinitionFactory.newInstance();
116          Definition wsdlDefinition = factory.parse(wsdlDocumentLocation);
117
118          // In this case we have no jaxrpc-mapping.xml
119
ServiceDescription serviceDesc = new ServiceDescription(wsdlDefinition, null, null, null);
120          service.initService(serviceDesc, null);
121       }
122       catch (Exception JavaDoc e)
123       {
124          throw new ServiceException JavaDoc(e);
125       }
126
127       return service;
128    }
129
130    /**
131     * Create a <code>Service</code> instance.
132     * <p/>
133     * Note, this method is not in the {@link ServiceFactory} interface, it provides the service
134     * with additional ws4ee wsdl/java mapping information
135     *
136     * @param wsdlLocation URL for the WSDL document location
137     * @param mappingLocation An optional URL for the jaxrpc-mapping.xml location
138     * @param ws4eeMetaData An optional URL for the jboss propriatary deployment descriptor, see wiki for details.
139     * @param serviceName QName for the service.
140     * @param portName An optional port name
141     * @return Service.
142     * @throws ServiceException If any error in creation of the specified service
143     */

144    public Service JavaDoc createService(URL JavaDoc wsdlLocation, URL JavaDoc mappingLocation, URL JavaDoc ws4eeMetaData, QName JavaDoc serviceName, String JavaDoc portName) throws ServiceException JavaDoc
145    {
146       ServiceImpl service = new ServiceImpl(wsdlLocation, serviceName);
147
148       try
149       {
150          WSDL11DefinitionFactory wsdlFactory = WSDL11DefinitionFactory.newInstance();
151          Definition wsdlDefinition = wsdlFactory.parse(wsdlLocation);
152
153          JavaWsdlMapping javaWsdlMapping = null;
154          if (mappingLocation != null)
155          {
156             JavaWsdlMappingFactory mappingFactory = JavaWsdlMappingFactory.newInstance();
157             javaWsdlMapping = mappingFactory.parse(mappingLocation);
158          }
159
160          ServiceDescription serviceDesc = new ServiceDescription(wsdlDefinition, javaWsdlMapping, ws4eeMetaData, portName);
161          service.initService(serviceDesc, portName);
162       }
163       catch (Exception JavaDoc e)
164       {
165          log.error(e.getMessage(), e);
166          throw new ServiceException JavaDoc(e);
167       }
168
169       return service;
170    }
171 }
172
Popular Tags