1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/WSDLInternalizationLogic.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,147 @@ 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.tools.internal.ws.wsdl.parser; 1.30 + 1.31 +import com.sun.tools.internal.ws.wscompile.WsimportOptions; 1.32 +import com.sun.tools.internal.ws.wsdl.document.WSDLConstants; 1.33 +import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; 1.34 +import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants; 1.35 +import com.sun.tools.internal.xjc.util.DOMUtils; 1.36 +import org.w3c.dom.Element; 1.37 +import org.w3c.dom.NodeList; 1.38 +import org.xml.sax.Attributes; 1.39 +import org.xml.sax.helpers.XMLFilterImpl; 1.40 + 1.41 +/** 1.42 + * @author Vivek Pandey 1.43 + */ 1.44 +public class WSDLInternalizationLogic implements InternalizationLogic{ 1.45 + 1.46 + /** 1.47 + * This filter looks for <xs:import> and <xs:include> 1.48 + * and parses those documents referenced by them. 1.49 + */ 1.50 + private static final class ReferenceFinder extends AbstractReferenceFinderImpl { 1.51 + ReferenceFinder( DOMForest parent) { 1.52 + super(parent); 1.53 + } 1.54 + 1.55 + protected String findExternalResource( String nsURI, String localName, Attributes atts) { 1.56 + if(WSDLConstants.NS_WSDL.equals(nsURI) && "import".equals(localName)){ 1.57 + if(parent.isExtensionMode()){ 1.58 + //TODO: add support for importing schema using wsdl:import 1.59 + } 1.60 + return atts.getValue("location"); 1.61 + } 1.62 + 1.63 + // We don't need to do this anymore, JAXB handles the schema imports, includes etc., but this is useful for the clientJar option in 1.64 + // fetching the imported schemas to package in the jar.. 1.65 + if (parent.options.clientjar != null) { 1.66 + if (SchemaConstants.NS_XSD.equals(nsURI) && "import".equals(localName)) { 1.67 + return atts.getValue("schemaLocation"); 1.68 + } 1.69 + } 1.70 + return null; 1.71 + } 1.72 + } 1.73 + public XMLFilterImpl createExternalReferenceFinder(DOMForest parent) { 1.74 + return new ReferenceFinder(parent); 1.75 + } 1.76 + 1.77 + public boolean checkIfValidTargetNode(DOMForest parent, Element bindings, Element target) { 1.78 + return false; 1.79 + } 1.80 + 1.81 + public Element refineSchemaTarget(Element target) { 1.82 + // look for existing xs:annotation 1.83 + Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation"); 1.84 + if(annotation==null) 1.85 + // none exists. need to make one 1.86 + annotation = insertXMLSchemaElement( target, "annotation" ); 1.87 + 1.88 + // then look for appinfo 1.89 + Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo" ); 1.90 + if(appinfo==null) 1.91 + // none exists. need to make one 1.92 + appinfo = insertXMLSchemaElement( annotation, "appinfo" ); 1.93 + 1.94 + return appinfo; 1.95 + 1.96 + } 1.97 + 1.98 + public Element refineWSDLTarget(Element target){ 1.99 + // look for existing xs:annotation 1.100 + Element JAXWSBindings = DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings"); 1.101 + if(JAXWSBindings==null) 1.102 + // none exists. need to make one 1.103 + JAXWSBindings = insertJAXWSBindingsElement(target, "bindings" ); 1.104 + return JAXWSBindings; 1.105 + } 1.106 + 1.107 + private Element insertJAXWSBindingsElement( Element parent, String localName ) { 1.108 + String qname = "JAXWS:"+localName; 1.109 + 1.110 + Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname ); 1.111 + 1.112 + NodeList children = parent.getChildNodes(); 1.113 + 1.114 + if( children.getLength()==0 ) 1.115 + parent.appendChild(child); 1.116 + else 1.117 + parent.insertBefore( child, children.item(0) ); 1.118 + 1.119 + return child; 1.120 + } 1.121 + 1.122 + 1.123 + /** 1.124 + * Creates a new XML Schema element of the given local name 1.125 + * and insert it as the first child of the given parent node. 1.126 + * 1.127 + * @return 1.128 + * Newly create element. 1.129 + */ 1.130 + private Element insertXMLSchemaElement( Element parent, String localName ) { 1.131 + // use the same prefix as the parent node to avoid modifying 1.132 + // the namespace binding. 1.133 + String qname = parent.getTagName(); 1.134 + int idx = qname.indexOf(':'); 1.135 + if(idx==-1) qname = localName; 1.136 + else qname = qname.substring(0,idx+1)+localName; 1.137 + 1.138 + Element child = parent.getOwnerDocument().createElementNS( Constants.NS_XSD, qname ); 1.139 + 1.140 + NodeList children = parent.getChildNodes(); 1.141 + 1.142 + if( children.getLength()==0 ) 1.143 + parent.appendChild(child); 1.144 + else 1.145 + parent.insertBefore( child, children.item(0) ); 1.146 + 1.147 + return child; 1.148 + } 1.149 + 1.150 +}