src/share/jaxws_classes/com/sun/xml/internal/ws/server/provider/ProviderEndpointModel.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/server/provider/ProviderEndpointModel.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.server.provider;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.xml.internal.ws.api.WSBinding;
    1.33 +import com.sun.xml.internal.ws.api.server.AsyncProvider;
    1.34 +import com.sun.xml.internal.ws.resources.ServerMessages;
    1.35 +import com.sun.xml.internal.ws.spi.db.BindingHelper;
    1.36 +
    1.37 +import javax.activation.DataSource;
    1.38 +import javax.xml.soap.SOAPMessage;
    1.39 +import javax.xml.transform.Source;
    1.40 +import javax.xml.ws.Provider;
    1.41 +import javax.xml.ws.Service;
    1.42 +import javax.xml.ws.ServiceMode;
    1.43 +import javax.xml.ws.WebServiceException;
    1.44 +import javax.xml.ws.soap.SOAPBinding;
    1.45 +import java.lang.reflect.ParameterizedType;
    1.46 +import java.lang.reflect.Type;
    1.47 +
    1.48 +
    1.49 +/**
    1.50 + * Keeps the runtime information like Service.Mode and erasure of Provider class
    1.51 + * about Provider endpoint. It proccess annotations to find about Service.Mode
    1.52 + * It also finds about parameterized type(e.g. Source, SOAPMessage, DataSource)
    1.53 + * of endpoint class.
    1.54 + *
    1.55 + * @author Jitendra Kotamraju
    1.56 + * @author Kohsuke Kawaguchi
    1.57 + */
    1.58 +final class ProviderEndpointModel<T> {
    1.59 +    /**
    1.60 +     * True if this is {@link AsyncProvider}.
    1.61 +     */
    1.62 +    final boolean isAsync;
    1.63 +
    1.64 +    /**
    1.65 +     * In which mode does this provider operate?
    1.66 +     */
    1.67 +    @NotNull final Service.Mode mode;
    1.68 +    /**
    1.69 +     * T of {@link Provider}&lt;T>.
    1.70 +     */
    1.71 +    @NotNull final Class datatype;
    1.72 +    /**
    1.73 +     * User class that extends {@link Provider}.
    1.74 +     */
    1.75 +    @NotNull final Class implClass;
    1.76 +
    1.77 +    ProviderEndpointModel(Class<T> implementorClass, WSBinding binding) {
    1.78 +        assert implementorClass != null;
    1.79 +        assert binding != null;
    1.80 +
    1.81 +        implClass = implementorClass;
    1.82 +        mode = getServiceMode(implementorClass);
    1.83 +        Class otherClass = (binding instanceof SOAPBinding)
    1.84 +            ? SOAPMessage.class : DataSource.class;
    1.85 +        isAsync = AsyncProvider.class.isAssignableFrom(implementorClass);
    1.86 +
    1.87 +
    1.88 +        Class<? extends Object> baseType = isAsync ? AsyncProvider.class : Provider.class;
    1.89 +        Type baseParam = BindingHelper.getBaseType(implementorClass, baseType);
    1.90 +        if (baseParam==null)
    1.91 +            throw new WebServiceException(ServerMessages.NOT_IMPLEMENT_PROVIDER(implementorClass.getName()));
    1.92 +        if (!(baseParam instanceof ParameterizedType))
    1.93 +            throw new WebServiceException(ServerMessages.PROVIDER_NOT_PARAMETERIZED(implementorClass.getName()));
    1.94 +
    1.95 +        ParameterizedType pt = (ParameterizedType)baseParam;
    1.96 +        Type[] types = pt.getActualTypeArguments();
    1.97 +        if(!(types[0] instanceof Class))
    1.98 +            throw new WebServiceException(ServerMessages.PROVIDER_INVALID_PARAMETER_TYPE(implementorClass.getName(),types[0]));
    1.99 +        datatype = (Class)types[0];
   1.100 +
   1.101 +        if (mode == Service.Mode.PAYLOAD && datatype!=Source.class) {
   1.102 +            // Illegal to have PAYLOAD && SOAPMessage
   1.103 +            // Illegal to have PAYLOAD && DataSource
   1.104 +            throw new IllegalArgumentException(
   1.105 +                "Illeagal combination - Mode.PAYLOAD and Provider<"+otherClass.getName()+">");
   1.106 +        }
   1.107 +    }
   1.108 +
   1.109 +    /**
   1.110 +     * Is it PAYLOAD or MESSAGE ??
   1.111 +     *
   1.112 +     * @param c endpoint class
   1.113 +     * @return Service.Mode.PAYLOAD or Service.Mode.MESSAGE
   1.114 +     */
   1.115 +    private static Service.Mode getServiceMode(Class<?> c) {
   1.116 +        ServiceMode mode = c.getAnnotation(ServiceMode.class);
   1.117 +        return (mode == null) ? Service.Mode.PAYLOAD : mode.value();
   1.118 +    }
   1.119 +}

mercurial