001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.remoting.jaxws;
018:
019: import java.net.URL;
020: import java.util.concurrent.Executor;
021:
022: import javax.xml.namespace.QName;
023: import javax.xml.ws.Service;
024: import javax.xml.ws.handler.HandlerResolver;
025:
026: import org.springframework.core.task.TaskExecutor;
027: import org.springframework.core.task.support.ConcurrentExecutorAdapter;
028:
029: /**
030: * Factory for locally defined JAX-WS {@link javax.xml.ws.Service} references.
031: * Uses the JAX-WS {@link javax.xml.ws.Service#create} factory API underneath.
032: *
033: * <p>Serves as base class for {@link LocalJaxWsServiceFactoryBean} as well as
034: * {@link JaxWsPortClientInterceptor} and {@link JaxWsPortProxyFactoryBean}.
035: *
036: * @author Juergen Hoeller
037: * @since 2.5
038: * @see javax.xml.ws.Service
039: * @see LocalJaxWsServiceFactoryBean
040: * @see JaxWsPortClientInterceptor
041: * @see JaxWsPortProxyFactoryBean
042: */
043: public class LocalJaxWsServiceFactory {
044:
045: private URL wsdlDocumentUrl;
046:
047: private String namespaceUri;
048:
049: private String serviceName;
050:
051: private Executor executor;
052:
053: private HandlerResolver handlerResolver;
054:
055: /**
056: * Set the URL of the WSDL document that describes the service.
057: */
058: public void setWsdlDocumentUrl(URL wsdlDocumentUrl) {
059: this .wsdlDocumentUrl = wsdlDocumentUrl;
060: }
061:
062: /**
063: * Return the URL of the WSDL document that describes the service.
064: */
065: public URL getWsdlDocumentUrl() {
066: return this .wsdlDocumentUrl;
067: }
068:
069: /**
070: * Set the namespace URI of the service.
071: * Corresponds to the WSDL "targetNamespace".
072: */
073: public void setNamespaceUri(String namespaceUri) {
074: this .namespaceUri = (namespaceUri != null ? namespaceUri.trim()
075: : null);
076: }
077:
078: /**
079: * Return the namespace URI of the service.
080: */
081: public String getNamespaceUri() {
082: return this .namespaceUri;
083: }
084:
085: /**
086: * Set the name of the service to look up.
087: * Corresponds to the "wsdl:service" name.
088: */
089: public void setServiceName(String serviceName) {
090: this .serviceName = serviceName;
091: }
092:
093: /**
094: * Return the name of the service.
095: */
096: public String getServiceName() {
097: return this .serviceName;
098: }
099:
100: /**
101: * Set the JDK concurrent executor to use for asynchronous executions
102: * that require callbacks.
103: * @see javax.xml.ws.Service#setExecutor
104: */
105: public void setExecutor(Executor executor) {
106: this .executor = executor;
107: }
108:
109: /**
110: * Set the Spring TaskExecutor to use for asynchronous executions
111: * that require callbacks.
112: * @see javax.xml.ws.Service#setExecutor
113: */
114: public void setTaskExecutor(TaskExecutor executor) {
115: this .executor = new ConcurrentExecutorAdapter(executor);
116: }
117:
118: /**
119: * Set the JAX-WS HandlerResolver to use for all proxies and dispatchers
120: * created through this factory.
121: * @see javax.xml.ws.Service#setHandlerResolver
122: */
123: public void setHandlerResolver(HandlerResolver handlerResolver) {
124: this .handlerResolver = handlerResolver;
125: }
126:
127: /**
128: * Create a JAX-WS Service according to the parameters of this factory.
129: * @see #setServiceName
130: * @see #setWsdlDocumentUrl
131: */
132: public Service createJaxWsService() {
133: Service service = (this .wsdlDocumentUrl != null ? Service
134: .create(this .wsdlDocumentUrl,
135: getQName(this .serviceName)) : Service
136: .create(getQName(this .serviceName)));
137:
138: if (this .executor != null) {
139: service.setExecutor(this .executor);
140: }
141: if (this .handlerResolver != null) {
142: service.setHandlerResolver(this .handlerResolver);
143: }
144: return service;
145: }
146:
147: /**
148: * Return a QName for the given name, relative to the namespace URI
149: * of this factory, if given.
150: * @see #setNamespaceUri
151: */
152: protected QName getQName(String name) {
153: return (getNamespaceUri() != null ? new QName(
154: getNamespaceUri(), name) : new QName(name));
155: }
156:
157: }
|