1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/writer/W3CAddressingMetadataWSDLGeneratorExtension.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,151 @@ 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.wsdl.writer; 1.30 + 1.31 +import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; 1.32 +import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGenExtnContext; 1.33 +import com.sun.xml.internal.ws.api.model.JavaMethod; 1.34 +import com.sun.xml.internal.ws.api.model.CheckedException; 1.35 +import com.sun.xml.internal.txw2.TypedXmlWriter; 1.36 +import static com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants.*; 1.37 +import com.sun.xml.internal.ws.model.JavaMethodImpl; 1.38 +import com.sun.xml.internal.ws.model.CheckedExceptionImpl; 1.39 +import com.sun.xml.internal.ws.addressing.WsaActionUtil; 1.40 +import java.net.URI; 1.41 +import java.net.URISyntaxException; 1.42 +import java.util.logging.Logger; 1.43 + 1.44 +/** 1.45 + * This extension class generates wsam:Action values for input, output and faults in the generated wsdl. 1.46 + * 1.47 + * @author Rama Pulavarthi 1.48 + */ 1.49 +public class W3CAddressingMetadataWSDLGeneratorExtension extends 1.50 + WSDLGeneratorExtension { 1.51 + 1.52 + @Override 1.53 + public void start(WSDLGenExtnContext ctxt) { 1.54 + TypedXmlWriter root = ctxt.getRoot(); 1.55 + root._namespace(WSAM_NAMESPACE_NAME, WSAM_PREFIX_NAME); 1.56 + } 1.57 + 1.58 + @Override 1.59 + public void addOperationInputExtension(TypedXmlWriter input, 1.60 + JavaMethod method) { 1.61 + input._attribute(WSAM_ACTION_QNAME, getInputAction(method)); 1.62 + } 1.63 + 1.64 + @Override 1.65 + public void addOperationOutputExtension(TypedXmlWriter output, 1.66 + JavaMethod method) { 1.67 + output._attribute(WSAM_ACTION_QNAME, getOutputAction(method)); 1.68 + } 1.69 + 1.70 + @Override 1.71 + public void addOperationFaultExtension(TypedXmlWriter fault, 1.72 + JavaMethod method, CheckedException ce) { 1.73 + fault._attribute(WSAM_ACTION_QNAME, getFaultAction(method, ce)); 1.74 + } 1.75 + 1.76 + 1.77 + private static final String getInputAction(JavaMethod method) { 1.78 + String inputaction = ((JavaMethodImpl)method).getInputAction(); 1.79 + if (inputaction.equals("")) { 1.80 + // Calculate default action 1.81 + inputaction = getDefaultInputAction(method); 1.82 + } 1.83 + return inputaction; 1.84 + } 1.85 + 1.86 + protected static final String getDefaultInputAction(JavaMethod method) { 1.87 + String tns = method.getOwner().getTargetNamespace(); 1.88 + String delim = getDelimiter(tns); 1.89 + if (tns.endsWith(delim)) 1.90 + tns = tns.substring(0, tns.length() - 1); 1.91 + //this assumes that fromjava case there won't be input name. 1.92 + // if there is input name in future, then here name=inputName 1.93 + //else use operation name as follows. 1.94 + String name = (method.getMEP().isOneWay()) ? 1.95 + method.getOperationName() : method.getOperationName() + "Request"; 1.96 + 1.97 + return new StringBuilder(tns).append(delim).append( 1.98 + method.getOwner().getPortTypeName().getLocalPart()).append( 1.99 + delim).append(name).toString(); 1.100 + } 1.101 + 1.102 + private static final String getOutputAction(JavaMethod method) { 1.103 + String outputaction = ((JavaMethodImpl)method).getOutputAction(); 1.104 + if(outputaction.equals("")) 1.105 + outputaction = getDefaultOutputAction(method); 1.106 + return outputaction; 1.107 + } 1.108 + 1.109 + protected static final String getDefaultOutputAction(JavaMethod method) { 1.110 + String tns = method.getOwner().getTargetNamespace(); 1.111 + String delim = getDelimiter(tns); 1.112 + if (tns.endsWith(delim)) 1.113 + tns = tns.substring(0, tns.length() - 1); 1.114 + //this assumes that fromjava case there won't be output name. 1.115 + // if there is input name in future, then here name=outputName 1.116 + //else use operation name as follows. 1.117 + String name = method.getOperationName() + "Response"; 1.118 + 1.119 + return new StringBuilder(tns).append(delim).append( 1.120 + method.getOwner().getPortTypeName().getLocalPart()).append( 1.121 + delim).append(name).toString(); 1.122 + } 1.123 + 1.124 + 1.125 + private static final String getDelimiter(String tns) { 1.126 + String delim = "/"; 1.127 + // TODO: is this the correct way to find the separator ? 1.128 + try { 1.129 + URI uri = new URI(tns); 1.130 + if ((uri.getScheme() != null) && uri.getScheme().equalsIgnoreCase("urn")) 1.131 + delim = ":"; 1.132 + } catch (URISyntaxException e) { 1.133 + LOGGER.warning("TargetNamespace of WebService is not a valid URI"); 1.134 + } 1.135 + return delim; 1.136 + 1.137 + } 1.138 + 1.139 + private static final String getFaultAction(JavaMethod method, 1.140 + CheckedException ce) { 1.141 + String faultaction = ((CheckedExceptionImpl)ce).getFaultAction(); 1.142 + if (faultaction.equals("")) { 1.143 + faultaction = getDefaultFaultAction(method,ce); 1.144 + } 1.145 + return faultaction; 1.146 + } 1.147 + 1.148 + protected static final String getDefaultFaultAction(JavaMethod method, CheckedException ce) { 1.149 + return WsaActionUtil.getDefaultFaultAction(method,ce); 1.150 + } 1.151 + 1.152 + private static final Logger LOGGER = 1.153 + Logger.getLogger(W3CAddressingMetadataWSDLGeneratorExtension.class.getName()); 1.154 +}