325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.api;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
325N/Aimport com.sun.xml.internal.ws.api.server.Container;
325N/Aimport com.sun.xml.internal.ws.api.server.ContainerResolver;
325N/Aimport com.sun.xml.internal.ws.api.server.WSEndpoint;
325N/Aimport com.sun.xml.internal.ws.client.WSServiceDelegate;
325N/A
325N/Aimport javax.xml.bind.JAXBContext;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.ws.Dispatch;
325N/Aimport javax.xml.ws.EndpointReference;
325N/Aimport javax.xml.ws.Service;
325N/Aimport javax.xml.ws.Service.Mode;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport javax.xml.ws.WebServiceFeature;
325N/Aimport javax.xml.ws.spi.ServiceDelegate;
325N/Aimport java.lang.reflect.Field;
325N/Aimport java.net.URL;
325N/Aimport java.security.AccessController;
325N/Aimport java.security.PrivilegedAction;
325N/A
325N/A/**
325N/A * JAX-WS implementation of {@link ServiceDelegate}.
325N/A *
325N/A * <p>
325N/A * This abstract class is used only to improve the static type safety
325N/A * of the JAX-WS internal API.
325N/A *
325N/A * <p>
325N/A * The class name intentionally doesn't include "Delegate",
325N/A * because the fact that it's a delegate is a detail of
325N/A * the JSR-224 API, and for the layers above us this object
325N/A * nevertheless represents {@link Service}. We want them
325N/A * to think of this as an internal representation of a service.
325N/A *
325N/A * <p>
325N/A * Only JAX-WS internal code may downcast this to {@link WSServiceDelegate}.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic abstract class WSService extends ServiceDelegate {
325N/A protected WSService() {
325N/A }
325N/A
325N/A /**
325N/A * Works like {@link #getPort(EndpointReference, Class, WebServiceFeature...)}
325N/A * but takes {@link WSEndpointReference}.
325N/A */
325N/A public abstract <T> T getPort(WSEndpointReference epr, Class<T> portInterface, WebServiceFeature... features);
325N/A
325N/A /**
325N/A * Works like {@link #createDispatch(EndpointReference, Class, Mode, WebServiceFeature[])}
325N/A * but it takes the port name separately, so that EPR without embedded metadata can be used.
325N/A */
325N/A public abstract <T> Dispatch<T> createDispatch(QName portName, WSEndpointReference wsepr, Class<T> aClass, Service.Mode mode, WebServiceFeature... features);
325N/A
325N/A /**
325N/A * Works like {@link #createDispatch(EndpointReference, JAXBContext, Mode, WebServiceFeature[])}
325N/A * but it takes the port name separately, so that EPR without embedded metadata can be used.
325N/A */
325N/A public abstract Dispatch<Object> createDispatch(QName portName, WSEndpointReference wsepr, JAXBContext jaxbContext, Service.Mode mode, WebServiceFeature... features);
325N/A
325N/A /**
325N/A * Gets the {@link Container} object.
325N/A *
325N/A * <p>
325N/A * The components inside {@link WSEndpoint} uses this reference
325N/A * to communicate with the hosting environment.
325N/A *
325N/A * @return
325N/A * always same object. If no "real" {@link Container} instance
325N/A * is given, {@link Container#NONE} will be returned.
325N/A */
325N/A public abstract @NotNull Container getContainer();
325N/A
325N/A /**
325N/A * Create a <code>Service</code> instance.
325N/A *
325N/A * The specified WSDL document location and service qualified name MUST
325N/A * uniquely identify a <code>wsdl:service</code> element.
325N/A *
325N/A * @param wsdlDocumentLocation URL for the WSDL document location
325N/A * for the service
325N/A * @param serviceName QName for the service
325N/A * @throws WebServiceException If any error in creation of the
325N/A * specified service.
325N/A **/
325N/A public static WSService create( URL wsdlDocumentLocation, QName serviceName) {
325N/A return new WSServiceDelegate(wsdlDocumentLocation,serviceName,Service.class);
325N/A }
325N/A
325N/A /**
325N/A * Create a <code>Service</code> instance.
325N/A *
325N/A * @param serviceName QName for the service
325N/A * @throws WebServiceException If any error in creation of the
325N/A * specified service
325N/A */
325N/A public static WSService create(QName serviceName) {
325N/A return create(null,serviceName);
325N/A }
325N/A
325N/A /**
325N/A * Creates a service with a dummy service name.
325N/A */
325N/A public static WSService create() {
325N/A return create(null,new QName(WSService.class.getName(),"dummy"));
325N/A }
325N/A
325N/A /**
325N/A * Typed parameter bag used by {@link WSService#create(URL, QName, InitParams)}
325N/A *
325N/A * @since 2.1.3
325N/A */
325N/A public static final class InitParams {
325N/A private Container container;
325N/A /**
325N/A * Sets the {@link Container} object used by the created service.
325N/A * This allows the client to use a specific {@link Container} instance
325N/A * as opposed to the one obtained by {@link ContainerResolver}.
325N/A */
325N/A public void setContainer(Container c) {
325N/A this.container = c;
325N/A }
325N/A public Container getContainer() {
325N/A return container;
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * To create a {@link Service}, we need to go through the API that doesn't let us
325N/A * pass parameters, so as a hack we use thread local.
325N/A */
325N/A protected static final ThreadLocal<InitParams> INIT_PARAMS = new ThreadLocal<InitParams>();
325N/A
325N/A /**
325N/A * Used as a immutable constant so that we can avoid null check.
325N/A */
325N/A protected static final InitParams EMPTY_PARAMS = new InitParams();
325N/A
325N/A /**
325N/A * Creates a {@link Service} instance.
325N/A *
325N/A * <p>
325N/A * This method works really like {@link Service#create(URL, QName)}
325N/A * except it takes one more RI specific parameter.
325N/A *
325N/A * @param wsdlDocumentLocation
325N/A * {@code URL} for the WSDL document location for the service.
325N/A * Can be null, in which case WSDL is not loaded.
325N/A * @param serviceName
325N/A * {@code QName} for the service.
325N/A * @param properties
325N/A * Additional RI specific initialization parameters. Can be null.
325N/A * @throws WebServiceException
325N/A * If any error in creation of the specified service.
325N/A **/
325N/A public static Service create( URL wsdlDocumentLocation, QName serviceName, InitParams properties) {
325N/A if(INIT_PARAMS.get()!=null)
325N/A throw new IllegalStateException("someone left non-null InitParams");
325N/A INIT_PARAMS.set(properties);
325N/A try {
325N/A Service svc = Service.create(wsdlDocumentLocation, serviceName);
325N/A if(INIT_PARAMS.get()!=null)
325N/A throw new IllegalStateException("Service "+svc+" didn't recognize InitParams");
325N/A return svc;
325N/A } finally {
325N/A // even in case of an exception still reset INIT_PARAMS
325N/A INIT_PARAMS.set(null);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Obtains the {@link WSService} that's encapsulated inside a {@link Service}.
325N/A *
325N/A * @throws IllegalArgumentException
325N/A * if the given service object is not from the JAX-WS RI.
325N/A */
325N/A public static WSService unwrap(final Service svc) {
325N/A return AccessController.doPrivileged(new PrivilegedAction<WSService>() {
325N/A public WSService run() {
325N/A try {
325N/A Field f = svc.getClass().getField("delegate");
325N/A f.setAccessible(true);
325N/A Object delegate = f.get(svc);
325N/A if(!(delegate instanceof WSService))
325N/A throw new IllegalArgumentException();
325N/A return (WSService) delegate;
325N/A } catch (NoSuchFieldException e) {
325N/A AssertionError x = new AssertionError("Unexpected service API implementation");
325N/A x.initCause(e);
325N/A throw x;
325N/A } catch (IllegalAccessException e) {
325N/A IllegalAccessError x = new IllegalAccessError(e.getMessage());
325N/A x.initCause(e);
325N/A throw x;
325N/A }
325N/A }
325N/A });
325N/A }
325N/A}