feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.wsdl.document.mime.MIMEConstants;
import org.w3c.dom.Element;
import java.util.Collections;
import java.util.Map;
/**
* An abstract implementation class of {@link TWSDLExtensionHandler}
*
* @author Vivek Pandey
*/
public abstract class AbstractExtensionHandler extends TWSDLExtensionHandler {
private final Map<String, AbstractExtensionHandler> extensionHandlers;
private final Map<String, AbstractExtensionHandler> unmodExtenHandlers;
public AbstractExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
this.extensionHandlers = extensionHandlerMap;
this.unmodExtenHandlers = Collections.unmodifiableMap(extensionHandlers);
}
public Map<String, AbstractExtensionHandler> getExtensionHandlers(){
return unmodExtenHandlers;
}
/**
* Callback that gets called by the WSDL parser or any other extension handler on finding an extensibility element
* that it can't understand.
*
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean doHandleExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (parent.getWSDLElementName().equals(MIMEConstants.QNAME_PART)) {
return handleMIMEPartExtension(context, parent, e);
} else {
return super.doHandleExtension(context, parent, e);
}
}
/**
* Callback for <code>wsdl:mime</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
protected boolean handleMIMEPartExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e){
return false;
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.istack.internal.SAXParseException2;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.XMLFilterImpl;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
/**
* XMLFilter that finds references to other schema files from
* SAX events.
*
* This implementation is a base implementation for typical case
* where we just need to look for a particular attribute which
* contains an URL to another schema file.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* Vivek Pandey
*/
public abstract class AbstractReferenceFinderImpl extends XMLFilterImpl {
protected final DOMForest parent;
protected AbstractReferenceFinderImpl( DOMForest _parent ) {
this.parent = _parent;
}
/**
* IF the given element contains a reference to an external resource,
* return its URL.
*
* @param nsURI
* Namespace URI of the current element
* @param localName
* Local name of the current element
* @return
* It's OK to return a relative URL.
*/
protected abstract String findExternalResource( String nsURI, String localName, Attributes atts);
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
super.startElement(namespaceURI, localName, qName, atts);
String relativeRef = findExternalResource(namespaceURI,localName,atts);
if(relativeRef==null) return; // non found
try {
// absolutize URL.
assert locator != null;
String lsi = locator.getSystemId();
String ref;
if (lsi.startsWith("jar:")) {
int bangIdx = lsi.indexOf('!');
if (bangIdx > 0) {
ref = new URL(new URL(lsi), relativeRef).toString();
} else
ref = relativeRef;
} else
ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
// then parse this schema as well,
// but don't mark this document as a root.
parent.parse(ref,false);
} catch( URISyntaxException e ) {
SAXParseException spe = new SAXParseException2(
WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef,e.getMessage()),
locator, e );
fatalError(spe);
throw spe;
} catch( IOException e ) {
SAXParseException spe = new SAXParseException2(
WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef,e.getMessage()),
locator, e );
fatalError(spe);
throw spe;
}
}
private Locator locator;
@Override
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
this.locator = locator;
}
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
/**
* An interface defining constants needed to read and write WSDL documents.
*
* @author WS Development Team
*/
public interface Constants {
// WSDL element tags
static final String TAG_BINDING = "binding";
static final String TAG_DEFINITIONS = "definitions";
static final String TAG_DOCUMENTATION = "documentation";
static final String TAG_MESSAGE = "message";
static final String TAG_PART = "part";
static final String TAG_PORT_TYPE = "portType";
static final String TAG_TYPES = "types";
static final String TAG_OPERATION = "operation";
static final String TAG_INPUT = "input";
static final String TAG_OUTPUT = "output";
static final String TAG_FAULT = "fault";
static final String TAG_SERVICE = "service";
static final String TAG_PORT = "port";
static final String TAG_ = "";
// WSDL attribute names
static final String ATTR_ELEMENT = "element";
static final String ATTR_NAME = "name";
static final String ATTR_REQUIRED = "required";
static final String ATTR_TARGET_NAMESPACE = "targetNamespace";
static final String ATTR_TYPE = "type";
static final String ATTR_MESSAGE = "message";
static final String ATTR_BINDING = "binding";
static final String ATTR_LOCATION = "location";
static final String ATTR_TRANSPORT = "transport";
static final String ATTR_STYLE = "style";
static final String ATTR_USE = "use";
static final String ATTR_NAMESPACE = "namespace";
static final String ATTR_ENCODING_STYLE = "encodingStyle";
static final String ATTR_PART = "part";
static final String ATTR_PARTS = "parts";
static final String ATTR_SOAP_ACTION = "soapAction";
static final String ATTR_PARAMETER_ORDER = "parameterOrder";
static final String ATTR_VERB = "verb";
// schema attribute names
static final String ATTR_ID = "id";
static final String ATTR_VERSION = "version";
static final String ATTR_ATTRIBUTE_FORM_DEFAULT = "attributeFormDefault";
static final String ATTR_BLOCK_DEFAULT = "blockDefault";
static final String ATTR_ELEMENT_FORM_DEFAULT = "elementFormDefault";
static final String ATTR_FINAL_DEFAULT = "finalDefault";
static final String ATTR_ABSTRACT = "abstract";
static final String ATTR_NILLABLE = "nillable";
static final String ATTR_DEFAULT = "default";
static final String ATTR_FIXED = "fixed";
static final String ATTR_FORM = "form";
static final String ATTR_BLOCK = "block";
static final String ATTR_FINAL = "final";
static final String ATTR_REF = "ref";
static final String ATTR_SUBSTITUTION_GROUP = "substitutionGroup";
static final String ATTR_MIN_OCCURS = "minOccurs";
static final String ATTR_MAX_OCCURS = "maxOccurs";
static final String ATTR_PROCESS_CONTENTS = "processContents";
static final String ATTR_MIXED = "mixed";
static final String ATTR_BASE = "base";
static final String ATTR_VALUE = "value";
static final String ATTR_XPATH = "xpath";
static final String ATTR_SCHEMA_LOCATION = "schemaLocation";
static final String ATTR_REFER = "refer";
static final String ATTR_ITEM_TYPE = "itemType";
static final String ATTR_PUBLIC = "public";
static final String ATTR_SYSTEM = "system";
static final String ATTR_MEMBER_TYPES = "memberTypes";
static final String ATTR_ = "";
// WSDL attribute values
static final String ATTRVALUE_RPC = "rpc";
static final String ATTRVALUE_DOCUMENT = "document";
static final String ATTRVALUE_LITERAL = "literal";
static final String ATTRVALUE_ENCODED = "encoded";
// schema attribute values
static final String ATTRVALUE_QUALIFIED = "qualified";
static final String ATTRVALUE_UNQUALIFIED = "unqualified";
static final String ATTRVALUE_ALL = "#all";
static final String ATTRVALUE_SUBSTITUTION = "substitution";
static final String ATTRVALUE_EXTENSION = "extension";
static final String ATTRVALUE_RESTRICTION = "restriction";
static final String ATTRVALUE_LIST = "list";
static final String ATTRVALUE_UNION = "union";
static final String ATTRVALUE_UNBOUNDED = "unbounded";
static final String ATTRVALUE_PROHIBITED = "prohibited";
static final String ATTRVALUE_OPTIONAL = "optional";
static final String ATTRVALUE_REQUIRED = "required";
static final String ATTRVALUE_LAX = "lax";
static final String ATTRVALUE_SKIP = "skip";
static final String ATTRVALUE_STRICT = "strict";
static final String ATTRVALUE_ANY = "##any";
static final String ATTRVALUE_LOCAL = "##local";
static final String ATTRVALUE_OTHER = "##other";
static final String ATTRVALUE_TARGET_NAMESPACE = "##targetNamespace";
static final String ATTRVALUE_ = "";
// namespace URIs
static final String NS_XML = "http://www.w3.org/XML/1998/namespace";
static final String NS_XMLNS = "http://www.w3.org/2000/xmlns/";
static final String NS_WSDL = "http://schemas.xmlsoap.org/wsdl/";
static final String NS_WSDL_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
static final String NS_WSDL_SOAP12 = "http://schemas.xmlsoap.org/wsdl/soap12/";
static final String NS_WSDL_HTTP = "http://schemas.xmlsoap.org/wsdl/http/";
static final String NS_WSDL_MIME = "http://schemas.xmlsoap.org/wsdl/mime/";
static final String NS_XSD = "http://www.w3.org/2001/XMLSchema";
static final String NS_XSI = "http://www.w3.org/2001/XMLSchema-instance";
static final String NS_ = "";
// other constants
static final String XMLNS = "xmlns";
static final String TRUE = "true";
static final String FALSE = "false";
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import java.util.WeakHashMap;
/**
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
*/
abstract class ContextClassloaderLocal<V> {
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
public V get() throws Error {
ClassLoader tccl = getContextClassLoader();
V instance = CACHE.get(tccl);
if (instance == null) {
instance = createNewInstance();
CACHE.put(tccl, instance);
}
return instance;
}
public void set(V instance) {
CACHE.put(getContextClassLoader(), instance);
}
protected abstract V initialValue() throws Exception;
private V createNewInstance() {
try {
return initialValue();
} catch (Exception e) {
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
}
}
private static String format(String property, Object... args) {
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
return MessageFormat.format(text, args);
}
private static ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
}
return cl;
}
});
}
}

View File

@@ -0,0 +1,125 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
import com.sun.tools.internal.xjc.reader.internalizer.LocatorTable;
import com.sun.xml.internal.bind.marshaller.SAX2DOMEx;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import java.util.Set;
/**
* Builds DOM while keeping the location information.
*
* <p>
* This class also looks for outer most &lt;jaxws:bindings>
* customizations.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* Vivek Pandey
*/
class DOMBuilder extends SAX2DOMEx implements LexicalHandler {
/**
* Grows a DOM tree under the given document, and
* stores location information to the given table.
*
* @param outerMostBindings
* This set will receive newly found outermost
* jaxb:bindings customizations.
*/
public DOMBuilder( Document dom, LocatorTable ltable, Set outerMostBindings ) {
super( dom );
this.locatorTable = ltable;
this.outerMostBindings = outerMostBindings;
}
/** Location information will be stored into this object. */
private final LocatorTable locatorTable;
private final Set outerMostBindings;
private Locator locator;
public void setDocumentLocator(Locator locator) {
this.locator = locator;
super.setDocumentLocator(locator);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
super.startElement(namespaceURI, localName, qName, atts);
Element e = getCurrentElement();
locatorTable.storeStartLocation( e, locator );
// check if this element is an outer-most <jaxb:bindings>
if( JAXWSBindingsConstants.JAXWS_BINDINGS.getNamespaceURI().equals(e.getNamespaceURI())
&& "bindings".equals(e.getLocalName()) ) {
// if this is the root node (meaning that this file is an
// external binding file) or if the parent is XML Schema element
// (meaning that this is an "inlined" external binding)
Node p = e.getParentNode();
if( p instanceof Document) {
outerMostBindings.add(e); // remember this value
}
}
}
public void endElement(String namespaceURI, String localName, String qName) {
locatorTable.storeEndLocation( getCurrentElement(), locator );
super.endElement(namespaceURI, localName, qName);
}
public void startDTD(String name, String publicId, String systemId) throws SAXException {}
public void endDTD() throws SAXException {}
public void startEntity(String name) throws SAXException {}
public void endEntity(String name) throws SAXException {}
public void startCDATA() throws SAXException {}
public void endCDATA() throws SAXException {}
public void comment(char[] ch, int start, int length) throws SAXException {
//Element e = getCurrentElement(); // does not work as the comments at the top of the document would return Document Node
// instead of Element
Node parent = nodeStack.peek();
Comment comment = document.createComment(new String(ch,start,length));
parent.appendChild(comment);
}
}

View File

@@ -0,0 +1,385 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.istack.internal.NotNull;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
import com.sun.tools.internal.xjc.reader.internalizer.LocatorTable;
import com.sun.xml.internal.bind.marshaller.DataWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.ContentHandler;
import org.xml.sax.*;
import org.xml.sax.helpers.XMLFilterImpl;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.*;
import java.util.*;
/**
* @author Vivek Pandey
*/
public class DOMForest {
/**
* To correctly feed documents to a schema parser, we need to remember
* which documents (of the forest) were given as the root
* documents, and which of them are read as included/imported
* documents.
* <p/>
* <p/>
* Set of system ids as strings.
*/
protected final Set<String> rootDocuments = new HashSet<String>();
/**
* Contains wsdl:import(s)
*/
protected final Set<String> externalReferences = new HashSet<String>();
/**
* actual data storage map&lt;SystemId,Document>.
*/
protected final Map<String, Document> core = new HashMap<String, Document>();
protected final ErrorReceiver errorReceiver;
private final DocumentBuilder documentBuilder;
private final SAXParserFactory parserFactory;
/**
* inlined schema elements inside wsdl:type section
*/
protected final List<Element> inlinedSchemaElements = new ArrayList<Element>();
/**
* Stores location information for all the trees in this forest.
*/
public final LocatorTable locatorTable = new LocatorTable();
protected final EntityResolver entityResolver;
/**
* Stores all the outer-most &lt;jaxb:bindings> customizations.
*/
public final Set<Element> outerMostBindings = new HashSet<Element>();
/**
* Schema language dependent part of the processing.
*/
protected final InternalizationLogic logic;
protected final WsimportOptions options;
public DOMForest(InternalizationLogic logic, @NotNull EntityResolver entityResolver, WsimportOptions options, ErrorReceiver errReceiver) {
this.options = options;
this.entityResolver = entityResolver;
this.errorReceiver = errReceiver;
this.logic = logic;
// secure xml processing can be switched off if input requires it
boolean disableXmlSecurity = options == null ? false : options.disableXmlSecurity;
DocumentBuilderFactory dbf = XmlUtil.newDocumentBuilderFactory(disableXmlSecurity);
this.parserFactory = XmlUtil.newSAXParserFactory(disableXmlSecurity);
try {
this.documentBuilder = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new AssertionError(e);
}
}
public List<Element> getInlinedSchemaElement() {
return inlinedSchemaElements;
}
public @NotNull Document parse(InputSource source, boolean root) throws SAXException, IOException {
if (source.getSystemId() == null)
throw new IllegalArgumentException();
return parse(source.getSystemId(), source, root);
}
/**
* Parses an XML at the given location (
* and XMLs referenced by it) into DOM trees
* and stores them to this forest.
*
* @return the parsed DOM document object.
*/
public Document parse(String systemId, boolean root) throws SAXException, IOException{
systemId = normalizeSystemId(systemId);
InputSource is = null;
// allow entity resolver to find the actual byte stream.
is = entityResolver.resolveEntity(null, systemId);
if (is == null)
is = new InputSource(systemId);
else {
resolvedCache.put(systemId, is.getSystemId());
systemId=is.getSystemId();
}
if (core.containsKey(systemId)) {
// this document has already been parsed. Just ignore.
return core.get(systemId);
}
if(!root)
addExternalReferences(systemId);
// but we still use the original system Id as the key.
return parse(systemId, is, root);
}
protected Map<String,String> resolvedCache = new HashMap<String,String>();
public Map<String,String> getReferencedEntityMap() {
return resolvedCache;
}
/**
* Parses the given document and add it to the DOM forest.
*
* @return null if there was a parse error. otherwise non-null.
*/
private @NotNull Document parse(String systemId, InputSource inputSource, boolean root) throws SAXException, IOException{
Document dom = documentBuilder.newDocument();
systemId = normalizeSystemId(systemId);
// put into the map before growing a tree, to
// prevent recursive reference from causing infinite loop.
core.put(systemId, dom);
dom.setDocumentURI(systemId);
if (root)
rootDocuments.add(systemId);
try {
XMLReader reader = createReader(dom);
InputStream is = null;
if(inputSource.getByteStream() == null){
inputSource = entityResolver.resolveEntity(null, systemId);
}
reader.parse(inputSource);
Element doc = dom.getDocumentElement();
if (doc == null) {
return null;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
} catch (ParserConfigurationException e) {
errorReceiver.error(e);
throw new SAXException(e.getMessage());
}
resolvedCache.put(systemId, dom.getDocumentURI());
return dom;
}
public void addExternalReferences(String ref) {
if (!externalReferences.contains(ref))
externalReferences.add(ref);
}
public Set<String> getExternalReferences() {
return externalReferences;
}
public interface Handler extends ContentHandler {
/**
* Gets the DOM that was built.
*/
public Document getDocument();
}
/**
* Returns a {@link org.xml.sax.XMLReader} to parse a document into this DOM forest.
* <p/>
* This version requires that the DOM object to be created and registered
* to the map beforehand.
*/
private XMLReader createReader(Document dom) throws SAXException, ParserConfigurationException {
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
DOMBuilder dombuilder = new DOMBuilder(dom, locatorTable, outerMostBindings);
try {
reader.setProperty("http://xml.org/sax/properties/lexical-handler", dombuilder);
} catch(SAXException e) {
errorReceiver.debug(e.getMessage());
}
ContentHandler handler = new WhitespaceStripper(dombuilder, errorReceiver, entityResolver);
handler = new VersionChecker(handler, errorReceiver, entityResolver);
// insert the reference finder so that
// included/imported schemas will be also parsed
XMLFilterImpl f = logic.createExternalReferenceFinder(this);
f.setContentHandler(handler);
if (errorReceiver != null)
f.setErrorHandler(errorReceiver);
f.setEntityResolver(entityResolver);
reader.setContentHandler(f);
if (errorReceiver != null)
reader.setErrorHandler(errorReceiver);
reader.setEntityResolver(entityResolver);
return reader;
}
private String normalizeSystemId(String systemId) {
try {
systemId = new URI(systemId).normalize().toString();
} catch (URISyntaxException e) {
// leave the system ID untouched. In my experience URI is often too strict
}
return systemId;
}
boolean isExtensionMode() {
return options.isExtensionMode();
}
/**
* Gets the DOM tree associated with the specified system ID,
* or null if none is found.
*/
public Document get(String systemId) {
Document doc = core.get(systemId);
if (doc == null && systemId.startsWith("file:/") && !systemId.startsWith("file://")) {
// As of JDK1.4, java.net.URL.toExternal method returns URLs like
// "file:/abc/def/ghi" which is an incorrect file protocol URL according to RFC1738.
// Some other correctly functioning parts return the correct URLs ("file:///abc/def/ghi"),
// and this descripancy breaks DOM look up by system ID.
// this extra check solves this problem.
doc = core.get("file://" + systemId.substring(5));
}
if (doc == null && systemId.startsWith("file:")) {
// on Windows, filenames are case insensitive.
// perform case-insensitive search for improved user experience
String systemPath = getPath(systemId);
for (String key : core.keySet()) {
if (key.startsWith("file:") && getPath(key).equalsIgnoreCase(systemPath)) {
doc = core.get(key);
break;
}
}
}
return doc;
}
/**
* Strips off the leading 'file:///' portion from an URL.
*/
private String getPath(String key) {
key = key.substring(5); // skip 'file:'
while (key.length() > 0 && key.charAt(0) == '/')
key = key.substring(1);
return key;
}
/**
* Gets all the system IDs of the documents.
*/
public String[] listSystemIDs() {
return core.keySet().toArray(new String[core.keySet().size()]);
}
/**
* Gets the system ID from which the given DOM is parsed.
* <p/>
* Poor-man's base URI.
*/
public String getSystemId(Document dom) {
for (Map.Entry<String, Document> e : core.entrySet()) {
if (e.getValue() == dom)
return e.getKey();
}
return null;
}
/**
* Gets the first one (which is more or less random) in {@link #rootDocuments}.
*/
public String getFirstRootDocument() {
if(rootDocuments.isEmpty()) return null;
return rootDocuments.iterator().next();
}
public Set<String> getRootDocuments() {
return rootDocuments;
}
/**
* Dumps the contents of the forest to the specified stream.
* <p/>
* This is a debug method. As such, error handling is sloppy.
*/
public void dump(OutputStream out) throws IOException {
try {
// create identity transformer
// secure xml processing can be switched off if input requires it
boolean secureProcessingEnabled = options == null || !options.disableXmlSecurity;
TransformerFactory tf = XmlUtil.newTransformerFactory(secureProcessingEnabled);
Transformer it = tf.newTransformer();
for (Map.Entry<String, Document> e : core.entrySet()) {
out.write(("---<< " + e.getKey() + '\n').getBytes());
DataWriter dw = new DataWriter(new OutputStreamWriter(out), null);
dw.setIndentStep(" ");
it.transform(new DOMSource(e.getValue()),
new SAXResult(dw));
out.write("\n\n\n".getBytes());
}
} catch (TransformerException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import org.w3c.dom.Document;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.IOException;
import com.sun.xml.internal.xsom.parser.XMLParser;
/**
* {@link XMLParser} implementation that
* parses XML from a DOM forest instead of parsing it from
* its original location.
*
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* @author Vivek Pandey
*/
public class DOMForestParser implements XMLParser {
/**
* DOM forest to be "parsed".
*/
private final DOMForest forest;
/**
* Scanner object will do the actual SAX events generation.
*/
private final DOMForestScanner scanner;
private final XMLParser fallbackParser;
/**
* @param fallbackParser This parser will be used when DOMForestParser needs to parse
* documents that are not in the forest.
*/
public DOMForestParser(DOMForest forest, XMLParser fallbackParser) {
this.forest = forest;
this.scanner = new DOMForestScanner(forest);
this.fallbackParser = fallbackParser;
}
public void parse(InputSource source, ContentHandler handler, EntityResolver entityResolver, ErrorHandler errHandler) throws SAXException, IOException {
}
public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver)
throws SAXException, IOException {
String systemId = source.getSystemId();
Document dom = forest.get(systemId);
if (dom == null) {
// if no DOM tree is built for it,
// let the fall back parser parse the original document.
//
// for example, XSOM parses datatypes.xsd (XML Schema part 2)
// but this will never be built into the forest.
fallbackParser.parse(source, handler, errorHandler, entityResolver);
return;
}
scanner.scan(dom, handler);
}
}

View File

@@ -0,0 +1,176 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* Produces a complete series of SAX events from any DOM node
* in the DOMForest.
*
* <p>
* This class hides a logic of re-associating {@link org.xml.sax.Locator}
* to the generated SAX event stream.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class DOMForestScanner {
private final DOMForest forest;
/**
* Scans DOM nodes of the given forest.
*
* DOM node parameters to the scan method must be a part of
* this forest.
*/
public DOMForestScanner( DOMForest _forest ) {
this.forest = _forest;
}
/**
* Generates the whole set of SAX events by treating
* element e as if it's a root element.
*/
public void scan( Element e, ContentHandler contentHandler ) throws SAXException {
DOMScanner scanner = new DOMScanner();
// insert the location resolver into the pipe line
LocationResolver resolver = new LocationResolver(scanner);
resolver.setContentHandler(contentHandler);
// parse this DOM.
scanner.setContentHandler(resolver);
scanner.scan(e);
}
/**
* Generates the whole set of SAX events from the given Document
* in the DOMForest.
*/
public void scan( Document d, ContentHandler contentHandler ) throws SAXException {
scan( d.getDocumentElement(), contentHandler );
}
/**
* Intercepts the invocation of the setDocumentLocator method
* and passes itself as the locator.
*
* If the client calls one of the methods on the Locator interface,
* use the LocatorTable to resolve the source location.
*/
private class LocationResolver extends XMLFilterImpl implements Locator {
LocationResolver( DOMScanner _parent ) {
this.parent = _parent;
}
private final DOMScanner parent;
/**
* Flag that tells us whether we are processing a start element event
* or an end element event.
*
* DOMScanner's getCurrentLocation method doesn't tell us which, but
* this information is necessary to return the correct source line information.
*
* Thus we set this flag appropriately before we pass an event to
* the next ContentHandler, thereby making it possible to figure
* out which location to return.
*/
private boolean inStart = false;
public void setDocumentLocator(Locator locator) {
// ignore one set by the parent.
super.setDocumentLocator(this);
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
inStart = false;
super.endElement(namespaceURI, localName, qName);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
inStart = true;
super.startElement(namespaceURI, localName, qName, atts);
}
private Locator findLocator() {
Node n = parent.getCurrentLocation();
if( n instanceof Element ) {
Element e = (Element)n;
if( inStart )
return forest.locatorTable.getStartLocation( e );
else
return forest.locatorTable.getEndLocation( e );
}
return null;
}
//
//
// Locator methods
//
//
public int getColumnNumber() {
Locator l = findLocator();
if(l!=null) return l.getColumnNumber();
return -1;
}
public int getLineNumber() {
Locator l = findLocator();
if(l!=null) return l.getLineNumber();
return -1;
}
public String getPublicId() {
Locator l = findLocator();
if(l!=null) return l.getPublicId();
return null;
}
public String getSystemId() {
Locator l = findLocator();
if(l!=null) return l.getSystemId();
return null;
}
}
}

View File

@@ -0,0 +1,216 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wsdl.document.http.*;
import org.w3c.dom.Element;
import java.util.Map;
/**
* The HTTP extension handler for WSDL.
*
* @author WS Development Team
*/
public class HTTPExtensionHandler extends AbstractExtensionHandler {
public HTTPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
super(extensionHandlerMap);
}
public String getNamespaceURI() {
return Constants.NS_WSDL_HTTP;
}
public boolean handleDefinitionsExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
public boolean handleTypesExtension(
com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
public boolean handleBindingExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_BINDING)) {
context.push();
context.registerNamespaces(e);
HTTPBinding binding = new HTTPBinding(context.getLocation(e));
String verb = Util.getRequiredAttribute(e, Constants.ATTR_VERB);
binding.setVerb(verb);
parent.addExtension(binding);
context.pop();
// context.fireDoneParsingEntity(HTTPConstants.QNAME_BINDING, binding);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
public boolean handleOperationExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_OPERATION)) {
context.push();
context.registerNamespaces(e);
HTTPOperation operation = new HTTPOperation(context.getLocation(e));
String location =
Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
operation.setLocation(location);
parent.addExtension(operation);
context.pop();
// context.fireDoneParsingEntity(
// HTTPConstants.QNAME_OPERATION,
// operation);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
public boolean handleInputExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_URL_ENCODED)) {
parent.addExtension(new HTTPUrlEncoded(context.getLocation(e)));
return true;
} else if (
XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_URL_REPLACEMENT)) {
parent.addExtension(new HTTPUrlReplacement(context.getLocation(e)));
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
public boolean handleOutputExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
public boolean handleFaultExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
public boolean handleServiceExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
public boolean handlePortExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, HTTPConstants.QNAME_ADDRESS)) {
context.push();
context.registerNamespaces(e);
HTTPAddress address = new HTTPAddress(context.getLocation(e));
String location =
Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
address.setLocation(location);
parent.addExtension(address);
context.pop();
// context.fireDoneParsingEntity(HTTPConstants.QNAME_ADDRESS, address);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import org.w3c.dom.Element;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* Encapsulates schema-language dependent internalization logic.
*
* {@link com.sun.tools.internal.xjc.reader.internalizer.Internalizer} and {@link DOMForest} are responsible for
* doing schema language independent part, and this object is responsible
* for schema language dependent part.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* Vivek Pandey
*/
public interface InternalizationLogic {
/**
* Creates a new instance of XMLFilter that can be used to
* find references to external schemas.
*
* <p>
* Schemas that are included/imported need to be a part of
* {@link DOMForest}, and this filter will be expected to
* find such references.
*
* <p>
* Once such a reference is found, the filter is expected to
* call the parse method of DOMForest.
*
* <p>
* {@link DOMForest} will register ErrorHandler to the returned
* object, so any error should be sent to that error handler.
*
* @return
* This method returns {@link org.xml.sax.helpers.XMLFilterImpl} because
* the filter has to be usable for two directions
* (wrapping a reader and wrapping a ContentHandler)
*/
XMLFilterImpl createExternalReferenceFinder( DOMForest parent );
/**
* Checks if the specified element is a valid target node
* to attach a customization.
*
* @param parent
* The owner DOMForest object. Probably useful only
* to obtain context information, such as error handler.
* @param bindings
* &lt;jaxb:bindings> element or a customization element.
* @return
* true if it's OK, false if not.
*/
boolean checkIfValidTargetNode( DOMForest parent, Element bindings, Element target );
/**
* Prepares an element that actually receives customizations.
*
* <p>
* For example, in XML Schema, target nodes can be any schema
* element but it is always the &lt;xsd:appinfo> element that
* receives customization.
*
* @param target
* The target node designated by the customization.
* @return
* Always return non-null valid object
*/
Element refineSchemaTarget( Element target );
/**
* Prepares a WSDL element that actually receives customizations.
*
*
* @param target
* The target node designated by the customization.
* @return
* Always return non-null valid object
*/
Element refineWSDLTarget( Element target );
}

View File

@@ -0,0 +1,522 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.istack.internal.SAXParseException2;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
import com.sun.tools.internal.xjc.util.DOMUtils;
import com.sun.xml.internal.bind.v2.util.EditDistance;
import com.sun.xml.internal.ws.util.DOMUtil;
import com.sun.xml.internal.ws.util.JAXWSUtils;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.w3c.dom.*;
import org.xml.sax.SAXParseException;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Internalizes external binding declarations.
*
* @author Vivek Pandey
*/
public class Internalizer {
private final XPath xpath = xpf.get().newXPath();
private final DOMForest forest;
private final ErrorReceiver errorReceiver;
public Internalizer(DOMForest forest, WsimportOptions options, ErrorReceiver errorReceiver) {
this.forest = forest;
this.errorReceiver = errorReceiver;
}
public void transform() {
for (Element jaxwsBinding : forest.outerMostBindings) {
internalize(jaxwsBinding, jaxwsBinding);
}
}
private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
@Override
protected XPathFactory initialValue() throws Exception {
return XPathFactory.newInstance();
}
};
/**
* Validates attributes of a &lt;JAXWS:bindings> element.
*/
private void validate(Element bindings) {
NamedNodeMap atts = bindings.getAttributes();
for (int i = 0; i < atts.getLength(); i++) {
Attr a = (Attr) atts.item(i);
if (a.getNamespaceURI() != null) {
continue; // all foreign namespace OK.
}
if (a.getLocalName().equals("node")) {
continue;
}
if (a.getLocalName().equals("wsdlLocation")) {
continue;
}
// TODO: flag error for this undefined attribute
}
}
private void internalize(Element bindings, Node inheritedTarget) {
// start by the inherited target
Node target = inheritedTarget;
validate(bindings); // validate this node
// look for @wsdlLocation
if (isTopLevelBinding(bindings)) {
String wsdlLocation;
if (bindings.getAttributeNode("wsdlLocation") != null) {
wsdlLocation = bindings.getAttribute("wsdlLocation");
try {
// absolutize this URI.
// TODO: use the URI class
// TODO: honor xml:base
wsdlLocation = new URL(new URL(forest.getSystemId(bindings.getOwnerDocument())),
wsdlLocation).toExternalForm();
} catch (MalformedURLException e) {
wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
}
} else {
//the node does not have
wsdlLocation = forest.getFirstRootDocument();
}
target = forest.get(wsdlLocation);
if (target == null) {
reportError(bindings, WsdlMessages.INTERNALIZER_INCORRECT_SCHEMA_REFERENCE(wsdlLocation, EditDistance.findNearest(wsdlLocation, forest.listSystemIDs())));
return; // abort processing this <JAXWS:bindings>
}
}
//if the target node is xs:schema, declare the jaxb version on it as latter on it will be
//required by the inlined schema bindings
Element element = DOMUtil.getFirstElementChild(target);
if (element != null && element.getNamespaceURI().equals(Constants.NS_WSDL) && element.getLocalName().equals("definitions")) {
//get all schema elements
Element type = DOMUtils.getFirstChildElement(element, Constants.NS_WSDL, "types");
if (type != null) {
for (Element schemaElement : DOMUtils.getChildElements(type, Constants.NS_XSD, "schema")) {
if (!schemaElement.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) {
schemaElement.setAttributeNS(Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS);
}
//add jaxb:bindings version info. Lets put it to 1.0, may need to change latter
if (!schemaElement.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) {
schemaElement.setAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "jaxb:version", JAXWSBindingsConstants.JAXB_BINDING_VERSION);
}
}
}
}
NodeList targetNodes = null;
boolean hasNode = true;
boolean isToplevelBinding = isTopLevelBinding(bindings);
if ((isJAXWSBindings(bindings) || isJAXBBindings(bindings)) && bindings.getAttributeNode("node") != null) {
targetNodes = evaluateXPathMultiNode(bindings, target, bindings.getAttribute("node"), new NamespaceContextImpl(bindings));
} else
if (isJAXWSBindings(bindings) && (bindings.getAttributeNode("node") == null) && !isToplevelBinding) {
hasNode = false;
} else
if (isGlobalBinding(bindings) && !isWSDLDefinition(target) && isTopLevelBinding(bindings.getParentNode())) {
targetNodes = getWSDLDefintionNode(bindings, target);
}
//if target is null or empty it means the xpath evaluation has some problem,
// just return
if (targetNodes == null && hasNode && !isToplevelBinding) {
return;
}
if (hasNode) {
if (targetNodes != null) {
for (int i = 0; i < targetNodes.getLength(); i++) {
insertBinding(bindings, targetNodes.item(i));
// look for child <JAXWS:bindings> and process them recursively
Element[] children = getChildElements(bindings);
for (Element child : children) {
if ("bindings".equals(child.getLocalName())) {
internalize(child, targetNodes.item(i));
}
}
}
}
}
if (targetNodes == null) {
// look for child <JAXWS:bindings> and process them recursively
Element[] children = getChildElements(bindings);
for (Element child : children) {
internalize(child, target);
}
}
}
/**
* Moves JAXWS customizations under their respective target nodes.
*/
private void insertBinding(@NotNull Element bindings, @NotNull Node target) {
if ("bindings".equals(bindings.getLocalName())) {
Element[] children = DOMUtils.getChildElements(bindings);
for (Element item : children) {
if ("bindings".equals(item.getLocalName())) {
//done
} else {
moveUnder(item, (Element) target);
}
}
} else {
moveUnder(bindings, (Element) target);
}
}
private NodeList getWSDLDefintionNode(Node bindings, Node target) {
return evaluateXPathMultiNode(bindings, target, "wsdl:definitions",
new NamespaceContext() {
@Override
public String getNamespaceURI(String prefix) {
return "http://schemas.xmlsoap.org/wsdl/";
}
@Override
public String getPrefix(String nsURI) {
throw new UnsupportedOperationException();
}
@Override
public Iterator getPrefixes(String namespaceURI) {
throw new UnsupportedOperationException();
}
});
}
private boolean isWSDLDefinition(Node target) {
if (target == null) {
return false;
}
String localName = target.getLocalName();
String nsURI = target.getNamespaceURI();
return fixNull(localName).equals("definitions") && fixNull(nsURI).equals("http://schemas.xmlsoap.org/wsdl/");
}
private boolean isTopLevelBinding(Node node) {
return node.getOwnerDocument().getDocumentElement() == node;
}
private boolean isJAXWSBindings(Node bindings) {
return (bindings.getNamespaceURI().equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS) && bindings.getLocalName().equals("bindings"));
}
private boolean isJAXBBindings(Node bindings) {
return (bindings.getNamespaceURI().equals(JAXWSBindingsConstants.NS_JAXB_BINDINGS) && bindings.getLocalName().equals("bindings"));
}
private boolean isGlobalBinding(Node bindings) {
if (bindings.getNamespaceURI() == null) {
errorReceiver.warning(forest.locatorTable.getStartLocation((Element) bindings), WsdlMessages.INVALID_CUSTOMIZATION_NAMESPACE(bindings.getLocalName()));
return false;
}
return (bindings.getNamespaceURI().equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS) &&
(bindings.getLocalName().equals("package") ||
bindings.getLocalName().equals("enableAsyncMapping") ||
bindings.getLocalName().equals("enableAdditionalSOAPHeaderMapping") ||
bindings.getLocalName().equals("enableWrapperStyle") ||
bindings.getLocalName().equals("enableMIMEContent")));
}
private static Element[] getChildElements(Element parent) {
ArrayList<Element> a = new ArrayList<Element>();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node item = children.item(i);
if (!(item instanceof Element)) {
continue;
}
if (JAXWSBindingsConstants.NS_JAXWS_BINDINGS.equals(item.getNamespaceURI()) ||
JAXWSBindingsConstants.NS_JAXB_BINDINGS.equals(item.getNamespaceURI())) {
a.add((Element) item);
}
}
return a.toArray(new Element[a.size()]);
}
private NodeList evaluateXPathMultiNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
NodeList nlst;
try {
xpath.setNamespaceContext(namespaceContext);
nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATION_ERROR(e.getMessage()), e);
return null; // abort processing this <jaxb:bindings>
}
if (nlst.getLength() == 0) {
reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
return null; // abort
}
return nlst;
}
private boolean isJAXBBindingElement(Element e) {
return fixNull(e.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXB_BINDINGS);
}
private boolean isJAXWSBindingElement(Element e) {
return fixNull(e.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS);
}
/**
* Moves the "decl" node under the "target" node.
*
* @param decl A JAXWS customization element (e.g., &lt;JAXWS:class>)
* @param target XML wsdl element under which the declaration should move.
* For example, &lt;xs:element>
*/
private void moveUnder(Element decl, Element target) {
//if there is @node on decl and has a child element jaxb:bindings, move it under the target
//Element jaxb = getJAXBBindingElement(decl);
if (isJAXBBindingElement(decl)) {
//add jaxb namespace declaration
if (!target.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) {
target.setAttributeNS(Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS);
}
//add jaxb:bindings version info. Lets put it to 1.0, may need to change latter
if (!target.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) {
target.setAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "jaxb:version", JAXWSBindingsConstants.JAXB_BINDING_VERSION);
}
// HACK: allow XJC extension all the time. This allows people to specify
// the <xjc:someExtension> in the external bindings. Otherwise users lack the ability
// to specify jaxb:extensionBindingPrefixes, so it won't work.
//
// the current workaround is still problematic in the sense that
// it can't support user-defined extensions. This needs more careful thought.
//JAXB doesn't allow writing jaxb:extensionbindingPrefix anywhere other than root element so lets write only on <xs:schema>
if (target.getLocalName().equals("schema") && target.getNamespaceURI().equals(Constants.NS_XSD) && !target.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "extensionBindingPrefixes")) {
target.setAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "jaxb:extensionBindingPrefixes", "xjc");
target.setAttributeNS(Constants.NS_XMLNS, "xmlns:xjc", JAXWSBindingsConstants.NS_XJC_BINDINGS);
}
//insert xs:annotation/xs:appinfo where in jaxb:binding will be put
target = refineSchemaTarget(target);
copyInscopeNSAttributes(decl);
} else if (isJAXWSBindingElement(decl)) {
//add jaxb namespace declaration
if (!target.hasAttributeNS(Constants.NS_XMLNS, "JAXWS")) {
target.setAttributeNS(Constants.NS_XMLNS, "xmlns:JAXWS", JAXWSBindingsConstants.NS_JAXWS_BINDINGS);
}
//insert xs:annotation/xs:appinfo where in jaxb:binding will be put
target = refineWSDLTarget(target);
copyInscopeNSAttributes(decl);
} else {
return;
}
// finally move the declaration to the target node.
if (target.getOwnerDocument() != decl.getOwnerDocument()) {
// if they belong to different DOM documents, we need to clone them
decl = (Element) target.getOwnerDocument().importNode(decl, true);
}
target.appendChild(decl);
}
/**
* Copy in-scope namespace declarations of the decl node
* to the decl node itself so that this move won't change
* the in-scope namespace bindings.
*/
private void copyInscopeNSAttributes(Element e) {
Element p = e;
Set<String> inscopes = new HashSet<String>();
while (true) {
NamedNodeMap atts = p.getAttributes();
for (int i = 0; i < atts.getLength(); i++) {
Attr a = (Attr) atts.item(i);
if (Constants.NS_XMLNS.equals(a.getNamespaceURI())) {
String prefix;
if (a.getName().indexOf(':') == -1) {
prefix = "";
} else {
prefix = a.getLocalName();
}
if (inscopes.add(prefix) && p != e) {
// if this is the first time we see this namespace bindings,
// copy the declaration.
// if p==decl, there's no need to. Note that
// we want to add prefix to inscopes even if p==Decl
e.setAttributeNodeNS((Attr) a.cloneNode(true));
}
}
}
if (p.getParentNode() instanceof Document) {
break;
}
p = (Element) p.getParentNode();
}
if (!inscopes.contains("")) {
// if the default namespace was undeclared in the context of decl,
// it must be explicitly set to "" since the new environment might
// have a different default namespace URI.
e.setAttributeNS(Constants.NS_XMLNS, "xmlns", "");
}
}
public Element refineSchemaTarget(Element target) {
// look for existing xs:annotation
Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation");
if (annotation == null) {
// none exists. need to make one
annotation = insertXMLSchemaElement(target, "annotation");
}
// then look for appinfo
Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo");
if (appinfo == null) {
// none exists. need to make one
appinfo = insertXMLSchemaElement(annotation, "appinfo");
}
return appinfo;
}
public Element refineWSDLTarget(Element target) {
// look for existing xs:annotation
Element JAXWSBindings = DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings");
if (JAXWSBindings == null) {
// none exists. need to make one
JAXWSBindings = insertJAXWSBindingsElement(target, "bindings");
}
return JAXWSBindings;
}
/**
* Creates a new XML Schema element of the given local name
* and insert it as the first child of the given parent node.
*
* @return Newly create element.
*/
private Element insertXMLSchemaElement(Element parent, String localName) {
// use the same prefix as the parent node to avoid modifying
// the namespace binding.
String qname = parent.getTagName();
int idx = qname.indexOf(':');
if (idx == -1) {
qname = localName;
} else {
qname = qname.substring(0, idx + 1) + localName;
}
Element child = parent.getOwnerDocument().createElementNS(Constants.NS_XSD, qname);
NodeList children = parent.getChildNodes();
if (children.getLength() == 0) {
parent.appendChild(child);
} else {
parent.insertBefore(child, children.item(0));
}
return child;
}
private Element insertJAXWSBindingsElement(Element parent, String localName) {
String qname = "JAXWS:" + localName;
Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname);
NodeList children = parent.getChildNodes();
if (children.getLength() == 0) {
parent.appendChild(child);
} else {
parent.insertBefore(child, children.item(0));
}
return child;
}
@NotNull
static String fixNull(@Nullable String s) {
if (s == null) {
return "";
} else {
return s;
}
}
private void reportError(Element errorSource, String formattedMsg) {
reportError(errorSource, formattedMsg, null);
}
private void reportError(Element errorSource,
String formattedMsg, Exception nestedException) {
SAXParseException e = new SAXParseException2(formattedMsg,
forest.locatorTable.getStartLocation(errorSource),
nestedException);
errorReceiver.error(e);
}
}

View File

@@ -0,0 +1,661 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wsdl.document.*;
import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
import com.sun.tools.internal.ws.wsdl.document.jaxws.Parameter;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.xpath.*;
import java.util.Iterator;
import java.util.Map;
/**
* @author Vivek Pandey
*
* jaxws:bindings exension handler.
*
*/
public class JAXWSBindingExtensionHandler extends AbstractExtensionHandler {
// xml security enabled always, xpath used for parsing "part" attribute
private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
@Override
protected XPathFactory initialValue() throws Exception {
return XPathFactory.newInstance();
}
};
private final XPath xpath = xpf.get().newXPath();
public JAXWSBindingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
super(extensionHandlerMap);
}
/* (non-Javadoc)
* @see AbstractExtensionHandler#getNamespaceURI()
*/
@Override
public String getNamespaceURI() {
return JAXWSBindingsConstants.NS_JAXWS_BINDINGS;
}
/**
* @param context
* @param parent
* @param e
*/
private boolean parseGlobalJAXWSBindings(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = getJAXWSExtension(parent);
if(jaxwsBinding == null) {
jaxwsBinding = new JAXWSBinding(context.getLocation(e));
}
String attr = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.WSDL_LOCATION_ATTR);
if (attr != null) {
jaxwsBinding.setWsdlLocation(attr);
}
attr = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NODE_ATTR);
if (attr != null) {
jaxwsBinding.setNode(attr);
}
attr = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.VERSION_ATTR);
if (attr != null) {
jaxwsBinding.setVersion(attr);
}
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.PACKAGE)) {
parsePackage(context, jaxwsBinding, e2);
if ((jaxwsBinding.getJaxwsPackage() != null) && (jaxwsBinding.getJaxwsPackage().getJavaDoc() != null)) {
((Definitions) parent).setDocumentation(new Documentation(jaxwsBinding.getJaxwsPackage().getJavaDoc()));
}
} else if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_WRAPPER_STYLE)) {
parseWrapperStyle(context, jaxwsBinding, e2);
} else if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ASYNC_MAPPING)) {
parseAsynMapping(context, jaxwsBinding, e2);
} // else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ADDITIONAL_SOAPHEADER_MAPPING)){
// parseAdditionalSOAPHeaderMapping(context, jaxwsBinding, e2);
// }
else if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_MIME_CONTENT)) {
parseMimeContent(context, jaxwsBinding, e2);
} else {
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}
private static JAXWSBinding getJAXWSExtension(TWSDLExtensible extensible) {
for (TWSDLExtension extension:extensible.extensions()) {
if (extension.getClass().equals(JAXWSBinding.class)) {
return (JAXWSBinding)extension;
}
}
return null;
}
/**
* @param context
* @param parent
* @param e
*/
private void parseProvider(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding parent, Element e) {
String val = e.getTextContent();
if (val == null) {
return;
}
if (val.equals("false") || val.equals("0")) {
((JAXWSBinding)parent).setProvider(Boolean.FALSE);
} else if(val.equals("true") || val.equals("1")) {
((JAXWSBinding)parent).setProvider(Boolean.TRUE);
}
}
/**
* @param context
* @param parent
* @param e
*/
private void parsePackage(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding parent, Element e) {
//System.out.println("In handlePackageExtension: " + e.getNodeName());
String packageName = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);
JAXWSBinding binding = (JAXWSBinding)parent;
binding.setJaxwsPackage(new CustomName(packageName, getJavaDoc(e)));
}
/**
* @param context
* @param parent
* @param e
*/
private void parseWrapperStyle(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding parent, Element e) {
//System.out.println("In handleWrapperStyleExtension: " + e.getNodeName());
String val = e.getTextContent();
if (val == null) {
return;
}
if (val.equals("false") || val.equals("0")) {
((JAXWSBinding) parent).setEnableWrapperStyle(Boolean.FALSE);
} else if (val.equals("true") || val.equals("1")) {
((JAXWSBinding) parent).setEnableWrapperStyle(Boolean.TRUE);
}
}
/**
* @param context
* @param parent
* @param e
*/
// private void parseAdditionalSOAPHeaderMapping(TWSDLParserContextImpl context, TWSDLExtensible parent, Element e) {
// //System.out.println("In handleAdditionalSOAPHeaderExtension: " + e.getNodeName());
// String val = e.getTextContent();
// if(val == null)
// return;
// if(val.equals("false") || val.equals("0")){
// ((JAXWSBinding)parent).setEnableAdditionalHeaderMapping(Boolean.FALSE);
// }else if(val.equals("true") || val.equals("1")){
// ((JAXWSBinding)parent).setEnableAdditionalHeaderMapping(Boolean.TRUE);
// }
// }
/**
* @param context
* @param parent
* @param e
*/
private void parseAsynMapping(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding parent, Element e) {
//System.out.println("In handleAsynMappingExtension: " + e.getNodeName());
String val = e.getTextContent();
if (val == null) {
return;
}
if (val.equals("false") || val.equals("0")) {
((JAXWSBinding) parent).setEnableAsyncMapping(Boolean.FALSE);
} else if (val.equals("true") || val.equals("1")) {
((JAXWSBinding) parent).setEnableAsyncMapping(Boolean.TRUE);
}
}
/**
* @param context
* @param parent
* @param e
*/
private void parseMimeContent(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding parent, Element e) {
//System.out.println("In handleMimeContentExtension: " + e.getNodeName());
String val = e.getTextContent();
if (val == null) {
return;
}
if (val.equals("false") || val.equals("0")) {
((JAXWSBinding) parent).setEnableMimeContentMapping(Boolean.FALSE);
} else if (val.equals("true") || val.equals("1")) {
((JAXWSBinding) parent).setEnableMimeContentMapping(Boolean.TRUE);
}
}
/**
* @param context
* @param jaxwsBinding
* @param e
*/
private void parseMethod(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
String methodName = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);
String javaDoc = getJavaDoc(e);
CustomName name = new CustomName(methodName, javaDoc);
jaxwsBinding.setMethodName(name);
}
/**
* @param context
* @param jaxwsBinding
* @param e
*/
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
Node msgElm = msgPartElm.getParentNode();
//MessagePart msgPart = new MessagePart();
String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
if ((partName == null) || (msgName == null)) {
return;
}
String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);
QName elementName = null;
if(element != null){
String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
}
jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
private Element evaluateXPathNode(Node target, String expression, NamespaceContext namespaceContext) {
NodeList nlst;
try {
xpath.setNamespaceContext(namespaceContext);
nlst = (NodeList)xpath.evaluate(expression, target, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
Util.fail("internalizer.XPathEvaluationError", e.getMessage());
return null; // abort processing this <jaxb:bindings>
}
if( nlst.getLength()==0 ) {
Util.fail("internalizer.XPathEvaluatesToNoTarget", new Object[]{expression});
return null; // abort
}
if( nlst.getLength()!=1 ) {
Util.fail("internalizer.XPathEvaulatesToTooManyTargets", new Object[]{expression, nlst.getLength()});
return null; // abort
}
Node rnode = nlst.item(0);
if(!(rnode instanceof Element )) {
Util.fail("internalizer.XPathEvaluatesToNonElement", new Object[]{expression});
return null; // abort
}
return (Element)rnode;
}
/**
* @param context
* @param jaxwsBinding
* @param e
*/
private void parseClass(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
String className = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);
String javaDoc = getJavaDoc(e);
jaxwsBinding.setClassName(new CustomName(className, javaDoc));
}
@Override
public boolean handleDefinitionsExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return parseGlobalJAXWSBindings(context, parent, e);
}
@Override
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_WRAPPER_STYLE)) {
parseWrapperStyle(context, jaxwsBinding, e2);
} else if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ASYNC_MAPPING)) {
parseAsynMapping(context, jaxwsBinding, e2);
} else if (XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.CLASS)) {
parseClass(context, jaxwsBinding, e2);
if ((jaxwsBinding.getClassName() != null) && (jaxwsBinding.getClassName().getJavaDoc() != null) && (parent instanceof PortType)) {
((PortType) parent).setDocumentation(new Documentation(jaxwsBinding.getClassName().getJavaDoc()));
}
} else {
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
@Override
public boolean handleOperationExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
if(parent instanceof Operation){
return handlePortTypeOperation(context, (Operation)parent, e);
}else if(parent instanceof BindingOperation){
return handleBindingOperation(context, (BindingOperation)parent, e);
}
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
return false;
}
private boolean handleBindingOperation(TWSDLParserContext context, BindingOperation operation, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
// if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ADDITIONAL_SOAPHEADER_MAPPING)){
// parseAdditionalSOAPHeaderMapping(context, jaxwsBinding, e2);
// }else
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_MIME_CONTENT)){
parseMimeContent(context, jaxwsBinding, e2);
}else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.PARAMETER)){
parseParameter(context, jaxwsBinding, e2);
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
operation.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
private boolean handlePortTypeOperation(TWSDLParserContext context, Operation parent, Element e) {
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_WRAPPER_STYLE)){
parseWrapperStyle(context, jaxwsBinding, e2);
}else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ASYNC_MAPPING)){
parseAsynMapping(context, jaxwsBinding, e2);
}else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.METHOD)){
parseMethod(context, jaxwsBinding, e2);
if((jaxwsBinding.getMethodName() != null) && (jaxwsBinding.getMethodName().getJavaDoc() != null)){
parent.setDocumentation(new Documentation(jaxwsBinding.getMethodName().getJavaDoc()));
}
}else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.PARAMETER)){
parseParameter(context, jaxwsBinding, e2);
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}
@Override
public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
// if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_ADDITIONAL_SOAPHEADER_MAPPING)){
// parseAdditionalSOAPHeaderMapping(context, jaxwsBinding, e2);
// }else
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.ENABLE_MIME_CONTENT)){
parseMimeContent(context, jaxwsBinding, e2);
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
/* (non-Javadoc)
* @see ExtensionHandlerBase#handleFaultExtension(TWSDLParserContextImpl, TWSDLExtensible, org.w3c.dom.Element)
*/
@Override
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.CLASS)){
parseClass(context, jaxwsBinding, e2);
if((jaxwsBinding.getClassName() != null) && (jaxwsBinding.getClassName().getJavaDoc() != null)){
((Fault)parent).setDocumentation(new Documentation(jaxwsBinding.getClassName().getJavaDoc()));
}
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
@Override
public boolean handleServiceExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.CLASS)){
parseClass(context, jaxwsBinding, e2);
if((jaxwsBinding.getClassName() != null) && (jaxwsBinding.getClassName().getJavaDoc() != null)){
((Service)parent).setDocumentation(new Documentation(jaxwsBinding.getClassName().getJavaDoc()));
}
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
@Override
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if(XmlUtil.matchesTagNS(e, JAXWSBindingsConstants.JAXWS_BINDINGS)){
context.push();
context.registerNamespaces(e);
JAXWSBinding jaxwsBinding = new JAXWSBinding(context.getLocation(e));
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.PROVIDER)){
parseProvider(context, jaxwsBinding, e2);
}else if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.METHOD)){
parseMethod(context, jaxwsBinding, e2);
if((jaxwsBinding.getMethodName() != null) && (jaxwsBinding.getMethodName().getJavaDoc() != null)){
((Port)parent).setDocumentation(new Documentation(jaxwsBinding.getMethodName().getJavaDoc()));
}
}else{
Util.fail(
"parsing.invalidExtensionElement",
e2.getTagName(),
e2.getNamespaceURI());
return false;
}
}
parent.addExtension(jaxwsBinding);
context.pop();
// context.fireDoneParsingEntity(
// JAXWSBindingsConstants.JAXWS_BINDINGS,
// jaxwsBinding);
return true;
}else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false;
}
}
private String getJavaDoc(Element e){
for(Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();){
Element e2 = Util.nextElement(iter);
if (e2 == null) {
break;
}
if(XmlUtil.matchesTagNS(e2, JAXWSBindingsConstants.JAVADOC)){
return XmlUtil.getTextForNode(e2);
}
}
return null;
}
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
import com.sun.tools.internal.ws.wsdl.document.mime.*;
import org.w3c.dom.Element;
import java.util.Iterator;
import java.util.Map;
/**
* The MIME extension handler for WSDL.
*
* @author WS Development Team
*/
public class MIMEExtensionHandler extends AbstractExtensionHandler {
public MIMEExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
super(extensionHandlerMap);
}
public String getNamespaceURI() {
return Constants.NS_WSDL_MIME;
}
@Override
public boolean doHandleExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_OUTPUT)) {
return handleInputOutputExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_INPUT)) {
return handleInputOutputExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(MIMEConstants.QNAME_PART)) {
return handleMIMEPartExtension(context, parent, e);
} else {
// context.fireIgnoringExtension(
// new QName(e.getNamespaceURI(), e.getLocalName()),
// parent.getWSDLElementName());
return false;
}
}
protected boolean handleInputOutputExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MULTIPART_RELATED)) {
context.push();
context.registerNamespaces(e);
MIMEMultipartRelated mpr = new MIMEMultipartRelated(context.getLocation(e));
for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
Element e2 = Util.nextElement(iter);
if (e2 == null)
break;
if (XmlUtil.matchesTagNS(e2, MIMEConstants.QNAME_PART)) {
context.push();
context.registerNamespaces(e2);
MIMEPart part = new MIMEPart(context.getLocation(e2));
String name =
XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAME);
if (name != null) {
part.setName(name);
}
for (Iterator iter2 = XmlUtil.getAllChildren(e2);
iter2.hasNext();
) {
Element e3 = Util.nextElement(iter2);
if (e3 == null)
break;
AbstractExtensionHandler h = getExtensionHandlers().get(e3.getNamespaceURI());
boolean handled = false;
if (h != null) {
handled = h.doHandleExtension(context, part, e3);
}
if (!handled) {
String required =
XmlUtil.getAttributeNSOrNull(
e3,
Constants.ATTR_REQUIRED,
Constants.NS_WSDL);
if (required != null
&& required.equals(Constants.TRUE)) {
Util.fail(
"parsing.requiredExtensibilityElement",
e3.getTagName(),
e3.getNamespaceURI());
} else {
// context.fireIgnoringExtension(
// new QName(
// e3.getNamespaceURI(),
// e3.getLocalName()),
// part.getElementName());
}
}
}
mpr.add(part);
context.pop();
// context.fireDoneParsingEntity(
// MIMEConstants.QNAME_PART,
// part);
} else {
Util.fail(
"parsing.invalidElement",
e2.getTagName(),
e2.getNamespaceURI());
}
}
parent.addExtension(mpr);
context.pop();
// context.fireDoneParsingEntity(
// MIMEConstants.QNAME_MULTIPART_RELATED,
// mpr);
return true;
} else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
MIMEContent content = parseMIMEContent(context, e);
parent.addExtension(content);
return true;
} else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
MIMEXml mimeXml = parseMIMEXml(context, e);
parent.addExtension(mimeXml);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
@Override
protected boolean handleMIMEPartExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_CONTENT)) {
MIMEContent content = parseMIMEContent(context, e);
parent.addExtension(content);
return true;
} else if (XmlUtil.matchesTagNS(e, MIMEConstants.QNAME_MIME_XML)) {
MIMEXml mimeXml = parseMIMEXml(context, e);
parent.addExtension(mimeXml);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
protected MIMEContent parseMIMEContent(TWSDLParserContext context, Element e) {
context.push();
context.registerNamespaces(e);
MIMEContent content = new MIMEContent(context.getLocation(e));
String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
if (part != null) {
content.setPart(part);
}
String type = XmlUtil.getAttributeOrNull(e, Constants.ATTR_TYPE);
if (type != null) {
content.setType(type);
}
context.pop();
// context.fireDoneParsingEntity(MIMEConstants.QNAME_CONTENT, content);
return content;
}
protected MIMEXml parseMIMEXml(TWSDLParserContext context, Element e) {
context.push();
context.registerNamespaces(e);
MIMEXml mimeXml = new MIMEXml(context.getLocation(e));
String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
if (part != null) {
mimeXml.setPart(part);
}
context.pop();
// context.fireDoneParsingEntity(MIMEConstants.QNAME_MIME_XML, mimeXml);
return mimeXml;
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.resources.ModelerMessages;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wsdl.document.Fault;
import com.sun.tools.internal.ws.wsdl.document.Input;
import com.sun.tools.internal.ws.wsdl.document.Output;
import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
import javax.xml.namespace.QName;
import java.util.Map;
import static com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants.WSA_ACTION_QNAME;
/**
* @author Arun Gupta
*/
public class MemberSubmissionAddressingExtensionHandler extends W3CAddressingExtensionHandler {
private ErrorReceiver errReceiver;
private boolean extensionModeOn;
public MemberSubmissionAddressingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap, ErrorReceiver env, boolean extensionModeOn) {
super(extensionHandlerMap, env);
this.errReceiver = env;
this.extensionModeOn = extensionModeOn;
}
@Override
public String getNamespaceURI() {
return AddressingVersion.MEMBER.wsdlNsUri;
}
protected QName getWSDLExtensionQName() {
return AddressingVersion.MEMBER.wsdlExtensionTag;
}
@Override
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
// ignore any extension elements
return false;
}
@Override
public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (extensionModeOn) {
warn(context.getLocation(e));
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSA_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
return warnEmptyAction(parent, context.getLocation(e));
}
((Input) parent).setAction(actionValue);
return true;
} else {
return fail(context.getLocation(e));
}
}
private boolean fail(Locator location) {
errReceiver.warning(location,
ModelerMessages.WSDLMODELER_INVALID_IGNORING_MEMBER_SUBMISSION_ADDRESSING(
AddressingVersion.MEMBER.nsUri, W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME));
return false;
}
private void warn(Locator location) {
errReceiver.warning(location,
ModelerMessages.WSDLMODELER_WARNING_MEMBER_SUBMISSION_ADDRESSING_USED(
AddressingVersion.MEMBER.nsUri, W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME));
}
@Override
public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (extensionModeOn) {
warn(context.getLocation(e));
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSA_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
return warnEmptyAction(parent, context.getLocation(e));
}
((Output) parent).setAction(actionValue);
return true;
} else {
return fail(context.getLocation(e));
}
}
@Override
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (extensionModeOn) {
warn(context.getLocation(e));
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSA_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
errReceiver.warning(context.getLocation(e), WsdlMessages.WARNING_FAULT_EMPTY_ACTION(parent.getNameValue(), parent.getWSDLElementName().getLocalPart(), parent.getParent().getNameValue()));
return false; // keep compiler happy
}
((Fault) parent).setAction(actionValue);
return true;
} else {
return fail(context.getLocation(e));
}
}
private boolean warnEmptyAction(TWSDLExtensible parent, Locator pos) {
errReceiver.warning(pos, WsdlMessages.WARNING_INPUT_OUTPUT_EMPTY_ACTION(parent.getWSDLElementName().getLocalPart(), parent.getParent().getNameValue()));
return false;
}
}

View File

@@ -0,0 +1,384 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.tools.internal.ws.resources.WscompileMessages;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.wscompile.AbortException;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
import com.sun.tools.internal.ws.wsdl.framework.ParseException;
import com.sun.xml.internal.ws.api.wsdl.parser.MetaDataResolver;
import com.sun.xml.internal.ws.api.wsdl.parser.MetadataResolverFactory;
import com.sun.xml.internal.ws.api.wsdl.parser.ServiceDescriptor;
import com.sun.xml.internal.ws.util.DOMUtil;
import com.sun.xml.internal.ws.util.JAXWSUtils;
import com.sun.xml.internal.ws.util.ServiceFinder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.*;
/**
* @author Vivek Pandey
*/
public final class MetadataFinder extends DOMForest{
public boolean isMexMetadata;
private String rootWSDL;
private final Set<String> rootWsdls = new HashSet<String>();
public MetadataFinder(InternalizationLogic logic, WsimportOptions options, ErrorReceiver errReceiver) {
super(logic, new WSEntityResolver(options,errReceiver), options, errReceiver);
}
@SuppressWarnings("element-type-mismatch")
public void parseWSDL(){
// parse source grammars
for (InputSource value : options.getWSDLs()) {
String systemID = value.getSystemId();
errorReceiver.pollAbort();
Document dom;
Element doc;
try {
//if there is entity resolver use it
if (options.entityResolver != null) {
value = options.entityResolver.resolveEntity(null, systemID);
}
if (value == null) {
value = new InputSource(systemID);
}
dom = parse(value, true);
doc = dom.getDocumentElement();
if (doc == null) {
continue;
}
//if its not a WSDL document, retry with MEX
if (doc.getNamespaceURI() == null || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL) || !doc.getLocalName().equals("definitions")) {
throw new SAXParseException(WsdlMessages.INVALID_WSDL(systemID,
com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS, doc.getNodeName(), locatorTable.getStartLocation(doc).getLineNumber()), locatorTable.getStartLocation(doc));
}
} catch (FileNotFoundException e) {
errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e);
return;
} catch (IOException e) {
doc = getFromMetadataResolver(systemID, e);
} catch (SAXParseException e) {
doc = getFromMetadataResolver(systemID, e);
} catch (SAXException e) {
doc = getFromMetadataResolver(systemID, e);
}
if (doc == null) {
continue;
}
NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
for (int i = 0; i < schemas.getLength(); i++) {
if (!inlinedSchemaElements.contains(schemas.item(i))) {
inlinedSchemaElements.add((Element) schemas.item(i));
}
}
}
identifyRootWsdls();
}
public static class WSEntityResolver implements EntityResolver {
WsimportOptions options;
ErrorReceiver errorReceiver;
private URLConnection c = null;
private boolean doReset = false;
public WSEntityResolver(WsimportOptions options, ErrorReceiver errReceiver) {
this.options = options;
this.errorReceiver = errReceiver;
}
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
InputSource inputSource = null;
if(options.entityResolver != null ) {
inputSource = options.entityResolver.resolveEntity(null, systemId);
}
if (inputSource == null) {
inputSource = new InputSource(systemId);
InputStream is = null;
int redirects = 0;
boolean redirect;
URL url = JAXWSUtils.getFileOrURL(inputSource.getSystemId());
URLConnection conn = url.openConnection();
do {
if (conn instanceof HttpsURLConnection) {
if (options.disableSSLHostnameVerification) {
((HttpsURLConnection) conn).setHostnameVerifier(new HttpClientVerifier());
}
}
redirect = false;
if (conn instanceof HttpURLConnection) {
((HttpURLConnection) conn).setInstanceFollowRedirects(false);
}
if (conn instanceof JarURLConnection) {
if (conn.getUseCaches()) {
doReset = true;
conn.setDefaultUseCaches(false);
c = conn;
}
}
try {
is = conn.getInputStream();
//is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn);
} catch (IOException e) {
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = ((HttpURLConnection) conn);
int code = httpConn.getResponseCode();
if (code == 401) {
errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(e.getMessage(),
systemId, WsimportOptions.defaultAuthfile), null, e));
throw new AbortException();
}
//FOR other code we will retry with MEX
}
throw e;
}
//handle 302 or 303, JDK does not seem to handle 302 very well.
//Need to redesign this a bit as we need to throw better error message for IOException in this case
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = ((HttpURLConnection) conn);
int code = httpConn.getResponseCode();
if (code == 302 || code == 303) {
//retry with the value in Location header
List<String> seeOther = httpConn.getHeaderFields().get("Location");
if (seeOther != null && seeOther.size() > 0) {
URL newurl = new URL(url, seeOther.get(0));
if (!newurl.equals(url)) {
errorReceiver.info(new SAXParseException(WscompileMessages.WSIMPORT_HTTP_REDIRECT(code, seeOther.get(0)), null));
url = newurl;
httpConn.disconnect();
if (redirects >= 5) {
errorReceiver.error(new SAXParseException(WscompileMessages.WSIMPORT_MAX_REDIRECT_ATTEMPT(), null));
throw new AbortException();
}
conn = url.openConnection();
inputSource.setSystemId(url.toExternalForm());
redirects++;
redirect = true;
}
}
}
}
} while (redirect);
inputSource.setByteStream(is);
}
return inputSource;
}
@Override
protected void finalize() throws Throwable {
//see http://java.net/jira/browse/JAX_WS-1087
if (doReset) {
c.setDefaultUseCaches(true);
}
}
}
// overide default SSL HttpClientVerifier to always return true
// effectively overiding Hostname client verification when using SSL
private static class HttpClientVerifier implements HostnameVerifier {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}
/**
* Gives the root wsdl document systemId. A root wsdl document is the one which has wsdl:service.
* @return null if there is no root wsdl
*/
public @Nullable
String getRootWSDL(){
return rootWSDL;
}
/**
* Gives all the WSDL documents.
*/
public @NotNull
Set<String> getRootWSDLs(){
return rootWsdls;
}
/**
* Identifies WSDL documents from the {@link DOMForest}. Also identifies the root wsdl document.
*/
private void identifyRootWsdls(){
for(String location: rootDocuments){
Document doc = get(location);
if(doc!=null){
Element definition = doc.getDocumentElement();
if(definition == null || definition.getLocalName() == null || definition.getNamespaceURI() == null)
continue;
if(definition.getNamespaceURI().equals(WSDLConstants.NS_WSDL) && definition.getLocalName().equals("definitions")){
rootWsdls.add(location);
//set the root wsdl at this point. Root wsdl is one which has wsdl:service in it
NodeList nl = definition.getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");
//TODO:what if there are more than one wsdl with wsdl:service element. Probably such cases
//are rare and we will take any one of them, this logic should still work
if(nl.getLength() > 0)
rootWSDL = location;
}
}
}
//no wsdl with wsdl:service found, throw error
if(rootWSDL == null){
StringBuilder strbuf = new StringBuilder();
for(String str : rootWsdls){
strbuf.append(str);
strbuf.append('\n');
}
errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString()));
}
}
/*
* If source and target namespace are also passed in,
* then if the mex resolver is found and it cannot get
* the data, wsimport attempts to add ?wsdl to the
* address and retrieve the data with a normal http get.
* This behavior should only happen when trying a
* mex request first.
*/
private @Nullable Element getFromMetadataResolver(String systemId, Exception ex) {
//try MEX
MetaDataResolver resolver;
ServiceDescriptor serviceDescriptor = null;
for (MetadataResolverFactory resolverFactory : ServiceFinder.find(MetadataResolverFactory.class)) {
resolver = resolverFactory.metadataResolver(options.entityResolver);
try {
serviceDescriptor = resolver.resolve(new URI(systemId));
//we got the ServiceDescriptor, now break
if (serviceDescriptor != null)
break;
} catch (URISyntaxException e) {
throw new ParseException(e);
}
}
if (serviceDescriptor != null) {
errorReceiver.warning(new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
return parseMetadata(systemId, serviceDescriptor);
} else {
errorReceiver.error(null, WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)), ex);
}
return null;
}
private Element parseMetadata(@NotNull String systemId, @NotNull ServiceDescriptor serviceDescriptor) {
List<? extends Source> mexWsdls = serviceDescriptor.getWSDLs();
List<? extends Source> mexSchemas = serviceDescriptor.getSchemas();
Document root = null;
for (Source src : mexWsdls) {
if (src instanceof DOMSource) {
Node n = ((DOMSource) src).getNode();
Document doc;
if (n.getNodeType() == Node.ELEMENT_NODE && n.getOwnerDocument() == null) {
doc = DOMUtil.createDom();
doc.importNode(n, true);
} else {
doc = n.getOwnerDocument();
}
// Element e = (n.getNodeType() == Node.ELEMENT_NODE)?(Element)n: DOMUtil.getFirstElementChild(n);
if (root == null) {
//check if its main wsdl, then set it to root
NodeList nl = doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");
if (nl.getLength() > 0) {
root = doc;
rootWSDL = src.getSystemId();
}
}
NodeList nl = doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "import");
for(int i = 0; i < nl.getLength(); i++){
Element imp = (Element) nl.item(i);
String loc = imp.getAttribute("location");
if (loc != null) {
if (!externalReferences.contains(loc))
externalReferences.add(loc);
}
}
if (core.keySet().contains(systemId))
core.remove(systemId);
core.put(src.getSystemId(), doc);
resolvedCache.put(systemId, doc.getDocumentURI());
isMexMetadata = true;
}
//TODO:handle SAXSource
//TODO:handler StreamSource
}
for (Source src : mexSchemas) {
if (src instanceof DOMSource) {
Node n = ((DOMSource) src).getNode();
Element e = (n.getNodeType() == Node.ELEMENT_NODE) ? (Element) n : DOMUtil.getFirstElementChild(n);
inlinedSchemaElements.add(e);
}
//TODO:handle SAXSource
//TODO:handler StreamSource
}
return root.getDocumentElement();
}
}

View File

@@ -0,0 +1,99 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import javax.xml.namespace.NamespaceContext;
import java.util.Iterator;
public class NamespaceContextImpl implements NamespaceContext {
private final Element e;
public NamespaceContextImpl(Element e) {
this.e = e;
}
public String getNamespaceURI(String prefix) {
Node parent = e;
String namespace = null;
if (prefix.equals("xml")) {
namespace = WellKnownNamespace.XML_NAMESPACE_URI;
} else {
int type;
while ((null != parent) && (null == namespace)
&& (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
|| (type == Node.ENTITY_REFERENCE_NODE))) {
if (type == Node.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix + ':') == 0)
return parent.getNamespaceURI();
NamedNodeMap nnm = parent.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
public String getPrefix(String namespaceURI) {
throw new UnsupportedOperationException();
}
public Iterator getPrefixes(String namespaceURI) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
import org.w3c.dom.Element;
/**
* Policies are evaluated at runtime. This class makes sure that wscompile/wsimport
* ignores all policy elements at tooltime.
*
* @author Jakub Podlesak (jakub.podlesak at sun.com)
* @author Fabian Ritzmann
*/
public class Policy12ExtensionHandler extends TWSDLExtensionHandler {
@Override
public String getNamespaceURI() {
return NamespaceVersion.v1_2.toString();
}
@Override
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleDefinitionsExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleOperationExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleServiceExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
/**
* Only skip the element if it is a <wsp:Policy/>, <wsp:PolicyReference/> or
* <wsp:UsingPolicy> element.
*/
private boolean handleExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return XmlUtil.matchesTagNS(e, NamespaceVersion.v1_2.asQName(XmlToken.Policy))
|| XmlUtil.matchesTagNS(e,NamespaceVersion.v1_2.asQName(XmlToken.PolicyReference))
|| XmlUtil.matchesTagNS(e, NamespaceVersion.v1_2.asQName(XmlToken.UsingPolicy));
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
import org.w3c.dom.Element;
/**
* Policies are evaluated at runtime. This class makes sure that wscompile/wsimport
* ignores all policy elements at tooltime.
*
* @author Jakub Podlesak (jakub.podlesak at sun.com)
* @author Fabian Ritzmann
*/
public class Policy15ExtensionHandler extends TWSDLExtensionHandler {
@Override
public String getNamespaceURI() {
return NamespaceVersion.v1_5.toString();
}
@Override
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleDefinitionsExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleOperationExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handleServiceExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
@Override
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleExtension(context, parent, e);
}
/**
* Only skip the element if it is a <wsp:Policy/>, <wsp:PolicyReference/> or
* <wsp:UsingPolicy> element.
*/
private boolean handleExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return XmlUtil.matchesTagNS(e, NamespaceVersion.v1_5.asQName(XmlToken.Policy))
|| XmlUtil.matchesTagNS(e,NamespaceVersion.v1_5.asQName(XmlToken.PolicyReference))
|| XmlUtil.matchesTagNS(e, NamespaceVersion.v1_5.asQName(XmlToken.UsingPolicy));
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Binding;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Constants;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
import org.xml.sax.Locator;
import javax.xml.namespace.QName;
import java.util.Map;
public class SOAP12ExtensionHandler extends SOAPExtensionHandler {
public SOAP12ExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
super(extensionHandlerMap);
}
/*
* @see SOAPExtensionHandler#getNamespaceURI()
*/
@Override
public String getNamespaceURI() {
return Constants.NS_WSDL_SOAP12;
}
/*
* @see SOAPExtensionHandler#getAddressQName()
*/
@Override
protected QName getAddressQName() {
return SOAP12Constants.QNAME_ADDRESS;
}
/*
* @see SOAPExtensionHandler#getBindingQName()
*/
@Override
protected QName getBindingQName() {
return SOAP12Constants.QNAME_BINDING;
}
@Override protected SOAPBinding getSOAPBinding(Locator location) {
return new SOAP12Binding(location);
}
/*
* @see SOAPExtensionHandler#getBodyQName()
*/
@Override
protected QName getBodyQName() {
return SOAP12Constants.QNAME_BODY;
}
/*
* @see SOAPExtensionHandler#getFaultQName()
*/
@Override
protected QName getFaultQName() {
return SOAP12Constants.QNAME_FAULT;
}
/*
* @see SOAPExtensionHandler#getHeaderfaultQName()
*/
@Override
protected QName getHeaderfaultQName() {
return SOAP12Constants.QNAME_HEADERFAULT;
}
/*
* @see SOAPExtensionHandler#getHeaderQName()
*/
@Override
protected QName getHeaderQName() {
return SOAP12Constants.QNAME_HEADER;
}
/*
* @see SOAPExtensionHandler#getOperationQName()
*/
@Override
protected QName getOperationQName() {
return SOAP12Constants.QNAME_OPERATION;
}
}

View File

@@ -0,0 +1,217 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPConstants;
import com.sun.tools.internal.ws.wsdl.framework.EntityReferenceValidator;
import com.sun.tools.internal.ws.wsdl.framework.Kind;
import javax.xml.namespace.QName;
import java.util.HashSet;
import java.util.Set;
/**
* An interface implemented by a class that is capable of validating
* a QName/Kind pair referring to an external entity.
*
* @author WS Development Team
*/
public class SOAPEntityReferenceValidator implements EntityReferenceValidator {
public SOAPEntityReferenceValidator() {
}
public boolean isValid(Kind kind, QName name) {
// just let all "xml:" QNames through
if (name.getNamespaceURI().equals(Constants.NS_XML))
return true;
if (kind == SchemaKinds.XSD_TYPE) {
return _validTypes.contains(name);
} else if (kind == SchemaKinds.XSD_ELEMENT) {
return _validElements.contains(name);
} else if (kind == SchemaKinds.XSD_ATTRIBUTE) {
return _validAttributes.contains(name);
} else {
// no luck
return false;
}
}
private static final Set _validTypes;
private static final Set _validElements;
private static final Set _validAttributes;
static {
// add all XML Schema and SOAP types
_validTypes = new HashSet();
_validTypes.add(SOAPConstants.QNAME_TYPE_ARRAY);
_validTypes.add(SchemaConstants.QNAME_TYPE_STRING);
_validTypes.add(SchemaConstants.QNAME_TYPE_NORMALIZED_STRING);
_validTypes.add(SchemaConstants.QNAME_TYPE_TOKEN);
_validTypes.add(SchemaConstants.QNAME_TYPE_BYTE);
_validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_BYTE);
_validTypes.add(SchemaConstants.QNAME_TYPE_BASE64_BINARY);
_validTypes.add(SchemaConstants.QNAME_TYPE_HEX_BINARY);
_validTypes.add(SchemaConstants.QNAME_TYPE_INTEGER);
_validTypes.add(SchemaConstants.QNAME_TYPE_POSITIVE_INTEGER);
_validTypes.add(SchemaConstants.QNAME_TYPE_NEGATIVE_INTEGER);
_validTypes.add(SchemaConstants.QNAME_TYPE_NON_NEGATIVE_INTEGER);
_validTypes.add(SchemaConstants.QNAME_TYPE_NON_POSITIVE_INTEGER);
_validTypes.add(SchemaConstants.QNAME_TYPE_INT);
_validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_INT);
_validTypes.add(SchemaConstants.QNAME_TYPE_LONG);
_validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_LONG);
_validTypes.add(SchemaConstants.QNAME_TYPE_SHORT);
_validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_SHORT);
_validTypes.add(SchemaConstants.QNAME_TYPE_DECIMAL);
_validTypes.add(SchemaConstants.QNAME_TYPE_FLOAT);
_validTypes.add(SchemaConstants.QNAME_TYPE_DOUBLE);
_validTypes.add(SchemaConstants.QNAME_TYPE_BOOLEAN);
_validTypes.add(SchemaConstants.QNAME_TYPE_TIME);
_validTypes.add(SchemaConstants.QNAME_TYPE_DATE_TIME);
_validTypes.add(SchemaConstants.QNAME_TYPE_DURATION);
_validTypes.add(SchemaConstants.QNAME_TYPE_DATE);
_validTypes.add(SchemaConstants.QNAME_TYPE_G_MONTH);
_validTypes.add(SchemaConstants.QNAME_TYPE_G_YEAR);
_validTypes.add(SchemaConstants.QNAME_TYPE_G_YEAR_MONTH);
_validTypes.add(SchemaConstants.QNAME_TYPE_G_DAY);
_validTypes.add(SchemaConstants.QNAME_TYPE_G_MONTH_DAY);
_validTypes.add(SchemaConstants.QNAME_TYPE_NAME);
_validTypes.add(SchemaConstants.QNAME_TYPE_QNAME);
_validTypes.add(SchemaConstants.QNAME_TYPE_NCNAME);
_validTypes.add(SchemaConstants.QNAME_TYPE_ANY_URI);
_validTypes.add(SchemaConstants.QNAME_TYPE_ID);
_validTypes.add(SchemaConstants.QNAME_TYPE_IDREF);
_validTypes.add(SchemaConstants.QNAME_TYPE_IDREFS);
_validTypes.add(SchemaConstants.QNAME_TYPE_ENTITY);
_validTypes.add(SchemaConstants.QNAME_TYPE_ENTITIES);
_validTypes.add(SchemaConstants.QNAME_TYPE_NOTATION);
_validTypes.add(SchemaConstants.QNAME_TYPE_NMTOKEN);
_validTypes.add(SchemaConstants.QNAME_TYPE_NMTOKENS);
_validTypes.add(SchemaConstants.QNAME_TYPE_URTYPE);
_validTypes.add(SchemaConstants.QNAME_TYPE_SIMPLE_URTYPE);
_validTypes.add(SOAPConstants.QNAME_TYPE_STRING);
_validTypes.add(SOAPConstants.QNAME_TYPE_NORMALIZED_STRING);
_validTypes.add(SOAPConstants.QNAME_TYPE_TOKEN);
_validTypes.add(SOAPConstants.QNAME_TYPE_BYTE);
_validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_BYTE);
_validTypes.add(SOAPConstants.QNAME_TYPE_BASE64_BINARY);
_validTypes.add(SOAPConstants.QNAME_TYPE_HEX_BINARY);
_validTypes.add(SOAPConstants.QNAME_TYPE_INTEGER);
_validTypes.add(SOAPConstants.QNAME_TYPE_POSITIVE_INTEGER);
_validTypes.add(SOAPConstants.QNAME_TYPE_NEGATIVE_INTEGER);
_validTypes.add(SOAPConstants.QNAME_TYPE_NON_NEGATIVE_INTEGER);
_validTypes.add(SOAPConstants.QNAME_TYPE_NON_POSITIVE_INTEGER);
_validTypes.add(SOAPConstants.QNAME_TYPE_INT);
_validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_INT);
_validTypes.add(SOAPConstants.QNAME_TYPE_LONG);
_validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_LONG);
_validTypes.add(SOAPConstants.QNAME_TYPE_SHORT);
_validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_SHORT);
_validTypes.add(SOAPConstants.QNAME_TYPE_DECIMAL);
_validTypes.add(SOAPConstants.QNAME_TYPE_FLOAT);
_validTypes.add(SOAPConstants.QNAME_TYPE_DOUBLE);
_validTypes.add(SOAPConstants.QNAME_TYPE_BOOLEAN);
_validTypes.add(SOAPConstants.QNAME_TYPE_TIME);
_validTypes.add(SOAPConstants.QNAME_TYPE_DATE_TIME);
_validTypes.add(SOAPConstants.QNAME_TYPE_DURATION);
_validTypes.add(SOAPConstants.QNAME_TYPE_DATE);
_validTypes.add(SOAPConstants.QNAME_TYPE_G_MONTH);
_validTypes.add(SOAPConstants.QNAME_TYPE_G_YEAR);
_validTypes.add(SOAPConstants.QNAME_TYPE_G_YEAR_MONTH);
_validTypes.add(SOAPConstants.QNAME_TYPE_G_DAY);
_validTypes.add(SOAPConstants.QNAME_TYPE_G_MONTH_DAY);
_validTypes.add(SOAPConstants.QNAME_TYPE_NAME);
_validTypes.add(SOAPConstants.QNAME_TYPE_QNAME);
_validTypes.add(SOAPConstants.QNAME_TYPE_NCNAME);
_validTypes.add(SOAPConstants.QNAME_TYPE_ANY_URI);
_validTypes.add(SOAPConstants.QNAME_TYPE_ID);
_validTypes.add(SOAPConstants.QNAME_TYPE_IDREF);
_validTypes.add(SOAPConstants.QNAME_TYPE_IDREFS);
_validTypes.add(SOAPConstants.QNAME_TYPE_ENTITY);
_validTypes.add(SOAPConstants.QNAME_TYPE_ENTITIES);
_validTypes.add(SOAPConstants.QNAME_TYPE_NOTATION);
_validTypes.add(SOAPConstants.QNAME_TYPE_NMTOKEN);
_validTypes.add(SOAPConstants.QNAME_TYPE_NMTOKENS);
_validTypes.add(SOAPConstants.QNAME_TYPE_BASE64);
// New types 12/3/02
_validTypes.add(SchemaConstants.QNAME_TYPE_LANGUAGE);
// add all SOAP encoding elements
_validElements = new HashSet();
_validElements.add(SOAPConstants.QNAME_ELEMENT_STRING);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NORMALIZED_STRING);
_validElements.add(SOAPConstants.QNAME_ELEMENT_TOKEN);
_validElements.add(SOAPConstants.QNAME_ELEMENT_BYTE);
_validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_BYTE);
_validElements.add(SOAPConstants.QNAME_ELEMENT_BASE64_BINARY);
_validElements.add(SOAPConstants.QNAME_ELEMENT_HEX_BINARY);
_validElements.add(SOAPConstants.QNAME_ELEMENT_INTEGER);
_validElements.add(SOAPConstants.QNAME_ELEMENT_POSITIVE_INTEGER);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NEGATIVE_INTEGER);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NON_NEGATIVE_INTEGER);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NON_POSITIVE_INTEGER);
_validElements.add(SOAPConstants.QNAME_ELEMENT_INT);
_validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_INT);
_validElements.add(SOAPConstants.QNAME_ELEMENT_LONG);
_validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_LONG);
_validElements.add(SOAPConstants.QNAME_ELEMENT_SHORT);
_validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_SHORT);
_validElements.add(SOAPConstants.QNAME_ELEMENT_DECIMAL);
_validElements.add(SOAPConstants.QNAME_ELEMENT_FLOAT);
_validElements.add(SOAPConstants.QNAME_ELEMENT_DOUBLE);
_validElements.add(SOAPConstants.QNAME_ELEMENT_BOOLEAN);
_validElements.add(SOAPConstants.QNAME_ELEMENT_TIME);
_validElements.add(SOAPConstants.QNAME_ELEMENT_DATE_TIME);
_validElements.add(SOAPConstants.QNAME_ELEMENT_DURATION);
_validElements.add(SOAPConstants.QNAME_ELEMENT_DATE);
_validElements.add(SOAPConstants.QNAME_ELEMENT_G_MONTH);
_validElements.add(SOAPConstants.QNAME_ELEMENT_G_YEAR);
_validElements.add(SOAPConstants.QNAME_ELEMENT_G_YEAR_MONTH);
_validElements.add(SOAPConstants.QNAME_ELEMENT_G_DAY);
_validElements.add(SOAPConstants.QNAME_ELEMENT_G_MONTH_DAY);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NAME);
_validElements.add(SOAPConstants.QNAME_ELEMENT_QNAME);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NCNAME);
_validElements.add(SOAPConstants.QNAME_ELEMENT_ANY_URI);
_validElements.add(SOAPConstants.QNAME_ELEMENT_ID);
_validElements.add(SOAPConstants.QNAME_ELEMENT_IDREF);
_validElements.add(SOAPConstants.QNAME_ELEMENT_IDREFS);
_validElements.add(SOAPConstants.QNAME_ELEMENT_ENTITY);
_validElements.add(SOAPConstants.QNAME_ELEMENT_ENTITIES);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NOTATION);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NMTOKEN);
_validElements.add(SOAPConstants.QNAME_ELEMENT_NMTOKENS);
_validAttributes = new HashSet();
_validAttributes.add(SOAPConstants.QNAME_ATTR_ARRAY_TYPE);
_validAttributes.add(SOAPConstants.QNAME_ATTR_OFFSET);
_validAttributes.add(SOAPConstants.QNAME_ATTR_POSITION);
}
}

View File

@@ -0,0 +1,471 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wsdl.document.soap.*;
import com.sun.tools.internal.ws.wsdl.framework.TWSDLParserContextImpl;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
import javax.xml.namespace.QName;
import java.util.Iterator;
import java.util.Map;
/**
* The SOAP extension handler for WSDL.
*
* @author WS Development Team
*/
public class SOAPExtensionHandler extends AbstractExtensionHandler {
public SOAPExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
super(extensionHandlerMap);
}
public String getNamespaceURI() {
return Constants.NS_WSDL_SOAP;
}
public boolean handleDefinitionsExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
public boolean handleTypesExtension(
com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
protected SOAPBinding getSOAPBinding(Locator location){
return new SOAPBinding(location);
}
public boolean handleBindingExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, getBindingQName())) {
context.push();
context.registerNamespaces(e);
SOAPBinding binding = getSOAPBinding(context.getLocation(e));
// NOTE - the "transport" attribute is required according to section 3.3 of the WSDL 1.1 spec,
// but optional according to the schema in appendix A 4.2 of the same document!
String transport =
Util.getRequiredAttribute(e, Constants.ATTR_TRANSPORT);
binding.setTransport(transport);
String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
if (style != null) {
if (style.equals(Constants.ATTRVALUE_RPC)) {
binding.setStyle(SOAPStyle.RPC);
} else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
binding.setStyle(SOAPStyle.DOCUMENT);
} else {
Util.fail(
"parsing.invalidAttributeValue",
Constants.ATTR_STYLE,
style);
}
}
parent.addExtension(binding);
context.pop();
// context.fireDoneParsingEntity(getBindingQName(), binding);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
public boolean handleOperationExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, getOperationQName())) {
context.push();
context.registerNamespaces(e);
SOAPOperation operation = new SOAPOperation(context.getLocation(e));
String soapAction =
XmlUtil.getAttributeOrNull(e, Constants.ATTR_SOAP_ACTION);
if (soapAction != null) {
operation.setSOAPAction(soapAction);
}
String style = XmlUtil.getAttributeOrNull(e, Constants.ATTR_STYLE);
if (style != null) {
if (style.equals(Constants.ATTRVALUE_RPC)) {
operation.setStyle(SOAPStyle.RPC);
} else if (style.equals(Constants.ATTRVALUE_DOCUMENT)) {
operation.setStyle(SOAPStyle.DOCUMENT);
} else {
Util.fail(
"parsing.invalidAttributeValue",
Constants.ATTR_STYLE,
style);
}
}
parent.addExtension(operation);
context.pop();
// context.fireDoneParsingEntity(
// getOperationQName(),
// operation);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
public boolean handleInputExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
return handleInputOutputExtension(context, parent, e);
}
public boolean handleOutputExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
return handleInputOutputExtension(context, parent, e);
}
@Override
protected boolean handleMIMEPartExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
return handleInputOutputExtension(context, parent, e);
}
protected boolean handleInputOutputExtension(
TWSDLParserContext contextif,
TWSDLExtensible parent,
Element e) {
TWSDLParserContextImpl context = (TWSDLParserContextImpl)contextif;
if (XmlUtil.matchesTagNS(e, getBodyQName())) {
context.push();
context.registerNamespaces(e);
SOAPBody body = new SOAPBody(context.getLocation(e));
String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
if (use != null) {
if (use.equals(Constants.ATTRVALUE_LITERAL)) {
body.setUse(SOAPUse.LITERAL);
} else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
body.setUse(SOAPUse.ENCODED);
} else {
Util.fail(
"parsing.invalidAttributeValue",
Constants.ATTR_USE,
use);
}
}
String namespace =
XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
if (namespace != null) {
body.setNamespace(namespace);
}
String encodingStyle =
XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
if (encodingStyle != null) {
body.setEncodingStyle(encodingStyle);
}
String parts = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PARTS);
if (parts != null) {
body.setParts(parts);
}
parent.addExtension(body);
context.pop();
// context.fireDoneParsingEntity(getBodyQName(), body);
return true;
} else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
return handleHeaderElement(parent, e, context);
} else {
Util.fail("parsing.invalidExtensionElement", e.getTagName(), e.getNamespaceURI());
return false; // keep compiler happy
}
}
private boolean handleHeaderElement(TWSDLExtensible parent, Element e, TWSDLParserContextImpl context) {
context.push();
context.registerNamespaces(e);
SOAPHeader header = new SOAPHeader(context.getLocation(e));
String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
if (use != null) {
if (use.equals(Constants.ATTRVALUE_LITERAL)) {
header.setUse(SOAPUse.LITERAL);
} else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
header.setUse(SOAPUse.ENCODED);
} else {
Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use);
}
}
String namespace = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
if (namespace != null) {
header.setNamespace(namespace);
}
String encodingStyle = XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
if (encodingStyle != null) {
header.setEncodingStyle(encodingStyle);
}
String part = XmlUtil.getAttributeOrNull(e, Constants.ATTR_PART);
if (part != null) {
header.setPart(part);
}
String messageAttr = XmlUtil.getAttributeOrNull(e, Constants.ATTR_MESSAGE);
if (messageAttr != null) {
header.setMessage(context.translateQualifiedName(context.getLocation(e), messageAttr));
}
for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
Element e2 = Util.nextElement(iter);
if (e2 == null)
break;
if (XmlUtil.matchesTagNS(e2, getHeaderfaultQName())) {
handleHeaderFaultElement(e, context, header, use, e2);
} else {
Util.fail("parsing.invalidElement", e2.getTagName(), e2.getNamespaceURI());
}
}
parent.addExtension(header);
context.pop();
context.fireDoneParsingEntity(getHeaderQName(), header);
return true;
}
private void handleHeaderFaultElement(Element e, TWSDLParserContextImpl context, SOAPHeader header, String use, Element e2) {
context.push();
context.registerNamespaces(e);
SOAPHeaderFault headerfault = new SOAPHeaderFault(context.getLocation(e));
String use2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_USE);
if (use2 != null) {
if (use2.equals(Constants.ATTRVALUE_LITERAL)) {
headerfault.setUse(SOAPUse.LITERAL);
} else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
headerfault.setUse(SOAPUse.ENCODED);
} else {
Util.fail("parsing.invalidAttributeValue", Constants.ATTR_USE, use2);
}
}
String namespace2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_NAMESPACE);
if (namespace2 != null) {
headerfault.setNamespace(namespace2);
}
String encodingStyle2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_ENCODING_STYLE);
if (encodingStyle2 != null) {
headerfault.setEncodingStyle(encodingStyle2);
}
String part2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_PART);
if (part2 != null) {
headerfault.setPart(part2);
}
String messageAttr2 = XmlUtil.getAttributeOrNull(e2, Constants.ATTR_MESSAGE);
if (messageAttr2 != null) {
headerfault.setMessage(
context.translateQualifiedName(context.getLocation(e2), messageAttr2));
}
header.add(headerfault);
context.pop();
}
public boolean handleFaultExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, getFaultQName())) {
context.push();
context.registerNamespaces(e);
SOAPFault fault = new SOAPFault(context.getLocation(e));
String name = XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAME);
if (name != null) {
fault.setName(name);
}
String use = XmlUtil.getAttributeOrNull(e, Constants.ATTR_USE);
if (use != null) {
if (use.equals(Constants.ATTRVALUE_LITERAL)) {
fault.setUse(SOAPUse.LITERAL);
} else if (use.equals(Constants.ATTRVALUE_ENCODED)) {
fault.setUse(SOAPUse.ENCODED);
} else {
Util.fail(
"parsing.invalidAttributeValue",
Constants.ATTR_USE,
use);
}
}
String namespace =
XmlUtil.getAttributeOrNull(e, Constants.ATTR_NAMESPACE);
if (namespace != null) {
fault.setNamespace(namespace);
}
String encodingStyle =
XmlUtil.getAttributeOrNull(e, Constants.ATTR_ENCODING_STYLE);
if (encodingStyle != null) {
fault.setEncodingStyle(encodingStyle);
}
parent.addExtension(fault);
context.pop();
// context.fireDoneParsingEntity(getFaultQName(), fault);
return true;
} else if (XmlUtil.matchesTagNS(e, getHeaderQName())) {
// although SOAP spec doesn't define meaning of this extension; it is allowed
// to be here, so we have to accept it, not fail (bug 13576977)
return handleHeaderElement(parent, e, (TWSDLParserContextImpl) context);
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
public boolean handleServiceExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
@Override
public boolean handlePortExtension(
TWSDLParserContext context,
TWSDLExtensible parent,
Element e) {
if (XmlUtil.matchesTagNS(e, getAddressQName())) {
context.push();
context.registerNamespaces(e);
SOAPAddress address = new SOAPAddress(context.getLocation(e));
String location =
Util.getRequiredAttribute(e, Constants.ATTR_LOCATION);
address.setLocation(location);
parent.addExtension(address);
context.pop();
// context.fireDoneParsingEntity(getAddressQName(), address);
return true;
} else {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
}
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
Util.fail(
"parsing.invalidExtensionElement",
e.getTagName(),
e.getNamespaceURI());
return false; // keep compiler happy
}
protected QName getBodyQName(){
return SOAPConstants.QNAME_BODY;
}
protected QName getHeaderQName(){
return SOAPConstants.QNAME_HEADER;
}
protected QName getHeaderfaultQName(){
return SOAPConstants.QNAME_HEADERFAULT;
}
protected QName getOperationQName(){
return SOAPConstants.QNAME_OPERATION;
}
protected QName getFaultQName(){
return SOAPConstants.QNAME_FAULT;
}
protected QName getAddressQName(){
return SOAPConstants.QNAME_ADDRESS;
}
protected QName getBindingQName(){
return SOAPConstants.QNAME_BINDING;
}
}

View File

@@ -0,0 +1,181 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wsdl.framework.ParseException;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.w3c.dom.Comment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import javax.xml.namespace.QName;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
/**2
* Defines various utility methods.
*
* @author WS Development Team
*/
public class Util {
public static String getRequiredAttribute(Element element, String name) {
String result = XmlUtil.getAttributeOrNull(element, name);
if (result == null)
fail(
"parsing.missingRequiredAttribute",
element.getTagName(),
name);
return result;
}
public static void verifyTag(Element element, String tag) {
if (!element.getLocalName().equals(tag))
fail("parsing.invalidTag", element.getTagName(), tag);
}
public static void verifyTagNS(Element element, String tag, String nsURI) {
if (!element.getLocalName().equals(tag)
|| (element.getNamespaceURI() != null
&& !element.getNamespaceURI().equals(nsURI)))
fail(
"parsing.invalidTagNS",
new Object[] {
element.getTagName(),
element.getNamespaceURI(),
tag,
nsURI });
}
public static void verifyTagNS(Element element, QName name) {
if (!isTagName(element, name))
fail(
"parsing.invalidTagNS",
new Object[] {
element.getTagName(),
element.getNamespaceURI(),
name.getLocalPart(),
name.getNamespaceURI()});
}
public static boolean isTagName(Element element, QName name){
return (element.getLocalName().equals(name.getLocalPart())
&& (element.getNamespaceURI() != null
&& element.getNamespaceURI().equals(name.getNamespaceURI())));
}
public static void verifyTagNSRootElement(Element element, QName name) {
if (!element.getLocalName().equals(name.getLocalPart())
|| (element.getNamespaceURI() != null
&& !element.getNamespaceURI().equals(name.getNamespaceURI())))
fail(
"parsing.incorrectRootElement",
new Object[] {
element.getTagName(),
element.getNamespaceURI(),
name.getLocalPart(),
name.getNamespaceURI()});
}
public static Element nextElementIgnoringCharacterContent(Iterator iter) {
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (n instanceof Text)
continue;
if (n instanceof Comment)
continue;
if (!(n instanceof Element))
fail("parsing.elementExpected");
return (Element) n;
}
return null;
}
public static Element nextElement(Iterator iter) {
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (n instanceof Text) {
Text t = (Text) n;
if (t.getData().trim().length() == 0)
continue;
fail("parsing.nonWhitespaceTextFound", t.getData().trim());
}
if (n instanceof Comment)
continue;
if (!(n instanceof Element))
fail("parsing.elementExpected");
return (Element) n;
}
return null;
}
public static String processSystemIdWithBase(
String baseSystemId,
String systemId) {
try {
URL base = null;
try {
base = new URL(baseSystemId);
} catch (MalformedURLException e) {
base = new File(baseSystemId).toURL();
}
try {
URL url = new URL(base, systemId);
return url.toString();
} catch (MalformedURLException e) {
fail("parsing.invalidURI", systemId);
}
} catch (MalformedURLException e) {
fail("parsing.invalidURI", baseSystemId);
}
return null; // keep compiler happy
}
public static void fail(String key) {
throw new ParseException(key);
}
public static void fail(String key, String arg) {
throw new ParseException(key, arg);
}
public static void fail(String key, String arg1, String arg2) {
throw new ParseException(key, new Object[] { arg1, arg2 });
}
public static void fail(String key, Object[] args) {
throw new ParseException(key, args);
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
import org.xml.sax.*;
import org.xml.sax.helpers.LocatorImpl;
import org.xml.sax.helpers.XMLFilterImpl;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Checks the jaxb:version attribute on a XML Schema document.
*
* jaxws:version is optional, if absent its value is assumed to be "2.0" and if present its value must be
* "2.0" or more.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* Vivek Pandey
*/
public class VersionChecker extends XMLFilterImpl {
/**
* We store the value of the version attribute in this variable
* when we hit the root element.
*/
private String version = null ;
/** Will be set to true once we hit the root element. */
private boolean seenRoot = false;
/** Will be set to true once we hit a binding declaration. */
private boolean seenBindings = false;
private Locator locator;
/**
* Stores the location of the start tag of the root tag.
*/
private Locator rootTagStart;
public VersionChecker( XMLReader parent ) {
setParent(parent);
}
public VersionChecker( ContentHandler handler, ErrorHandler eh, EntityResolver er ) {
setContentHandler(handler);
if(eh!=null) setErrorHandler(eh);
if(er!=null) setEntityResolver(er);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException {
super.startElement(namespaceURI, localName, qName, atts);
if(!seenRoot) {
// if this is the root element
seenRoot = true;
rootTagStart = new LocatorImpl(locator);
version = atts.getValue(JAXWSBindingsConstants.NS_JAXWS_BINDINGS,"version");
if( namespaceURI.equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS) ) {
String version2 = atts.getValue("","version");
if( version!=null && version2!=null ) {
// we have both @version and @jaxb:version. error.
SAXParseException e = new SAXParseException(
WsdlMessages.INTERNALIZER_TWO_VERSION_ATTRIBUTES(), locator);
getErrorHandler().error(e);
}
//According to JAXWS 2.0 spec, if version attribute is missing its assumed to be "2.0"
if( version==null)
version = (version2!=null)?version2:"2.0";
}
}
if( JAXWSBindingsConstants.NS_JAXWS_BINDINGS.equals(namespaceURI)){
seenBindings = true;
if(version == null)
version = "2.0";
}
}
public void endDocument() throws SAXException {
super.endDocument();
if( seenBindings && version==null ) {
// if we see a binding declaration but not version attribute
SAXParseException e = new SAXParseException(WsdlMessages.INTERNALIZER_VERSION_NOT_PRESENT(), rootTagStart);
getErrorHandler().error(e);
}
// if present, the value must be >= 2.0
if( version!=null && !VERSIONS.contains(version) ) {
SAXParseException e = new SAXParseException(WsdlMessages.INTERNALIZER_INCORRECT_VERSION(), rootTagStart);
getErrorHandler().error(e);
}
}
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
this.locator = locator;
}
private static final Set<String> VERSIONS = new HashSet<String>(Arrays.asList("2.0","2.1"));
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wsdl.document.Fault;
import com.sun.tools.internal.ws.wsdl.document.Input;
import com.sun.tools.internal.ws.wsdl.document.Output;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
import javax.xml.namespace.QName;
import java.util.Map;
/**
* @author Arun Gupta
*/
public class W3CAddressingExtensionHandler extends AbstractExtensionHandler {
public W3CAddressingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
this(extensionHandlerMap, null);
}
public W3CAddressingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap, ErrorReceiver errReceiver) {
super(extensionHandlerMap);
}
@Override
public String getNamespaceURI() {
return AddressingVersion.W3C.wsdlNsUri;
}
protected QName getWSDLExtensionQName() {
return AddressingVersion.W3C.wsdlExtensionTag;
}
@Override
public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (XmlUtil.matchesTagNS(e, getWSDLExtensionQName())) {
/*
context.push();
context.registerNamespaces(e);
// TODO: read UsingAddressing extensibility element and store
// TODO: it as extension in "parent". It may be used to generate
// TODO: @Action/@FaultAction later.
context.pop();
*/
return true;
}
return false; // keep compiler happy
}
@Override
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return handleBindingExtension(context, parent, e);
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.util.xml.XmlUtil;
import com.sun.tools.internal.ws.wsdl.document.Input;
import com.sun.tools.internal.ws.wsdl.document.Output;
import com.sun.tools.internal.ws.wsdl.document.Fault;
import com.sun.tools.internal.ws.resources.WsdlMessages;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import static com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants.*;
import java.util.Map;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
/**
* This extension parses the WSDL Metadata extensibility elements in the wsdl definitions.
*
* This class looks for wsam:Action attribute on wsdl:input, wsdl:output, wsdl:fault elements and sets the action value
* in the wsdl model so that it can be used to generate correpsonding annotations on SEI.
*
* @author Rama Pulavarthi
*/
public class W3CAddressingMetadataExtensionHandler extends AbstractExtensionHandler {
private ErrorReceiver errReceiver;
public W3CAddressingMetadataExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap, ErrorReceiver errReceiver) {
super(extensionHandlerMap);
this.errReceiver = errReceiver;
}
@Override
public String getNamespaceURI() {
return WSAM_NAMESPACE_NAME;
}
@Override
public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSAM_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
return warnEmptyAction(parent, context.getLocation(e));
}
((Input)parent).setAction(actionValue);
return true;
}
@Override
public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSAM_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
return warnEmptyAction(parent,context.getLocation(e));
}
((Output)parent).setAction(actionValue);
return true;
}
@Override
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
String actionValue = XmlUtil.getAttributeNSOrNull(e, WSAM_ACTION_QNAME);
if (actionValue == null || actionValue.equals("")) {
errReceiver.warning(context.getLocation(e), WsdlMessages.WARNING_FAULT_EMPTY_ACTION(parent.getNameValue(), parent.getWSDLElementName().getLocalPart(), parent.getParent().getNameValue()));
return false; // keep compiler happy
}
((Fault)parent).setAction(actionValue);
return true;
}
private boolean warnEmptyAction(TWSDLExtensible parent, Locator pos) {
errReceiver.warning(pos, WsdlMessages.WARNING_INPUT_OUTPUT_EMPTY_ACTION(parent.getWSDLElementName().getLocalPart(), parent.getParent().getNameValue()));
return false;
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
import com.sun.tools.internal.xjc.util.DOMUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* @author Vivek Pandey
*/
public class WSDLInternalizationLogic implements InternalizationLogic{
/**
* This filter looks for &lt;xs:import> and &lt;xs:include>
* and parses those documents referenced by them.
*/
private static final class ReferenceFinder extends AbstractReferenceFinderImpl {
ReferenceFinder( DOMForest parent) {
super(parent);
}
@Override
protected String findExternalResource( String nsURI, String localName, Attributes atts) {
if(WSDLConstants.NS_WSDL.equals(nsURI) && "import".equals(localName)){
// if(parent.isExtensionMode()){
// //TODO: add support for importing schema using wsdl:import
// }
return atts.getValue("location");
}
// We don't need to do this anymore, JAXB handles the schema imports, includes etc., but this is useful for the clientJar option in
// fetching the imported schemas to package in the jar..
if (parent.options.clientjar != null) {
if (SchemaConstants.NS_XSD.equals(nsURI) && "import".equals(localName)) {
return atts.getValue("schemaLocation");
}
}
return null;
}
}
@Override
public XMLFilterImpl createExternalReferenceFinder(DOMForest parent) {
return new ReferenceFinder(parent);
}
@Override
public boolean checkIfValidTargetNode(DOMForest parent, Element bindings, Element target) {
return false;
}
@Override
public Element refineSchemaTarget(Element target) {
// look for existing xs:annotation
Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation");
if(annotation==null)
// none exists. need to make one
annotation = insertXMLSchemaElement( target, "annotation" );
// then look for appinfo
Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo" );
if(appinfo==null)
// none exists. need to make one
appinfo = insertXMLSchemaElement( annotation, "appinfo" );
return appinfo;
}
@Override
public Element refineWSDLTarget(Element target){
// look for existing xs:annotation
Element JAXWSBindings = DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings");
if(JAXWSBindings==null)
// none exists. need to make one
JAXWSBindings = insertJAXWSBindingsElement(target, "bindings" );
return JAXWSBindings;
}
private Element insertJAXWSBindingsElement( Element parent, String localName ) {
String qname = "JAXWS:"+localName;
Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname );
NodeList children = parent.getChildNodes();
if( children.getLength()==0 )
parent.appendChild(child);
else
parent.insertBefore( child, children.item(0) );
return child;
}
/**
* Creates a new XML Schema element of the given local name
* and insert it as the first child of the given parent node.
*
* @return
* Newly create element.
*/
private Element insertXMLSchemaElement( Element parent, String localName ) {
// use the same prefix as the parent node to avoid modifying
// the namespace binding.
String qname = parent.getTagName();
int idx = qname.indexOf(':');
if(idx==-1) qname = localName;
else qname = qname.substring(0,idx+1)+localName;
Element child = parent.getOwnerDocument().createElementNS( Constants.NS_XSD, qname );
NodeList children = parent.getChildNodes();
if( children.getLength()==0 )
parent.appendChild(child);
else
parent.insertBefore( child, children.item(0) );
return child;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.ws.wsdl.parser;
import com.sun.xml.internal.bind.WhiteSpaceProcessor;
import org.xml.sax.*;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* Strips ignorable whitespace from SAX event stream.
*
* <p>
* This filter works only when the event stream doesn't
* contain any mixed content.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
* Vivek Pandey
*/
class WhitespaceStripper extends XMLFilterImpl {
private int state = 0;
private char[] buf = new char[1024];
private int bufLen = 0;
private static final int AFTER_START_ELEMENT = 1;
private static final int AFTER_END_ELEMENT = 2;
public WhitespaceStripper(XMLReader reader) {
setParent(reader);
}
public WhitespaceStripper(ContentHandler handler, ErrorHandler eh, EntityResolver er) {
setContentHandler(handler);
if(eh!=null) setErrorHandler(eh);
if(er!=null) setEntityResolver(er);
}
public void characters(char[] ch, int start, int length) throws SAXException {
switch(state) {
case AFTER_START_ELEMENT:
// we have to store the characters here, even if it consists entirely
// of whitespaces. This is because successive characters event might
// include non-whitespace char, in which case all the whitespaces in
// this event may suddenly become significant.
if( bufLen+length>buf.length ) {
// reallocate buffer
char[] newBuf = new char[Math.max(bufLen+length,buf.length*2)];
System.arraycopy(buf,0,newBuf,0,bufLen);
buf = newBuf;
}
System.arraycopy(ch,start,buf,bufLen,length);
bufLen += length;
break;
case AFTER_END_ELEMENT:
// check if this is ignorable.
int len = start+length;
for( int i=start; i<len; i++ )
if( !WhiteSpaceProcessor.isWhiteSpace(ch[i]) ) {
super.characters(ch, start, length);
return;
}
// if it's entirely whitespace, ignore it.
break;
}
}
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
processPendingText();
super.startElement(uri, localName, qName, atts);
state = AFTER_START_ELEMENT;
bufLen = 0;
}
public void endElement(String uri, String localName, String qName) throws SAXException {
processPendingText();
super.endElement(uri, localName, qName);
state = AFTER_END_ELEMENT;
}
/**
* Forwars the buffered characters if it contains any non-whitespace
* character.
*/
private void processPendingText() throws SAXException {
if(state==AFTER_START_ELEMENT) {
for( int i=bufLen-1; i>=0; i-- )
if( !WhiteSpaceProcessor.isWhiteSpace(buf[i]) ) {
super.characters(buf, 0, bufLen);
return;
}
}
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
// ignore completely.
}
}