Fri, 04 Oct 2013 16:21:34 +0100
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.wsdl.writer; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; |
ohair@286 | 29 | import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGenExtnContext; |
ohair@286 | 30 | import com.sun.xml.internal.ws.api.model.JavaMethod; |
ohair@286 | 31 | import com.sun.xml.internal.ws.api.model.CheckedException; |
ohair@286 | 32 | import com.sun.xml.internal.txw2.TypedXmlWriter; |
ohair@286 | 33 | import static com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants.*; |
ohair@286 | 34 | import com.sun.xml.internal.ws.model.JavaMethodImpl; |
ohair@286 | 35 | import com.sun.xml.internal.ws.model.CheckedExceptionImpl; |
ohair@286 | 36 | import com.sun.xml.internal.ws.addressing.WsaActionUtil; |
ohair@286 | 37 | import java.net.URI; |
ohair@286 | 38 | import java.net.URISyntaxException; |
ohair@286 | 39 | import java.util.logging.Logger; |
ohair@286 | 40 | |
ohair@286 | 41 | /** |
ohair@286 | 42 | * This extension class generates wsam:Action values for input, output and faults in the generated wsdl. |
ohair@286 | 43 | * |
ohair@286 | 44 | * @author Rama Pulavarthi |
ohair@286 | 45 | */ |
ohair@286 | 46 | public class W3CAddressingMetadataWSDLGeneratorExtension extends |
ohair@286 | 47 | WSDLGeneratorExtension { |
ohair@286 | 48 | |
ohair@286 | 49 | @Override |
ohair@286 | 50 | public void start(WSDLGenExtnContext ctxt) { |
ohair@286 | 51 | TypedXmlWriter root = ctxt.getRoot(); |
ohair@286 | 52 | root._namespace(WSAM_NAMESPACE_NAME, WSAM_PREFIX_NAME); |
ohair@286 | 53 | } |
ohair@286 | 54 | |
ohair@286 | 55 | @Override |
ohair@286 | 56 | public void addOperationInputExtension(TypedXmlWriter input, |
ohair@286 | 57 | JavaMethod method) { |
ohair@286 | 58 | input._attribute(WSAM_ACTION_QNAME, getInputAction(method)); |
ohair@286 | 59 | } |
ohair@286 | 60 | |
ohair@286 | 61 | @Override |
ohair@286 | 62 | public void addOperationOutputExtension(TypedXmlWriter output, |
ohair@286 | 63 | JavaMethod method) { |
ohair@286 | 64 | output._attribute(WSAM_ACTION_QNAME, getOutputAction(method)); |
ohair@286 | 65 | } |
ohair@286 | 66 | |
ohair@286 | 67 | @Override |
ohair@286 | 68 | public void addOperationFaultExtension(TypedXmlWriter fault, |
ohair@286 | 69 | JavaMethod method, CheckedException ce) { |
ohair@286 | 70 | fault._attribute(WSAM_ACTION_QNAME, getFaultAction(method, ce)); |
ohair@286 | 71 | } |
ohair@286 | 72 | |
ohair@286 | 73 | |
ohair@286 | 74 | private static final String getInputAction(JavaMethod method) { |
ohair@286 | 75 | String inputaction = ((JavaMethodImpl)method).getInputAction(); |
ohair@286 | 76 | if (inputaction.equals("")) { |
ohair@286 | 77 | // Calculate default action |
ohair@286 | 78 | inputaction = getDefaultInputAction(method); |
ohair@286 | 79 | } |
ohair@286 | 80 | return inputaction; |
ohair@286 | 81 | } |
ohair@286 | 82 | |
ohair@286 | 83 | protected static final String getDefaultInputAction(JavaMethod method) { |
ohair@286 | 84 | String tns = method.getOwner().getTargetNamespace(); |
ohair@286 | 85 | String delim = getDelimiter(tns); |
ohair@286 | 86 | if (tns.endsWith(delim)) |
ohair@286 | 87 | tns = tns.substring(0, tns.length() - 1); |
ohair@286 | 88 | //this assumes that fromjava case there won't be input name. |
ohair@286 | 89 | // if there is input name in future, then here name=inputName |
ohair@286 | 90 | //else use operation name as follows. |
ohair@286 | 91 | String name = (method.getMEP().isOneWay()) ? |
ohair@286 | 92 | method.getOperationName() : method.getOperationName() + "Request"; |
ohair@286 | 93 | |
ohair@286 | 94 | return new StringBuilder(tns).append(delim).append( |
ohair@286 | 95 | method.getOwner().getPortTypeName().getLocalPart()).append( |
ohair@286 | 96 | delim).append(name).toString(); |
ohair@286 | 97 | } |
ohair@286 | 98 | |
ohair@286 | 99 | private static final String getOutputAction(JavaMethod method) { |
ohair@286 | 100 | String outputaction = ((JavaMethodImpl)method).getOutputAction(); |
ohair@286 | 101 | if(outputaction.equals("")) |
ohair@286 | 102 | outputaction = getDefaultOutputAction(method); |
ohair@286 | 103 | return outputaction; |
ohair@286 | 104 | } |
ohair@286 | 105 | |
ohair@286 | 106 | protected static final String getDefaultOutputAction(JavaMethod method) { |
ohair@286 | 107 | String tns = method.getOwner().getTargetNamespace(); |
ohair@286 | 108 | String delim = getDelimiter(tns); |
ohair@286 | 109 | if (tns.endsWith(delim)) |
ohair@286 | 110 | tns = tns.substring(0, tns.length() - 1); |
ohair@286 | 111 | //this assumes that fromjava case there won't be output name. |
ohair@286 | 112 | // if there is input name in future, then here name=outputName |
ohair@286 | 113 | //else use operation name as follows. |
ohair@286 | 114 | String name = method.getOperationName() + "Response"; |
ohair@286 | 115 | |
ohair@286 | 116 | return new StringBuilder(tns).append(delim).append( |
ohair@286 | 117 | method.getOwner().getPortTypeName().getLocalPart()).append( |
ohair@286 | 118 | delim).append(name).toString(); |
ohair@286 | 119 | } |
ohair@286 | 120 | |
ohair@286 | 121 | |
ohair@286 | 122 | private static final String getDelimiter(String tns) { |
ohair@286 | 123 | String delim = "/"; |
ohair@286 | 124 | // TODO: is this the correct way to find the separator ? |
ohair@286 | 125 | try { |
ohair@286 | 126 | URI uri = new URI(tns); |
ohair@286 | 127 | if ((uri.getScheme() != null) && uri.getScheme().equalsIgnoreCase("urn")) |
ohair@286 | 128 | delim = ":"; |
ohair@286 | 129 | } catch (URISyntaxException e) { |
ohair@286 | 130 | LOGGER.warning("TargetNamespace of WebService is not a valid URI"); |
ohair@286 | 131 | } |
ohair@286 | 132 | return delim; |
ohair@286 | 133 | |
ohair@286 | 134 | } |
ohair@286 | 135 | |
ohair@286 | 136 | private static final String getFaultAction(JavaMethod method, |
ohair@286 | 137 | CheckedException ce) { |
ohair@286 | 138 | String faultaction = ((CheckedExceptionImpl)ce).getFaultAction(); |
ohair@286 | 139 | if (faultaction.equals("")) { |
ohair@286 | 140 | faultaction = getDefaultFaultAction(method,ce); |
ohair@286 | 141 | } |
ohair@286 | 142 | return faultaction; |
ohair@286 | 143 | } |
ohair@286 | 144 | |
ohair@286 | 145 | protected static final String getDefaultFaultAction(JavaMethod method, CheckedException ce) { |
ohair@286 | 146 | return WsaActionUtil.getDefaultFaultAction(method,ce); |
ohair@286 | 147 | } |
ohair@286 | 148 | |
ohair@286 | 149 | private static final Logger LOGGER = |
ohair@286 | 150 | Logger.getLogger(W3CAddressingMetadataWSDLGeneratorExtension.class.getName()); |
ohair@286 | 151 | } |