src/share/jaxws_classes/com/sun/xml/internal/ws/model/JavaMethodImpl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.model;
    28 import com.sun.istack.internal.NotNull;
    29 import com.sun.xml.internal.bind.api.TypeReference;
    30 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
    31 import com.sun.xml.internal.ws.api.model.JavaMethod;
    32 import com.sun.xml.internal.ws.api.model.MEP;
    33 import com.sun.xml.internal.ws.api.model.SEIModel;
    34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
    37 import com.sun.xml.internal.ws.api.model.soap.SOAPBinding;
    38 import com.sun.xml.internal.ws.model.soap.SOAPBindingImpl;
    39 import com.sun.xml.internal.ws.spi.db.TypeInfo;
    40 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
    41 import com.sun.istack.internal.Nullable;
    43 import javax.xml.namespace.QName;
    44 import javax.xml.ws.Action;
    45 import javax.xml.ws.WebServiceException;
    46 import javax.jws.WebMethod;
    47 import java.lang.reflect.Method;
    48 import java.util.ArrayList;
    49 import java.util.Collections;
    50 import java.util.List;
    51 import java.util.logging.Logger;
    53 /**
    54  * Build this runtime model using java SEI and annotations
    55  *
    56  * @author Vivek Pandey
    57  */
    58 public final class JavaMethodImpl implements JavaMethod {
    60     private String inputAction = "";
    61     private String outputAction = "";
    62     private final List<CheckedExceptionImpl> exceptions = new ArrayList<CheckedExceptionImpl>();
    63     private final Method method;
    64     /*package*/ final List<ParameterImpl> requestParams = new ArrayList<ParameterImpl>();
    65     /*package*/ final List<ParameterImpl> responseParams = new ArrayList<ParameterImpl>();
    66     private final List<ParameterImpl> unmReqParams = Collections.unmodifiableList(requestParams);
    67     private final List<ParameterImpl> unmResParams = Collections.unmodifiableList(responseParams);
    68     private SOAPBinding binding;
    69     private MEP mep;
    70     private QName operationName;
    71     private WSDLBoundOperation wsdlOperation;
    72     /*package*/ final AbstractSEIModelImpl owner;
    73     private final Method seiMethod;
    74     private QName requestPayloadName;
    75     private String soapAction;
    77     /**
    78      * @param owner
    79      * @param method : Implementation class method
    80      * @param seiMethod : corresponding SEI Method.
    81      *                  Is there is no SEI, it should be Implementation class method
    82      */
    83     public JavaMethodImpl(AbstractSEIModelImpl owner, Method method, Method seiMethod, MetadataReader metadataReader) {
    84         this.owner = owner;
    85         this.method = method;
    86         this.seiMethod = seiMethod;
    87         setWsaActions(metadataReader);
    88     }
    90     private void setWsaActions(MetadataReader metadataReader) {
    91         Action action = (metadataReader != null)? metadataReader.getAnnotation(Action.class, seiMethod):seiMethod.getAnnotation(Action.class);
    92         if(action != null) {
    93             inputAction = action.input();
    94             outputAction = action.output();
    95         }
    97         //@Action(input) =="", get it from @WebMethod(action)
    98         WebMethod webMethod = (metadataReader != null)? metadataReader.getAnnotation(WebMethod.class, seiMethod):seiMethod.getAnnotation(WebMethod.class);
    99         soapAction = "";
   100         if (webMethod != null )
   101             soapAction = webMethod.action();
   102         if(!soapAction.equals("")) {
   103             //non-empty soapAction
   104             if(inputAction.equals(""))
   105                 // set input action to non-empty soapAction
   106                 inputAction = soapAction;
   107             else if(!inputAction.equals(soapAction)){
   108                 //both are explicitly set via annotations, make sure @Action == @WebMethod.action
   109                 //http://java.net/jira/browse/JAX_WS-1108
   110               //throw new WebServiceException("@Action and @WebMethod(action=\"\" does not match on operation "+ method.getName());
   111             }
   112         }
   113     }
   115     public ActionBasedOperationSignature getOperationSignature() {
   116         QName qname = getRequestPayloadName();
   117         if (qname == null) qname = new QName("", "");
   118         return new ActionBasedOperationSignature(getInputAction(), qname);
   119     }
   121     public SEIModel getOwner() {
   122         return owner;
   123     }
   125     /**
   126      * @see JavaMethod
   127      *
   128      * @return Returns the method.
   129      */
   130     public Method getMethod() {
   131         return method;
   132     }
   134     /**
   135      * @see JavaMethod
   136      *
   137      * @return Returns the SEI method where annotations are present
   138      */
   139     public Method getSEIMethod() {
   140         return seiMethod;
   141     }
   143     /**
   144      * @return Returns the mep.
   145      */
   146     public MEP getMEP() {
   147         return mep;
   148     }
   150     /**
   151      * @param mep
   152      *            The mep to set.
   153      */
   154     void setMEP(MEP mep) {
   155         this.mep = mep;
   156     }
   158     /**
   159      * @return the Binding object
   160      */
   161     public SOAPBinding getBinding() {
   162         if (binding == null)
   163             return new SOAPBindingImpl();
   164         return binding;
   165     }
   167     /**
   168      * @param binding
   169      */
   170     void setBinding(SOAPBinding binding) {
   171         this.binding = binding;
   172     }
   174     /**
   175      * Returns the {@link WSDLBoundOperation} Operation associated with {@link JavaMethodImpl}
   176      * operation.
   177      * @deprecated
   178      * @return the WSDLBoundOperation for this JavaMethod
   179      */
   180     public WSDLBoundOperation getOperation() {
   181 //        assert wsdlOperation != null;
   182         return wsdlOperation;
   183     }
   185     public void setOperationQName(QName name) {
   186         this.operationName = name;
   187     }
   189     public QName getOperationQName() {
   190         return (wsdlOperation != null)? wsdlOperation.getName(): operationName;
   191     }
   193     public String getSOAPAction() {
   194         return (wsdlOperation != null)? wsdlOperation.getSOAPAction(): soapAction;
   195     }
   197     public String getOperationName() {
   198         return operationName.getLocalPart();
   199     }
   201     public String getRequestMessageName() {
   202         return getOperationName();
   203     }
   205     public String getResponseMessageName() {
   206         if(mep.isOneWay())
   207             return null;
   208         return getOperationName()+"Response";
   209     }
   211     public void setRequestPayloadName(QName n)  {
   212         requestPayloadName = n;
   213     }
   215     /**
   216      * @return soap:Body's first child name for request message.
   217      */
   218     public @Nullable QName getRequestPayloadName() {
   219         return (wsdlOperation != null)? wsdlOperation.getReqPayloadName(): requestPayloadName;
   220     }
   222     /**
   223      * @return soap:Body's first child name for response message.
   224      */
   225     public @Nullable QName getResponsePayloadName() {
   226         return (mep == MEP.ONE_WAY) ? null : wsdlOperation.getResPayloadName();
   227     }
   229     /**
   230      * @return returns unmodifiable list of request parameters
   231      */
   232     public List<ParameterImpl> getRequestParameters() {
   233         return unmReqParams;
   234     }
   236     /**
   237      * @return returns unmodifiable list of response parameters
   238      */
   239     public List<ParameterImpl> getResponseParameters() {
   240         return unmResParams;
   241     }
   243     void addParameter(ParameterImpl p) {
   244         if (p.isIN() || p.isINOUT()) {
   245             assert !requestParams.contains(p);
   246             requestParams.add(p);
   247         }
   249         if (p.isOUT() || p.isINOUT()) {
   250             // this check is only for out parameters
   251             assert !responseParams.contains(p);
   252             responseParams.add(p);
   253         }
   254     }
   256     void addRequestParameter(ParameterImpl p){
   257         if (p.isIN() || p.isINOUT()) {
   258             requestParams.add(p);
   259         }
   260     }
   262     void addResponseParameter(ParameterImpl p){
   263         if (p.isOUT() || p.isINOUT()) {
   264             responseParams.add(p);
   265         }
   266     }
   268     /**
   269      * @return Returns number of java method parameters - that will be all the
   270      *         IN, INOUT and OUT holders
   271      *
   272      * @deprecated no longer use in the new architecture
   273      */
   274     public int getInputParametersCount() {
   275         int count = 0;
   276         for (ParameterImpl param : requestParams) {
   277             if (param.isWrapperStyle()) {
   278                 count += ((WrapperParameter) param).getWrapperChildren().size();
   279             } else {
   280                 count++;
   281             }
   282         }
   284         for (ParameterImpl param : responseParams) {
   285             if (param.isWrapperStyle()) {
   286                 for (ParameterImpl wc : ((WrapperParameter) param).getWrapperChildren()) {
   287                     if (!wc.isResponse() && wc.isOUT()) {
   288                         count++;
   289                     }
   290                 }
   291             } else if (!param.isResponse() && param.isOUT()) {
   292                 count++;
   293             }
   294         }
   296         return count;
   297     }
   299     /**
   300      * @param ce
   301      */
   302     void addException(CheckedExceptionImpl ce) {
   303         if (!exceptions.contains(ce))
   304             exceptions.add(ce);
   305     }
   307     /**
   308      * @param exceptionClass
   309      * @return CheckedException corresponding to the exceptionClass. Returns
   310      *         null if not found.
   311      */
   312     public CheckedExceptionImpl getCheckedException(Class exceptionClass) {
   313         for (CheckedExceptionImpl ce : exceptions) {
   314             if (ce.getExceptionClass()==exceptionClass)
   315                 return ce;
   316         }
   317         return null;
   318     }
   321     /**
   322      * @return a list of checked Exceptions thrown by this method
   323      */
   324     public List<CheckedExceptionImpl> getCheckedExceptions(){
   325         return Collections.unmodifiableList(exceptions);
   326     }
   328     public String getInputAction() {
   329 //        return (wsdlOperation != null)? wsdlOperation.getOperation().getInput().getAction(): inputAction;
   330         return inputAction;
   331     }
   333     public String getOutputAction() {
   334 //        return (wsdlOperation != null)? wsdlOperation.getOperation().getOutput().getAction(): outputAction;
   335         return outputAction;
   336     }
   338     /**
   339      * @deprecated
   340      * @param detailType
   341      * @return Gets the CheckedException corresponding to detailType. Returns
   342      *         null if no CheckedExcpetion with the detailType found.
   343      */
   344     public CheckedExceptionImpl getCheckedException(TypeReference detailType) {
   345         for (CheckedExceptionImpl ce : exceptions) {
   346             TypeInfo actual = ce.getDetailType();
   347             if (actual.tagName.equals(detailType.tagName) && actual.type==detailType.type) {
   348                 return ce;
   349             }
   350         }
   351         return null;
   352     }
   356     /**
   357      * Returns if the java method  is async
   358      * @return if this is an Asynch
   359      */
   360     public boolean isAsync(){
   361         return mep.isAsync;
   362     }
   364     /*package*/ void freeze(WSDLPort portType) {
   365         this.wsdlOperation = portType.getBinding().get(new QName(portType.getBinding().getPortType().getName().getNamespaceURI(),getOperationName()));
   366         // TODO: replace this with proper error handling
   367         if(wsdlOperation ==null)
   368             throw new WebServiceException("Method "+seiMethod.getName()+" is exposed as WebMethod, but there is no corresponding wsdl operation with name "+operationName+" in the wsdl:portType" + portType.getBinding().getPortType().getName());
   370         //so far, the inputAction, outputAction and fault actions are set from the @Action and @FaultAction
   371         //set the values from WSDLModel, if such annotations are not present or defaulted
   372         if(inputAction.equals("")) {
   373                 inputAction = wsdlOperation.getOperation().getInput().getAction();
   374         } else if(!inputAction.equals(wsdlOperation.getOperation().getInput().getAction()))
   375                 //TODO input action might be from @Action or WebMethod(action)
   376                 LOGGER.warning("Input Action on WSDL operation "+wsdlOperation.getName().getLocalPart() + " and @Action on its associated Web Method " + seiMethod.getName() +" did not match and will cause problems in dispatching the requests");
   378         if (!mep.isOneWay()) {
   379             if (outputAction.equals(""))
   380                 outputAction = wsdlOperation.getOperation().getOutput().getAction();
   382             for (CheckedExceptionImpl ce : exceptions) {
   383                 if (ce.getFaultAction().equals("")) {
   384                     QName detailQName = ce.getDetailType().tagName;
   385                     WSDLFault wsdlfault = wsdlOperation.getOperation().getFault(detailQName);
   386                     if(wsdlfault == null) {
   387                         // mismatch between wsdl model and SEI model, log a warning and use  SEI model for Action determination
   388                         LOGGER.warning("Mismatch between Java model and WSDL model found, For wsdl operation " +
   389                                 wsdlOperation.getName() + ",There is no matching wsdl fault with detail QName " +
   390                                 ce.getDetailType().tagName);
   391                         ce.setFaultAction(ce.getDefaultFaultAction());
   392                     } else {
   393                         ce.setFaultAction(wsdlfault.getAction());
   394                     }
   395                 }
   396             }
   397         }
   398     }
   400     final void fillTypes(List<TypeInfo> types) {
   401         fillTypes(requestParams, types);
   402         fillTypes(responseParams, types);
   404         for (CheckedExceptionImpl ce : exceptions) {
   405             types.add(ce.getDetailType());
   406         }
   407     }
   409     private void fillTypes(List<ParameterImpl> params, List<TypeInfo> types) {
   410         for (ParameterImpl p : params) {
   411             p.fillTypes(types);
   412         }
   413     }
   415     private static final Logger LOGGER = Logger.getLogger(com.sun.xml.internal.ws.model.JavaMethodImpl.class.getName());
   417 }

mercurial