KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > spi > ServiceDelegateImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.webservice.spi;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import javax.xml.namespace.QName JavaDoc;
31 import javax.xml.ws.Dispatch;
32 import javax.xml.ws.Service;
33 import javax.xml.ws.handler.HandlerResolver;
34 import javax.xml.bind.JAXBContext;
35
36 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
37 import com.sun.enterprise.webservice.ServiceRefDescUtil;
38 import com.sun.enterprise.webservice.WsUtil;
39
40 public class ServiceDelegateImpl extends javax.xml.ws.spi.ServiceDelegate {
41
42    private javax.xml.ws.spi.ServiceDelegate delegate;
43    private ArrayList JavaDoc<InvInterfaceCreationListener> listeners = new ArrayList JavaDoc();
44    private ServiceReferenceDescriptor serviceRef;
45    
46    public ServiceDelegateImpl(javax.xml.ws.spi.ServiceDelegate delegate) {
47        this.delegate = delegate;
48        serviceRef = ServiceRefDescUtil.getReference();
49    }
50    
51   /** The getPort method returns a stub. A service client
52    * uses this stub to invoke operations on the target
53    * service endpoint. The <code>serviceEndpointInterface</code>
54    * specifies the service endpoint interface that is supported by
55    * the created dynamic proxy or stub instance.
56    *
57    * @param portName Qualified name of the service endpoint in
58    * the WSDL service description
59    * @param serviceEndpointInterface Service endpoint interface
60    * supported by the dynamic proxy or stub
61    * instance
62    * @return Object Proxy instance that
63    * supports the specified service endpoint
64    * interface
65    * @throws WebServiceException This exception is thrown in the
66    * following cases:
67    * <UL>
68    * <LI>If there is an error in creation of
69    * the proxy
70    * <LI>If there is any missing WSDL metadata
71    * as required by this method
72    * <LI>Optionally, if an illegal
73    * <code>serviceEndpointInterface</code>
74    * or <code>portName</code> is specified
75    * </UL>
76    * @see java.lang.reflect.Proxy
77    * @see java.lang.reflect.InvocationHandler
78   **/

79   @Override JavaDoc
80   public <T> T getPort(QName JavaDoc portName,
81                    Class JavaDoc<T> serviceEndpointInterface) {
82       T port = delegate.getPort(portName, serviceEndpointInterface);
83       portCreated(port, serviceEndpointInterface);
84       return port;
85   }
86
87   /** The getPort method returns a stub. The parameter
88    * <code>serviceEndpointInterface</code> specifies the service
89    * endpoint interface that is supported by the returned proxy.
90    * In the implementation of this method, the JAX-WS
91    * runtime system takes the responsibility of selecting a protocol
92    * binding (and a port) and configuring the proxy accordingly.
93    * The returned proxy should not be reconfigured by the client.
94    *
95    * @param serviceEndpointInterface Service endpoint interface
96    * @return Object instance that supports the
97    * specified service endpoint interface
98    * @throws WebServiceException
99    * <UL>
100    * <LI>If there is an error during creation
101    * of the proxy
102    * <LI>If there is any missing WSDL metadata
103    * as required by this method
104    * <LI>Optionally, if an illegal
105    * <code>serviceEndpointInterface</code>
106    * is specified
107    * </UL>
108   **/

109   public <T> T getPort(Class JavaDoc<T> serviceEndpointInterface) {
110     T port = delegate.getPort(serviceEndpointInterface);
111     portCreated(port, serviceEndpointInterface);
112     return port;
113   }
114
115   /** Creates a new port for the service. Ports created in this way contain
116    * no WSDL port type information and can only be used for creating
117    * <code>Dispatch</code>instances.
118    *
119    * @param portName Qualified name for the target service endpoint
120    * @param bindingId A URI identifier of a binding.
121    * @param endpointAddress Address of the target service endpoint as a URI
122    * @throws WebServiceException If any error in the creation of
123    * the port
124    *
125    * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING
126    * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING
127    * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_MTOM_BINDING
128    * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_MTOM_BINDING
129    * @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING
130    **/

131   public void addPort(QName JavaDoc portName, String JavaDoc bindingId,
132       String JavaDoc endpointAddress) {
133       delegate.addPort(portName, bindingId, endpointAddress);
134   }
135
136   /** Creates a <code>Dispatch</code> instance for use with objects of
137    * the users choosing.
138    *
139    * @param portName Qualified name for the target service endpoint
140    * @param type The class of object used to messages or message
141    * payloads. Implementations are required to support
142    * javax.xml.transform.Source and javax.xml.soap.SOAPMessage.
143    * @param mode Controls whether the created dispatch instance is message
144    * or payload oriented, i.e. whether the user will work with complete
145    * protocol messages or message payloads. E.g. when using the SOAP
146    * protocol, this parameter controls whether the user will work with
147    * SOAP messages or the contents of a SOAP body. Mode must be MESSAGE
148    * when type is SOAPMessage.
149    *
150    * @return Dispatch instance
151    * @throws WebServiceException If any error in the creation of
152    * the <code>Dispatch</code> object
153    * @see javax.xml.transform.Source
154    * @see javax.xml.soap.SOAPMessage
155    **/

156   public <T> Dispatch<T> createDispatch(QName JavaDoc portName, Class JavaDoc<T> type, Service.Mode mode) {
157       Dispatch<T> dispatch = delegate.createDispatch(portName, type, mode);
158       dispatchCreated(dispatch, type);
159       return dispatch;
160   }
161
162   /** Creates a <code>Dispatch</code> instance for use with JAXB
163    * generated objects.
164    *
165    * @param portName Qualified name for the target service endpoint
166    * @param context The JAXB context used to marshall and unmarshall
167    * messages or message payloads.
168    * @param mode Controls whether the created dispatch instance is message
169    * or payload oriented, i.e. whether the user will work with complete
170    * protocol messages or message payloads. E.g. when using the SOAP
171    * protocol, this parameter controls whether the user will work with
172    * SOAP messages or the contents of a SOAP body.
173    *
174    * @return Dispatch instance
175    * @throws ServiceException If any error in the creation of
176    * the <code>Dispatch</code> object
177    *
178    * @see javax.xml.bind.JAXBContext
179    **/

180   public Dispatch<Object JavaDoc> createDispatch(QName JavaDoc portName,
181               JAXBContext context, Service.Mode mode) {
182       
183       Dispatch<Object JavaDoc> dispatch = delegate.createDispatch(portName, context, mode);
184       dispatchCreated(dispatch, Object JavaDoc.class);
185       return dispatch;
186       
187   }
188
189
190   /** Gets the name of this service.
191    * @return Qualified name of this service
192   **/

193   public QName JavaDoc getServiceName() {
194       return delegate.getServiceName();
195   }
196
197   /** Returns an <code>Iterator</code> for the list of
198    * <code>QName</code>s of service endpoints grouped by this
199    * service
200    *
201    * @return Returns <code>java.util.Iterator</code> with elements
202    * of type <code>javax.xml.namespace.QName</code>
203    * @throws WebServiceException If this Service class does not
204    * have access to the required WSDL metadata
205   **/

206   public Iterator JavaDoc<javax.xml.namespace.QName JavaDoc> getPorts() {
207       return delegate.getPorts();
208   }
209
210   /** Gets the location of the WSDL document for this Service.
211    *
212    * @return URL for the location of the WSDL document for
213    * this service
214   **/

215   public java.net.URL JavaDoc getWSDLDocumentLocation() {
216       return delegate.getWSDLDocumentLocation();
217   }
218
219   /**
220    * Returns the configured handler resolver.
221    *
222    * @return HandlerResolver The <code>HandlerResolver</code> being
223    * used by this <code>Service</code> instance, or <code>null</code>
224    * if there isn't one.
225   **/

226   public HandlerResolver getHandlerResolver() {
227       return delegate.getHandlerResolver();
228   }
229
230   /**
231    * Sets the <code>HandlerResolver</code> for this <code>Service</code>
232    * instance.
233    * <p>
234    * The handler resolver, if present, will be called once for each
235    * proxy or dispatch instance that is created, and the handler chain
236    * returned by the resolver will be set on the instance.
237    *
238    * @param handlerResolver The <code>HandlerResolver</code> to use
239    * for all subsequently created proxy/dispatch objects.
240    *
241    * @see javax.xml.ws.handler.HandlerResolver
242   **/

243   public void setHandlerResolver(HandlerResolver handlerResolver) {
244       delegate.setHandlerResolver(handlerResolver);
245   }
246
247   /**
248    * Returns the executor for this <code>Service</code>instance.
249    *
250    * The executor is used for all asynchronous invocations that
251    * require callbacks.
252    *
253    * @return The <code>java.util.concurrent.Executor</code> to be
254    * used to invoke a callback.
255    *
256    * @see java.util.concurrent.Executor
257    **/

258    public java.util.concurrent.Executor JavaDoc getExecutor() {
259        return delegate.getExecutor();
260    }
261   
262   /**
263    * Sets the executor for this <code>Service</code> instance.
264    *
265    * The executor is used for all asynchronous invocations that
266    * require callbacks.
267    *
268    * @param executor The <code>java.util.concurrent.Executor</code>
269    * to be used to invoke a callback.
270    *
271    * @throws SecurityException If the instance does not support
272    * setting an executor for security reasons (e.g. the
273    * necessary permissions are missing).
274    *
275    * @see java.util.concurrent.Executor
276    **/

277    public void setExecutor(java.util.concurrent.Executor JavaDoc executor) {
278        delegate.setExecutor(executor);
279    }
280        
281   
282  
283   /**
284    * notifies our listener of a port creation
285    */

286   private <T> void portCreated(T port, Class JavaDoc<T> serviceEndpointInterface) {
287       for (InvInterfaceCreationListener listener : listeners) {
288           try {
289             listener.portCreated(port, serviceEndpointInterface);
290           } catch(Throwable JavaDoc t) {
291                  WsUtil.getDefaultLogger().severe("Exception "
292                          + t.getMessage() + " in portCreationListener : " + listener);
293                  WsUtil.getDefaultLogger().log(Level.FINE, t.getMessage(), t);
294           }
295       }
296   }
297   
298   /**
299    * Add a new listener for port creation
300    * @param the listener
301    */

302   public void addListener(InvInterfaceCreationListener listener) {
303     listeners.add(listener);
304   }
305   
306   /**
307    * notifies our listeners of a Dispatch creation
308    */

309   private <T> void dispatchCreated(Dispatch<T> dispatch, Class JavaDoc<T> serviceEndpointInterface) {
310       for (InvInterfaceCreationListener listener : listeners) {
311           try {
312             listener.dispatchCreated(dispatch, serviceEndpointInterface);
313           } catch(Throwable JavaDoc t) {
314                  WsUtil.getDefaultLogger().severe("Exception "
315                          + t.getMessage() + " in dispatchCreationListener : " + listener);
316                  WsUtil.getDefaultLogger().log(Level.FINE, t.getMessage(), t);
317           }
318       }
319   }
320   
321   /**
322    * @return the service reference descriptor used to describe this
323    * Service instance
324    */

325   public ServiceReferenceDescriptor getServiceReference() {
326       return serviceRef;
327   }
328             
329 }
330         
Popular Tags