src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/writer/W3CAddressingMetadataWSDLGeneratorExtension.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, 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.wsdl.writer;
    28 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension;
    29 import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGenExtnContext;
    30 import com.sun.xml.internal.ws.api.model.JavaMethod;
    31 import com.sun.xml.internal.ws.api.model.CheckedException;
    32 import com.sun.xml.internal.txw2.TypedXmlWriter;
    33 import static com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants.*;
    34 import com.sun.xml.internal.ws.model.JavaMethodImpl;
    35 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
    36 import com.sun.xml.internal.ws.addressing.WsaActionUtil;
    37 import java.net.URI;
    38 import java.net.URISyntaxException;
    39 import java.util.logging.Logger;
    41 /**
    42  * This extension class generates wsam:Action values for input, output and faults in the generated wsdl.
    43  *
    44  * @author Rama Pulavarthi
    45  */
    46 public class W3CAddressingMetadataWSDLGeneratorExtension extends
    47         WSDLGeneratorExtension {
    49     @Override
    50     public void start(WSDLGenExtnContext ctxt) {
    51         TypedXmlWriter root = ctxt.getRoot();
    52         root._namespace(WSAM_NAMESPACE_NAME, WSAM_PREFIX_NAME);
    53     }
    55     @Override
    56     public void addOperationInputExtension(TypedXmlWriter input,
    57                                            JavaMethod method) {
    58         input._attribute(WSAM_ACTION_QNAME, getInputAction(method));
    59     }
    61     @Override
    62     public void addOperationOutputExtension(TypedXmlWriter output,
    63                                             JavaMethod method) {
    64         output._attribute(WSAM_ACTION_QNAME, getOutputAction(method));
    65     }
    67     @Override
    68     public void addOperationFaultExtension(TypedXmlWriter fault,
    69                                            JavaMethod method, CheckedException ce) {
    70         fault._attribute(WSAM_ACTION_QNAME, getFaultAction(method, ce));
    71     }
    74     private static final String getInputAction(JavaMethod method) {
    75         String inputaction = ((JavaMethodImpl)method).getInputAction();
    76         if (inputaction.equals("")) {
    77             // Calculate default action
    78             inputaction = getDefaultInputAction(method);
    79         }
    80         return inputaction;
    81     }
    83     protected static final String getDefaultInputAction(JavaMethod method) {
    84         String tns = method.getOwner().getTargetNamespace();
    85         String delim = getDelimiter(tns);
    86         if (tns.endsWith(delim))
    87             tns = tns.substring(0, tns.length() - 1);
    88         //this assumes that fromjava case there won't be input name.
    89         // if there is input name in future, then here name=inputName
    90         //else use operation name as follows.
    91         String name = (method.getMEP().isOneWay()) ?
    92                 method.getOperationName() : method.getOperationName() + "Request";
    94         return new StringBuilder(tns).append(delim).append(
    95                 method.getOwner().getPortTypeName().getLocalPart()).append(
    96                 delim).append(name).toString();
    97     }
    99     private static final String getOutputAction(JavaMethod method) {
   100         String outputaction = ((JavaMethodImpl)method).getOutputAction();
   101         if(outputaction.equals(""))
   102             outputaction = getDefaultOutputAction(method);
   103         return outputaction;
   104     }
   106     protected static final String getDefaultOutputAction(JavaMethod method) {
   107         String tns = method.getOwner().getTargetNamespace();
   108         String delim = getDelimiter(tns);
   109         if (tns.endsWith(delim))
   110             tns = tns.substring(0, tns.length() - 1);
   111         //this assumes that fromjava case there won't be output name.
   112         // if there is input name in future, then here name=outputName
   113         //else use operation name as follows.
   114         String name = method.getOperationName() + "Response";
   116         return new StringBuilder(tns).append(delim).append(
   117                 method.getOwner().getPortTypeName().getLocalPart()).append(
   118                 delim).append(name).toString();
   119     }
   122     private static final String getDelimiter(String tns) {
   123         String delim = "/";
   124         // TODO: is this the correct way to find the separator ?
   125         try {
   126             URI uri = new URI(tns);
   127             if ((uri.getScheme() != null) && uri.getScheme().equalsIgnoreCase("urn"))
   128                 delim = ":";
   129         } catch (URISyntaxException e) {
   130             LOGGER.warning("TargetNamespace of WebService is not a valid URI");
   131         }
   132         return delim;
   134     }
   136     private static final String getFaultAction(JavaMethod method,
   137                                                CheckedException ce) {
   138         String faultaction = ((CheckedExceptionImpl)ce).getFaultAction();
   139         if (faultaction.equals("")) {
   140             faultaction = getDefaultFaultAction(method,ce);
   141         }
   142         return faultaction;
   143     }
   145     protected static final String getDefaultFaultAction(JavaMethod method, CheckedException ce) {
   146         return WsaActionUtil.getDefaultFaultAction(method,ce);
   147     }
   149     private static final Logger LOGGER =
   150             Logger.getLogger(W3CAddressingMetadataWSDLGeneratorExtension.class.getName());
   151 }

mercurial