You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by sa...@apache.org on 2009/09/01 07:55:11 UTC
svn commit: r809836 [1/2] - in /webservices/woden/trunk/java/woden-dom: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/woden/ src/main/java/org/apache/woden/internal/
src/main/java/org/apache/wode...
Author: sagara
Date: Tue Sep 1 05:55:10 2009
New Revision: 809836
URL: http://svn.apache.org/viewvc?rev=809836&view=rev
Log:
Merging Woden-211 branch as the trunk.
Added:
webservices/woden/trunk/java/woden-dom/src/
webservices/woden/trunk/java/woden-dom/src/main/
webservices/woden/trunk/java/woden-dom/src/main/java/
webservices/woden/trunk/java/woden-dom/src/main/java/org/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLFactory.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLSource.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMXMLElement.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOM2Writer.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMQNameUtils.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMUtils.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/XPathUtils.java
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/xpointer/
webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/xpointer/DOMXMLElementEvaluator.java
webservices/woden/trunk/java/woden-dom/src/test/
webservices/woden/trunk/java/woden-dom/src/test/java/
webservices/woden/trunk/java/woden-dom/src/test/java/org/
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/woden/
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/woden/DOMXMLElementTest.java
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/woden/WSDLReaderTest.java
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/woden/schema/
webservices/woden/trunk/java/woden-dom/src/test/java/org/apache/woden/schema/SchemaTest.java
Modified:
webservices/woden/trunk/java/woden-dom/pom.xml
Modified: webservices/woden/trunk/java/woden-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/pom.xml?rev=809836&r1=809835&r2=809836&view=diff
==============================================================================
--- webservices/woden/trunk/java/woden-dom/pom.xml (original)
+++ webservices/woden/trunk/java/woden-dom/pom.xml Tue Sep 1 05:55:10 2009
@@ -30,23 +30,9 @@
<name>Woden - DOM</name>
<build>
- <sourceDirectory>../src</sourceDirectory>
- <testSourceDirectory>../test</testSourceDirectory>
<resources>
<resource>
- <directory>../src</directory>
- <includes>
- <include>**/internal/**</include>
- <include>**/javax/xml/namespace/**</include>
- <include>**/tool/converter/**</include>
- </includes>
- <excludes>
- <exclude>**/internal/OM**</exclude>
- <exclude>**/internal/resolver/OM**</exclude>
- <exclude>**/internal/util/om/**</exclude>
- <exclude>**/internal/xpointer/OM**</exclude>
- <exclude>**/*.java</exclude>
- </excludes>
+ <directory>src/main/resources</directory>
</resource>
<resource>
<targetPath>META-INF</targetPath>
@@ -58,39 +44,14 @@
</includes>
</resource>
</resources>
- <testResources>
- <testResource>
- <directory>../test</directory>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </testResource>
- </testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <includes>
- <include>**/internal/**</include>
- <include>**/javax/xml/namespace/**</include>
- <include>**/tool/converter/**</include>
- </includes>
- <excludes>
- <exclude>**/internal/OM**</exclude>
- <exclude>**/internal/resolver/OM**</exclude>
- <exclude>**/internal/util/om/**</exclude>
- <exclude>**/internal/xpointer/OM**</exclude>
- </excludes>
<source>1.4</source>
<target>1.4</target>
<compilerArgument>-g</compilerArgument>
- <testExcludes>
- <exclude>**/ant/*</exclude>
- <exclude>**/OM*</exclude>
- <exclude>**/AllWodenTests.java</exclude>
- <exclude>**/AllWodenTestsOM.java</exclude>
- </testExcludes>
</configuration>
</plugin>
<plugin>
@@ -110,7 +71,7 @@
</remoteRepositoryUrl>
</configuration>
</plugin>
- <plugin>
+ <!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
@@ -118,15 +79,25 @@
<include>**/AllWodenTestsDOM.class</include>
</includes>
</configuration>
- </plugin>
+ </plugin>-->
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.woden</groupId>
- <artifactId>woden-api</artifactId>
+ <artifactId>woden-impl-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
+ <!-- This dependency is need for getting shared test resources.
+ See http://tildemh.com/2007/12/19/maven2-unit-test-dependencies
+ -->
+ <dependency>
+ <groupId>org.apache.woden</groupId>
+ <artifactId>woden-impl-commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ <classifier>tests</classifier>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLFactory.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLFactory.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLFactory.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLFactory.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.internal;
+
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLReader;
+
+
+/**
+ * @author John Kaputin (jkaputin@apache.org)
+ */
+public class DOMWSDLFactory extends BaseWSDLFactory {
+
+ public DOMWSDLFactory() throws WSDLException {
+ super();
+ }
+
+ public WSDLReader newWSDLReader() throws WSDLException {
+ return new DOMWSDLReader(fWsdlContext);
+ }
+
+}
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLReader.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,963 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.internal;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.WSDLSource;
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.resolver.DOMSchemaResolverAdapter;
+import org.apache.woden.internal.resolver.EntityResolverAdapter;
+import org.apache.woden.internal.schema.ImportedSchemaImpl;
+import org.apache.woden.internal.schema.InlinedSchemaImpl;
+import org.apache.woden.internal.schema.SchemaConstants;
+import org.apache.woden.internal.util.StringUtils;
+import org.apache.woden.internal.wsdl20.Constants;
+import org.apache.woden.internal.wsdl20.validation.WSDLComponentValidator;
+import org.apache.woden.internal.wsdl20.validation.WSDLDocumentValidator;
+import org.apache.woden.internal.wsdl20.validation.WSDLValidator;
+import org.apache.woden.internal.xpointer.DOMXMLElementEvaluator;
+import org.apache.woden.schema.Schema;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.ImportElement;
+import org.apache.woden.wsdl20.xml.IncludeElement;
+import org.apache.woden.wsdl20.xml.TypesElement;
+import org.apache.woden.wsdl20.xml.WSDLElement;
+import org.apache.woden.xml.XMLAttr;
+import org.apache.woden.xpointer.InvalidXPointerException;
+import org.apache.woden.xpointer.XPointer;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaException;
+import org.apache.xerces.parsers.DOMParser;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Implements the WSDLReader behaviour for DOM-based parsing.
+ *
+ * @author John Kaputin (jkaputin@apache.org)
+ */
+public class DOMWSDLReader extends BaseWSDLReader {
+
+ private static final String emptyString = "".intern();
+
+ //a map of imported schema definitions keyed by schema location URI
+ private Map fImportedSchemas = new Hashtable();
+
+ /**
+ * WSDL document validator. Only one instance is needed.
+ */
+ private WSDLDocumentValidator docValidator = null;
+
+ /**
+ * WSDL component validator. Only one instance is needed.
+ */
+ private WSDLComponentValidator compValidator = null;
+
+ DOMWSDLReader(WSDLContext wsdlContext) throws WSDLException {
+ super(wsdlContext);
+ }
+
+ /* ************************************************************
+ * API public methods
+ * ************************************************************/
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.WSDLReader#createWSDLSource()
+ */
+ public WSDLSource createWSDLSource() {
+ return new DOMWSDLSource(getErrorReporter());
+ }
+
+ /*
+ * @see org.apache.woden.WSDLReader#readWSDL(String)
+ */
+ public Description readWSDL(String wsdlURI) throws WSDLException
+ {
+ URL url;
+ try {
+ url = StringUtils.getURL(null, wsdlURI);
+
+ } catch (MalformedURLException e) {
+
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ String wsdlURL = url.toString();
+
+ // ensure InputSource runs thru the URI Resolver
+ InputSource inputSource = new InputSource(resolveURI(wsdlURL));
+ return readWSDL(wsdlURL, inputSource);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.WSDLReader#readWSDL(org.apache.woden.WSDLSource)
+ */
+ public Description readWSDL(WSDLSource wsdlSource) throws WSDLException {
+
+ //TODO decide on how to handle null args in readWSDL methods (e.g.
+ //IllegalArgExc, WSDLExc, return null, etc).
+
+ Object source = wsdlSource.getSource();
+ URI baseURI = wsdlSource.getBaseURI();
+
+ String wsdlURL = null;
+ if(baseURI != null)
+ {
+ URL url;
+ try {
+ url = StringUtils.getURL(null, baseURI.toString());
+
+ } catch (MalformedURLException e) {
+
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL502", new Object[] {null, baseURI.toString()});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ wsdlURL = url.toString();
+ }
+
+ if(source instanceof Element) {
+ return readWSDL(wsdlURL, (Element)source);
+ }
+ else if(source instanceof Document) {
+ return readWSDL(wsdlURL, (Document)source);
+ }
+ else if(source instanceof InputSource) {
+ return readWSDL(wsdlURL, (InputSource)source);
+ }
+ else {
+ //This exception is checked in WSDLSource.setSource but we check
+ //again here in case the wrong type of WSDLSource has been used
+ //with this type of WSDLReader.
+ String sourceClass = source.getClass().getName();
+ String readerClass = this.getClass().getName();
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL017", new Object[] {sourceClass, readerClass});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+ }
+ }
+
+ /*
+ * Helper method for readWSDL(WSDLSource)
+ */
+ private Description readWSDL(String wsdlURL, Element docEl)
+ throws WSDLException {
+
+ XMLElement descEl = createXMLElement(docEl);
+ DescriptionElement descElem = parseDescription(wsdlURL, descEl, null);
+ Description descComp = descElem.toComponent();
+
+ //TODO if schema errors, don't do any further validation (i.e. assertions assume WSDL is schema valid)
+
+ // Validate the model if validation is enabled.
+ if(features.getValue(WSDLReader.FEATURE_VALIDATION))
+ {
+ /*
+ if(docValidator == null)
+ {
+ docValidator = new WSDLDocumentValidator();
+ }
+ if(docValidator.validate(descElem, getErrorReporter()))
+ {
+ if(compValidator == null)
+ {
+ compValidator = new WSDLComponentValidator();
+ }
+ compValidator.validate(descComp, getErrorReporter());
+ }
+ */
+ (new WSDLValidator()).validate(descComp, fWsdlContext);
+ }
+
+ return descComp;
+ }
+
+ /*
+ * Helper method for readWSDL(WSDLSource)
+ */
+ private Description readWSDL(String wsdlURI, Document domDoc)
+ throws WSDLException {
+
+ //Try to find an element the XPointer points to if a Fragment Identifier exists.
+ URI uri = null;
+ try {
+ uri = new URI(wsdlURI);
+ } catch (URISyntaxException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL506", new Object[] {null, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+
+ String fragment = uri.getFragment();
+
+
+ if (fragment == null) { //No fragment identifier so just use the root element.
+ return readWSDL(wsdlURI, domDoc.getDocumentElement());//Use document root if no WSDL20 root found.
+ } else {
+ XPointer xpointer;
+ try {
+ xpointer = new XPointer(fragment);
+ } catch(InvalidXPointerException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL530", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ Element root = domDoc.getDocumentElement();
+
+ DOMXMLElementEvaluator evaluator = new DOMXMLElementEvaluator(xpointer, root, getErrorReporter());
+ Element result = evaluator.evaluateElement();
+
+ if (result != null) { //Element from XPointer evaluation.
+ return readWSDL(wsdlURI, result);
+ } else {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL531", new Object[] {fragment, wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg);
+ }
+ }
+ }
+
+ /*
+ * Helper method for readWSDL(WSDLSource)
+ */
+ private Description readWSDL(String wsdlURI, InputSource inputSource)
+ throws WSDLException {
+
+ try
+ {
+ Document wsdlDocument = getDocument(inputSource, wsdlURI);
+
+ return readWSDL(wsdlURI, wsdlDocument);
+
+ } catch (IOException e) {
+ String msg = getErrorReporter().getFormattedMessage(
+ "WSDL503", new Object[] {wsdlURI});
+ throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
+ }
+ }
+
+ /* ************************************************************
+ * Parsing methods - e.g. parseXXXX()
+ * ************************************************************/
+
+
+ protected Schema parseSchemaInline(XMLElement schemaEl,
+ DescriptionElement desc)
+ throws WSDLException
+ {
+ InlinedSchemaImpl schema = new InlinedSchemaImpl();
+ schema.setXMLElement(schemaEl);
+
+ schema.setId(schemaEl.getAttributeValue(SchemaConstants.ATTR_ID));
+
+ String tns = schemaEl.getAttributeValue(SchemaConstants.ATTR_TARGET_NAMESPACE);
+ if(tns != null) {
+ schema.setNamespace(getURI(tns));
+ }
+
+ String baseURI = desc.getDocumentBaseURI() != null ?
+ desc.getDocumentBaseURI().toString() : null;
+ XmlSchema schemaDef = null;
+
+ try {
+ Element domSchemaEl = (Element)schemaEl.getSource();
+ XmlSchemaCollection xsc = new XmlSchemaCollection();
+ xsc.setBaseUri(baseURI);
+
+ // Plug in the selected woden URI Resolver
+ xsc.setSchemaResolver(new DOMSchemaResolverAdapter(getURIResolver(), schemaEl));
+ schemaDef = xsc.read(domSchemaEl, baseURI);
+ }
+ catch (XmlSchemaException e)
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL521",
+ new Object[] {baseURI},
+ ErrorReporter.SEVERITY_WARNING,
+ e);
+ }
+ catch (RuntimeException e)
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL521",
+ new Object[] {baseURI},
+ ErrorReporter.SEVERITY_ERROR,
+ e);
+ }
+
+ if(schemaDef != null) {
+ schema.setSchemaDefinition(schemaDef);
+ } else {
+ schema.setReferenceable(false);
+ }
+
+ return schema;
+ }
+
+ /*
+ * Parse the <xs:import> element and resolve the import to an
+ * XML Schema definition. Failure to retrieve
+ * the schema will only matter if any WSDL components contain elements or
+ * constraints that refer to the schema, and typically this will be
+ * determined later by WSDL validation. So just report any such errors
+ * and return the SchemaImport object (i.e. with a null schema property).
+ *
+ * WSDL 2.0 spec validation:
+ * - namespace attribute is REQUIRED
+ * - imported schema MUST have a targetNamespace
+ * - namespace and targetNamespace MUST be the same
+ *
+ * TODO implement a framework for caching schemas by namespace and resolving xs:import
+ */
+ protected Schema parseSchemaImport(XMLElement importEl,
+ DescriptionElement desc)
+ throws WSDLException
+ {
+ ImportedSchemaImpl schema = new ImportedSchemaImpl();
+ schema.setXMLElement(importEl);
+
+ String importNS = importEl.getAttributeValue(SchemaConstants.ATTR_NAMESPACE);
+ if(importNS != null) {
+ schema.setNamespace(getURI(importNS));
+ }
+
+ String schemaLoc = importEl.getAttributeValue(SchemaConstants.ATTR_SCHEMA_LOCATION);
+ if(schemaLoc != null) {
+ schema.setSchemaLocation(getURI(schemaLoc));
+ }
+
+ if(schema.getNamespace() == null)
+ {
+ //The namespace attribute is REQUIRED on xs:import, so don't continue.
+ schema.setReferenceable(false);
+ return schema;
+ }
+
+ XmlSchema schemaDef = null;
+
+ if(schema.getSchemaLocation() != null)
+ {
+ schemaDef = retrieveSchema(importEl, desc.getDocumentBaseURI(), schemaLoc);
+ }
+
+ if(schemaDef == null) {
+ //Either there was no schemaLocation or it did not resolve to a schema,
+ //so try to retrieve a schema at the namespace.
+ schemaDef = retrieveSchema(importEl, null, importNS);
+ }
+
+ if(schemaDef == null) {
+ //Check if any WSDL imports contain a schema with this namespace.
+ //TODO there may be multiple schemas that this namespace import could resolve to. This is a temporary solution pending WODEN- post M7.
+ ImportElement[] imports = desc.getImportElements();
+ for(int i=0; i<imports.length; i++) {
+ ImportElement importElem = (ImportElement) imports[i];
+ DescriptionElement nestedDesc = importElem.getDescriptionElement();
+ if(nestedDesc != null) {
+ TypesElement typesElem = nestedDesc.getTypesElement();
+ if(typesElem != null) {
+ Schema[] schemas = typesElem.getSchemas(schema.getNamespace());
+ for(int j=0; j<schemas.length; j++) {
+ Schema s = (Schema)schemas[i];
+ XmlSchema x = s.getSchemaDefinition();
+ if(x != null) {
+ schemaDef = x;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(schemaDef == null) {
+ //Check if any WSDL includes contain a schema with this namespace.
+ //TODO there may be multiple schemas that this namespace import could resolve to. This is a temporary solution pending WODEN- post M7.
+ IncludeElement[] includes = desc.getIncludeElements();
+ for(int i=0; i<includes.length; i++) {
+ IncludeElement includeElem = (IncludeElement) includes[i];
+ DescriptionElement nestedDesc = includeElem.getDescriptionElement();
+ if(nestedDesc != null) {
+ TypesElement typesElem = nestedDesc.getTypesElement();
+ if(typesElem != null) {
+ Schema[] schemas = typesElem.getSchemas(schema.getNamespace());
+ for(int j=0; j<schemas.length; j++) {
+ Schema s = (Schema)schemas[i];
+ XmlSchema x = s.getSchemaDefinition();
+ if(x != null) {
+ schemaDef = x;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(schemaDef != null) {
+ schema.setSchemaDefinition(schemaDef);
+ } else {
+ schema.setReferenceable(false);
+ }
+
+ return schema;
+ }
+
+ protected void parseExtensionAttributes(XMLElement extEl,
+ Class wsdlClass,
+ WSDLElement wsdlObj,
+ DescriptionElement desc)
+ throws WSDLException
+ {
+ Element domEl = (Element)extEl.getSource();
+ NamedNodeMap nodeMap = domEl.getAttributes();
+ int length = nodeMap.getLength();
+
+ for (int i = 0; i < length; i++)
+ {
+ Attr domAttr = (Attr)nodeMap.item(i);
+ String localName = domAttr.getLocalName();
+ String namespaceURI = domAttr.getNamespaceURI();
+ String prefix = domAttr.getPrefix();
+ QName attrType = new QName(namespaceURI, localName, (prefix != null ? prefix : emptyString));
+ String attrValue = domAttr.getValue();
+
+ if (namespaceURI != null && !namespaceURI.equals(Constants.NS_STRING_WSDL20))
+ {
+ if (!namespaceURI.equals(Constants.NS_STRING_XMLNS) &&
+ !namespaceURI.equals(Constants.NS_STRING_XSI)) //TODO handle xsi attrs elsewhere, without need to register
+ {
+ //TODO reg namespaces at appropriate element scope, not just at desc.
+ //DOMUtils.registerUniquePrefix(prefix, namespaceURI, desc);
+
+ ExtensionRegistry extReg = fWsdlContext.extensionRegistry;
+ XMLAttr xmlAttr = extReg.createExtAttribute(wsdlClass, attrType, extEl, attrValue);
+ if(xmlAttr != null) //TODO use an 'UnknownAttr' class in place of null
+ {
+ wsdlObj.setExtensionAttribute(attrType, xmlAttr);
+ }
+ }
+ else
+ {
+ //TODO parse xmlns namespace declarations - here or elsewhere?
+ }
+ }
+ else
+ {
+ //TODO confirm non-native attrs in WSDL 2.0 namespace will be detected by schema validation,
+ //so no need to handle error here.
+ }
+ }
+
+ }
+
+
+ /* ************************************************************
+ * Utility/helper methods
+ * ************************************************************/
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.internal.BaseWSDLReader#createXMLElement(java.lang.Object)
+ */
+ protected XMLElement createXMLElement(Object elem) {
+ DOMXMLElement domXMLElement = new DOMXMLElement(getErrorReporter());
+ domXMLElement.setSource(elem);
+ return domXMLElement;
+ }
+
+ //TODO when refactoring DOMWSDLReader into BaseWSDLReader, make this method abstract in BaseWSDLReader
+ //and keep this concrete implementation in DOMWSDLReader.
+ protected void parseNamespaceDeclarations(XMLElement xmlElem, WSDLElement wsdlElem)
+ throws WSDLException {
+
+ Element elem = (Element)xmlElem.getSource();
+
+ NamedNodeMap attrs = elem.getAttributes();
+ int size = attrs.getLength();
+
+ for (int i = 0; i < size; i++)
+ {
+ Attr attr = (Attr)attrs.item(i);
+ String namespaceURI = attr.getNamespaceURI();
+ String localPart = attr.getLocalName();
+ String value = attr.getValue();
+
+ if ((Constants.NS_STRING_XMLNS).equals(namespaceURI))
+ {
+ if (!(Constants.ATTR_XMLNS).equals(localPart))
+ {
+ wsdlElem.addNamespace(localPart, getURI(value)); //a prefixed namespace
+ }
+ else
+ {
+ wsdlElem.addNamespace(null, getURI(value)); //the default namespace
+ }
+ }
+ }
+ }
+
+ protected void parseSchemaForXMLSchema(DescriptionElement desc) throws WSDLException {
+
+ // Parse the schema for schema to include the built in schema types in the Woden model.
+ // TODO: As there are a finite number of built in schema types it may be better to create
+ // constants rather than reading the schema for schema on the creation of every model.
+ // Also, this method currently requires that the schema elements exist in the types element.
+ // This may not be the best idea as it may imply that this schema contains an actual import
+ // statement in a WSDL 2.0 document. This method also does not work for when building the
+ // model programmatically.
+ // This method should be reevaluated at a later point.
+ TypesElement types = desc.getTypesElement();
+ if (types == null) {
+ types = desc.addTypesElement();
+ }
+ if (types.getTypeSystem() == null)
+ {
+ types.setTypeSystem(Constants.TYPE_XSD_2001);
+ }
+
+ try
+ {
+ Document schemaDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element schemaElem = schemaDoc.
+ createElementNS(SchemaConstants.NS_STRING_SCHEMA, SchemaConstants.ELEM_IMPORT);
+ schemaElem.setAttribute(SchemaConstants.ATTR_NAMESPACE, SchemaConstants.NS_STRING_SCHEMA);
+ schemaElem.setAttribute(SchemaConstants.ATTR_SCHEMA_LOCATION, resolveURI("http://www.w3.org/2001/XMLSchema.xsd"));
+
+ XMLElement xmlEl = createXMLElement(schemaElem);
+ desc.getTypesElement().addSchema(parseSchemaImport(xmlEl, desc));
+ }
+ catch(Exception e)
+ {
+ System.out.println("A problem was encountered while creating the build in XML schema types: " + e);
+ }
+ }
+
+ private XmlSchema retrieveSchema(XMLElement contextElement, URI contextURI, String schemaSpec)
+ throws WSDLException {
+
+ Document importedSchemaDoc = null;
+ Element schemaEl = null;
+ String schemaLoc = null;
+ URL url = null;
+
+ try
+ {
+ /*
+ * For simple resolvers, we resolve the parent (Description) URI
+ * to be used as the context. This allows for relative locationURIs
+ * to be resolved implicitly - they are considered to be located
+ * relative to the resolved parent. Therefore, relative URIs such as these
+ * need not be listed in the catalog file.
+ */
+
+ /* TODO
+ * OASIS-style catalogs have a convenience notation to define root URIs
+ * thus grouping related URLs together. In this case the context URI here
+ * should be left alone, but the resultant locationURL resolved instead.
+ *
+ * Implement a boolean system property like org.apache.woden.resolver.useRelativeURLs
+ * (set by the resolver ctor). SimpleURIResolver (et al) should set this to true,
+ * OASISCatalogResolver should set to false.
+ */
+ URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
+ url = StringUtils.getURL(contextURL, schemaSpec);
+
+ } catch (MalformedURLException e) {
+
+ String baseLoc = contextURI != null ? contextURI.toString() : null;
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL502",
+ new Object[] {baseLoc, schemaLoc},
+ ErrorReporter.SEVERITY_ERROR);
+ //can't continue schema retrieval with a bad URL.
+ return null;
+ }
+
+ String schemaURL = url.toString();
+
+ //If the schema has already been imported, reuse it.
+ XmlSchema schemaDef = (XmlSchema)fImportedSchemas.get(schemaURL);
+
+ if(schemaDef == null)
+ {
+ //not previously imported, so retrieve it now.
+ String resolvedLoc = null;
+ try {
+ URI resolvedURI = resolveURI(getURI(schemaURL));
+ resolvedLoc = resolvedURI.toString();
+ importedSchemaDoc = getDocument(new InputSource(resolvedLoc), resolvedLoc);
+
+ } catch (IOException e4) {
+
+ //schema retrieval failed (e.g. 'not found')
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL504",
+ new Object[] {schemaURL},
+ ErrorReporter.SEVERITY_WARNING,
+ e4);
+ //cannot continue without resolving the URL
+ return null;
+ }
+
+ schemaEl = importedSchemaDoc.getDocumentElement();
+
+ try {
+ //String baseLoc = contextURI != null ? contextURI.toString() : null;
+ String baseLoc = resolvedLoc;
+ XmlSchemaCollection xsc = new XmlSchemaCollection();
+ xsc.setBaseUri(resolvedLoc);
+
+ // Plug in the selected woden URI Resolver
+ xsc.setSchemaResolver(new DOMSchemaResolverAdapter(getURIResolver(), contextElement));
+
+ schemaDef = xsc.read(schemaEl, baseLoc);
+ fImportedSchemas.put(schemaURL, schemaDef);
+ }
+ catch (XmlSchemaException e)
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL522",
+ new Object[] {schemaURL},
+ ErrorReporter.SEVERITY_WARNING,
+ e);
+ }
+ }
+
+ return schemaDef;
+ }
+
+ private Document getDocument(InputSource inputSource, String desc)
+ throws WSDLException, IOException
+ {
+ //TODO use 'desc' URL in any error message(s) for problem resolution.
+
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+//
+// factory.setNamespaceAware(true);
+
+ DOMParser parser = new DOMParser();
+ parser.setEntityResolver(new EntityResolverAdapter(getURIResolver()));
+
+ try
+ {
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACES_FEATURE, true);
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.NAMESPACE_PREFIXES_FEATURE, true);
+ }
+ catch(SAXNotRecognizedException e)
+ {
+
+ }
+ catch(SAXNotSupportedException e)
+ {
+
+ }
+
+ // Enable validation on the XML parser if it has been enabled
+ // for the Woden parser.
+ if(features.getValue(WSDLReader.FEATURE_VALIDATION))
+ {
+ //factory.setValidating(true);
+ try
+ {
+ parser.setFeature(org.apache.xerces.impl.Constants.SAX_FEATURE_PREFIX + org.apache.xerces.impl.Constants.VALIDATION_FEATURE, true);
+ parser.setFeature(org.apache.xerces.impl.Constants.XERCES_FEATURE_PREFIX + org.apache.xerces.impl.Constants.SCHEMA_VALIDATION_FEATURE, true);
+ // TODO: This external schema location should be removed once an URI resolution framework
+ // with a catalog is added to Woden.
+
+ parser.setProperty(org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX + org.apache.xerces.impl.Constants.SCHEMA_LOCATION, "http://www.w3.org/ns/wsdl " + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20.xsd") + " http://www.w3.org/ns/wsdl-extensions " + resolveURI("http://www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd") + " http://www.w3.org/2001/XMLSchema " + resolveURI("http://www.w3.org/2001/XMLSchema.xsd"));
+ }
+ catch(SAXNotRecognizedException e)
+ {
+ System.out.println("validation not supported by parser.");
+ }
+ catch(SAXNotSupportedException e)
+ {
+
+ }
+ }
+ else
+ {
+ //factory.setValidating(false);
+ }
+
+ Document doc = null;
+
+ try {
+
+ //DocumentBuilder builder = factory.newDocumentBuilder();
+ //builder.getDOMImplementation().hasFeature();
+ //builder.setErrorHandler(new ErrorHandlerWrapper(getErrorReporter()));
+ //builder.setEntityResolver(new DefaultHandler());
+ //doc = builder.parse(inputSource);
+ parser.parse(inputSource);
+ doc = parser.getDocument();
+
+ }
+// catch (ParserConfigurationException e)
+// {
+// String msg = getErrorReporter().getFormattedMessage("WSDL002", new Object[] {"XML"});
+// throw new WSDLException(WSDLException.CONFIGURATION_ERROR, msg, e);
+// }
+ catch (SAXException e)
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL500",
+ new Object[] {"SAX", desc},
+ ErrorReporter.SEVERITY_FATAL_ERROR,
+ e);
+ }
+
+ //TODO - potentially returns null. correct after deciding how
+ //to handle exceptions (e.g. return inside try block).
+ return doc;
+ }
+
+ /*
+ * Retrieve a WSDL document by resolving the location URI specified
+ * on a WSDL <import> or <include> element.
+ *
+ * TODO add support for a URL Catalog Resolver
+ */
+ protected DescriptionElement getWSDLFromLocation(String locationURI,
+ DescriptionElement desc,
+ Map wsdlModules)
+ throws WSDLException
+ {
+ DescriptionElement referencedDesc = null;
+ Element docEl;
+ URL locationURL = null;
+ URI contextURI = null;
+
+ try
+ {
+ /*
+ * For simple resolvers, we resolve the parent (Description) URI
+ * to be used as the context. This allows for relative locationURIs
+ * to be resolved implicitly - they are considered to be located
+ * relative to the resolved parent. Therefore, relative URIs such as these
+ * need not be listed in the catalog file.
+ */
+
+ /* TODO
+ * OASIS-style catalogs have a convenience notation to define root URIs
+ * thus grouping related URLs together. In this case the context URI here
+ * should be left alone, but the resultant locationURL resolved instead.
+ *
+ * Implement a boolean system property like org.apache.woden.resolver.useRelativeURLs
+ * (set by the resolver ctor). SimpleURIResolver (et al) should set this to true,
+ * OASISCatalogResolver should set to false.
+ */
+ // contextURI = desc.getDocumentBaseURI();
+ contextURI = resolveURI(desc.getDocumentBaseURI());
+ URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
+ locationURL = StringUtils.getURL(contextURL, locationURI);
+ }
+ catch (MalformedURLException e)
+ {
+ String baseURI = contextURI != null ? contextURI.toString() : null;
+
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL502",
+ new Object[] {baseURI, locationURI},
+ ErrorReporter.SEVERITY_ERROR);
+
+ //can't continue import with a bad URL.
+ return null;
+ }
+
+ String locationStr = locationURL.toString();
+
+ //Check if WSDL imported or included previously from this location.
+ referencedDesc = (DescriptionElement)wsdlModules.get(locationStr);
+
+ if(referencedDesc == null)
+ {
+ //not previously imported or included, so retrieve the WSDL.
+ try {
+ Document doc = getDocument(
+ new InputSource(locationStr), locationStr);
+ docEl = doc.getDocumentElement();
+ }
+ catch (IOException e)
+ {
+ //document retrieval failed (e.g. 'not found')
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL503",
+ new Object[] {locationStr},
+ ErrorReporter.SEVERITY_WARNING,
+ e);
+
+ //cannot continue without the referenced document
+ return null;
+ }
+
+ //The referenced document should contain a WSDL <description>
+ QName docElQN = new QName(docEl.getNamespaceURI(), docEl.getLocalName());
+
+ if(!Constants.Q_ELEM_DESCRIPTION.equals(docElQN))
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL501",
+ new Object[] {Constants.Q_ELEM_DESCRIPTION, docElQN},
+ ErrorReporter.SEVERITY_ERROR);
+
+ //cannot continue without a <description> element
+ return null;
+ }
+
+ XMLElement descEl = createXMLElement(docEl);
+
+ referencedDesc = parseDescription(locationStr,
+ descEl,
+ wsdlModules);
+
+ if(!wsdlModules.containsKey(locationStr))
+ {
+ wsdlModules.put(locationStr, referencedDesc);
+ }
+ }
+
+ return referencedDesc;
+ }
+
+ /**
+ * A wrapper that plugs Woden's error reporter mechanism into the
+ * XML parser used to parse the WSDL document.
+ */
+ class ErrorHandlerWrapper implements org.xml.sax.ErrorHandler
+ {
+ /**
+ * The error reporter used to report errors in Woden.
+ */
+ private ErrorReporter errorReporter;
+
+ /**
+ * Constructor.
+ *
+ * @param errorReporter The error reporter to be wrapped.
+ */
+ public ErrorHandlerWrapper(ErrorReporter errorReporter)
+ {
+ this.errorReporter = errorReporter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException error) throws SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(error.getLineNumber());
+ locator.setColumnNumber(error.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null, error.getMessage(), ErrorReporter.SEVERITY_ERROR, error.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException error) throws SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(error.getLineNumber());
+ locator.setColumnNumber(error.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null, error.getMessage(), ErrorReporter.SEVERITY_FATAL_ERROR, error.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException warning) throws SAXException
+ {
+ ErrorLocatorImpl locator = new ErrorLocatorImpl();
+ locator.setLineNumber(warning.getLineNumber());
+ locator.setColumnNumber(warning.getColumnNumber());
+ try
+ {
+ errorReporter.reportError(locator, null, warning.getMessage(), ErrorReporter.SEVERITY_WARNING, warning.getException());
+ }
+ catch(WSDLException e)
+ {
+ throw new SAXException("A problem occurred setting the error in the Woden error reporter wrapper.", e);
+ }
+
+ }
+
+
+
+ }
+
+ class WSDLEntityResolver implements org.xml.sax.EntityResolver
+ {
+
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ // TODO Auto-generated method stub
+
+ return null;
+ }
+
+ }
+
+}
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLSource.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLSource.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLSource.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMWSDLSource.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.internal;
+
+import org.apache.woden.ErrorReporter;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+
+
+/**
+ * This class provides a WSDLSource implementation that supports a
+ * DOM-based representation of the WSDL source. Specifically, it
+ * may accept via its <code>setSource</code> method an object of type
+ * org.w3c.dom.Element, org.w3c.dom.Document or org.xml.sax.InputSource.
+ * Any other type of object passed to this method will result in a
+ * WSDLException being thrown.
+ *
+ * @author John Kaputin (jkaputin@apache.org)
+ */
+public class DOMWSDLSource extends BaseWSDLSource {
+
+ public DOMWSDLSource(ErrorReporter errorReporter) {
+ super(errorReporter);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.WSDLSource#setSource(java.lang.Object)
+ */
+ public void setSource(Object wsdlSource) {
+
+ //TODO check if any other types of wsdl source should be supported
+ if(wsdlSource instanceof Element ||
+ wsdlSource instanceof Document ||
+ wsdlSource instanceof InputSource) {
+ fSource = wsdlSource;
+ }
+ else {
+ String sourceClass = (wsdlSource != null
+ ? wsdlSource.getClass().getName()
+ : null);
+ String wsdlSourceClass = this.getClass().getName();
+ String msg = fErrorReporter.getFormattedMessage(
+ "WSDL018", new Object[] {sourceClass, wsdlSourceClass});
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+}
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMXMLElement.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMXMLElement.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMXMLElement.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/DOMXMLElement.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,262 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.woden.internal;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.util.dom.DOMQNameUtils;
+import org.apache.woden.internal.util.dom.XPathUtils;
+import org.apache.woden.internal.wsdl20.Constants;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class DOMXMLElement extends BaseXMLElement{
+
+ private static final String emptyString = "".intern();
+
+ public DOMXMLElement(ErrorReporter errorReporter) {
+ super(errorReporter);
+ }
+
+ /*
+ * @see org.apache.woden.XMLElement#setSource(java.lang.Object)
+ */
+ public void setSource(Object elem) {
+
+ if(elem instanceof Element) {
+ fSource = elem;
+ }
+ else {
+ String elemClass = (elem != null
+ ? elem.getClass().getName()
+ : null);
+ String xmlElementClass = this.getClass().getName();
+ String msg = fErrorReporter.getFormattedMessage(
+ "WSDL019", new Object[] {elemClass, xmlElementClass});
+ throw new IllegalArgumentException(msg);
+ }
+
+ }
+
+ /*TODO complete this method if it's added to XMLElement.
+ *
+ public XMLAttribute[] getAttributes() {
+
+ String nodename, prefix;
+ Element el = (Element)fSource;
+ List attrs = new Vector();
+ NamedNodeMap attrMap = el.getAttributes();
+ for(int i = 0; i < attrMap.getLength(); i++){
+ nodename = attrMap.item(i).getNodeName();
+ prefix = attrMap.item(i).getPrefix();
+ if ( !(Constants.ATTR_XMLNS.equals(nodename) ||
+ Constants.ATTR_XMLNS.equals(prefix)) ) {
+ //TODO create an XMLAttribute from attrMap.item(i)
+ //attrs.add(xmlAttribute);
+ }
+ }
+
+ XMLElement[] array = new XMLElement[attrs.size()];
+ attrs.toArray(array);
+ return array;
+ }
+ */
+
+
+ protected String doGetAttributeValue(String attrName) {
+
+ Element el = (Element)fSource;
+ return getAttribute(el, attrName);
+ }
+
+ protected URI doGetNamespaceURI() throws WSDLException {
+
+ Element el = (Element)fSource;
+ String nsStr = el.getNamespaceURI();
+ URI uri = null;
+
+ if (nsStr != null) {
+ try {
+ uri = new URI(nsStr);
+ } catch (URISyntaxException e) {
+ String msg = fErrorReporter.getFormattedMessage("WSDL506", new Object[] { nsStr });
+ throw new WSDLException(WSDLException.INVALID_WSDL, msg, e);
+ }
+ }
+ return uri;
+ }
+
+ protected String doGetLocalName() {
+
+ Element el = (Element)fSource;
+ return el.getLocalName();
+ }
+
+ protected QName doGetQName() {
+
+ Element el = (Element)fSource;
+ return new QName(el.getNamespaceURI(), el.getLocalName());
+ }
+
+ protected QName doGetQName(String prefixedValue) throws WSDLException {
+
+ Element el = (Element)fSource;
+ int index = prefixedValue.indexOf(':');
+ String prefix = (index != -1)
+ ? prefixedValue.substring(0, index)
+ : null;
+ String localPart = prefixedValue.substring(index + 1);
+ String namespaceURI = getNamespaceFromPrefix(el, prefix);
+
+ if(prefix != null && namespaceURI == null) {
+ String faultCode = WSDLException.UNBOUND_PREFIX;
+ String msg = fErrorReporter.getFormattedMessage(
+ "WSDL513",
+ new Object[] {prefixedValue, DOMQNameUtils.newQName(el)});
+ WSDLException wsdlExc = new WSDLException(
+ faultCode,
+ msg);
+ wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(el));
+ throw wsdlExc;
+ }
+
+ return new QName(namespaceURI, localPart, (prefix != null ? prefix : emptyString));
+ }
+
+ protected XMLElement doGetFirstChildElement() {
+
+ XMLElement xmlElement = new DOMXMLElement(fErrorReporter);
+ Element el = (Element)fSource;
+ for (Node node = el.getFirstChild(); node!=null; node=node.getNextSibling()){
+ if (node.getNodeType() == Node.ELEMENT_NODE){
+ xmlElement.setSource(node);
+ return xmlElement;
+ }
+ }
+ return null; //no child element found
+ }
+
+ protected XMLElement doGetNextSiblingElement() {
+
+ XMLElement xmlElement = new DOMXMLElement(fErrorReporter);
+ Element el = (Element)fSource;
+ for (Node node = el.getNextSibling (); node != null; node = node.getNextSibling ()) {
+ if (node.getNodeType() == Node.ELEMENT_NODE){
+ xmlElement.setSource(node);
+ return xmlElement;
+ }
+ }
+ return null; //no sibling element found
+ }
+
+ protected XMLElement[] doGetChildElements() {
+
+ List children = new Vector();
+ XMLElement temp = doGetFirstChildElement();
+ while(temp != null)
+ {
+ children.add(temp);
+ temp = temp.getNextSiblingElement();
+ }
+ XMLElement[] array = new XMLElement[children.size()];
+ children.toArray(array);
+ return array;
+ }
+
+ /* ************************************************************************
+ * Private helper methods
+ * ************************************************************************/
+
+ private String getAttribute(Element el, String attrName) {
+
+ String sRet = null;
+ Attr attr = el.getAttributeNode(attrName);
+
+ if (attr != null) {
+ sRet = attr.getValue();
+ }
+ return sRet;
+ }
+
+ private String getAttributeNS (Element el,
+ String namespaceURI,
+ String localPart) {
+ String sRet = null;
+ Attr attr = el.getAttributeNodeNS (namespaceURI, localPart);
+
+ if (attr != null) {
+ sRet = attr.getValue ();
+ }
+
+ return sRet;
+ }
+
+ private String getNamespaceFromPrefix(Node context, String prefix) {
+
+ short nodeType = context.getNodeType ();
+ Node tempNode = null;
+
+ switch (nodeType)
+ {
+ case Node.ATTRIBUTE_NODE :
+ {
+ tempNode = ((Attr) context).getOwnerElement ();
+ break;
+ }
+ case Node.ELEMENT_NODE :
+ {
+ tempNode = context;
+ break;
+ }
+ default :
+ {
+ tempNode = context.getParentNode ();
+ break;
+ }
+ }
+
+ while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
+ {
+ Element tempEl = (Element) tempNode;
+
+ String namespaceURI = (prefix == null)
+ ? getAttribute (tempEl, Constants.ATTR_XMLNS)
+ : getAttributeNS (tempEl, Constants.NS_STRING_XMLNS, prefix);
+
+ if (namespaceURI != null)
+ {
+ return namespaceURI;
+ }
+ else
+ {
+ tempNode = tempEl.getParentNode ();
+ }
+ }
+
+ return null; //no namespace found for specified prefix
+ }
+}
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOM2Writer.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOM2Writer.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOM2Writer.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOM2Writer.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,451 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.internal.util.dom;
+
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.woden.internal.util.ObjectRegistry;
+import org.apache.woden.internal.util.StringUtils;
+import org.apache.woden.internal.wsdl20.Constants;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class copied from WSDL4J.
+ *
+ * This class is a utility to serialize a DOM node as XML. This class
+ * uses the <code>DOM Level 2</code> APIs.
+ * The main difference between this class and DOMWriter is that this class
+ * generates and prints out namespace declarations.
+ *
+ * @author Matthew J. Duftler (duftler@us.ibm.com)
+ * @author Joseph Kesselman
+ */
+public class DOM2Writer
+{
+ /**
+ * The namespaceURI represented by the prefix <code>xmlns</code>.
+ */
+ private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
+
+ /**
+ * The namespaceURI represented by the prefix <code>xml</code>.
+ */
+ private static String NS_URI_XML = "http://www.w3.org/XML/1998/namespace";
+
+ private static Map xmlEncodingMap = new HashMap();
+
+ static
+ {
+ xmlEncodingMap.put(null, Constants.XML_DECL_DEFAULT);
+ xmlEncodingMap.put(System.getProperty("file.encoding"),
+ Constants.XML_DECL_DEFAULT);
+ xmlEncodingMap.put("UTF8", "UTF-8");
+ xmlEncodingMap.put("UTF-16", "UTF-16");
+ xmlEncodingMap.put("UnicodeBig", "UTF-16");
+ xmlEncodingMap.put("UnicodeLittle", "UTF-16");
+ xmlEncodingMap.put("ASCII", "US-ASCII");
+ xmlEncodingMap.put("ISO8859_1", "ISO-8859-1");
+ xmlEncodingMap.put("ISO8859_2", "ISO-8859-2");
+ xmlEncodingMap.put("ISO8859_3", "ISO-8859-3");
+ xmlEncodingMap.put("ISO8859_4", "ISO-8859-4");
+ xmlEncodingMap.put("ISO8859_5", "ISO-8859-5");
+ xmlEncodingMap.put("ISO8859_6", "ISO-8859-6");
+ xmlEncodingMap.put("ISO8859_7", "ISO-8859-7");
+ xmlEncodingMap.put("ISO8859_8", "ISO-8859-8");
+ xmlEncodingMap.put("ISO8859_9", "ISO-8859-9");
+ xmlEncodingMap.put("ISO8859_13", "ISO-8859-13");
+ xmlEncodingMap.put("ISO8859_15_FDIS", "ISO-8859-15");
+ xmlEncodingMap.put("GBK", "GBK");
+ xmlEncodingMap.put("Big5", "Big5");
+ }
+
+ /**
+ * Return a string containing this node serialized as XML.
+ */
+ public static String nodeToString(Node node)
+ {
+ StringWriter sw = new StringWriter();
+
+ serializeAsXML(node, sw);
+
+ return sw.toString();
+ }
+
+
+ /**
+ * Print an XML declaration before serializing the element.
+ */
+ public static void serializeElementAsDocument(Element el, Writer writer)
+ {
+ PrintWriter pw = new PrintWriter(writer);
+ String javaEncoding = (writer instanceof OutputStreamWriter)
+ ? ((OutputStreamWriter) writer).getEncoding()
+ : null;
+
+ String xmlEncoding = java2XMLEncoding(javaEncoding);
+
+ if (xmlEncoding != null)
+ {
+ pw.println(Constants.XML_DECL_START +
+ xmlEncoding +
+ Constants.XML_DECL_END);
+ }
+ else
+ {
+ pw.println("<?xml version=\"1.0\"?>");
+ }
+
+ serializeAsXML(el, writer);
+ }
+
+ /**
+ * Serialize this node into the writer as XML.
+ */
+ public static void serializeAsXML(Node node, Writer writer)
+ {
+ ObjectRegistry namespaceStack = new ObjectRegistry();
+
+ namespaceStack.register("xml", NS_URI_XML);
+
+ PrintWriter pw = new PrintWriter(writer);
+ String javaEncoding = (writer instanceof OutputStreamWriter)
+ ? ((OutputStreamWriter) writer).getEncoding()
+ : null;
+
+ print(node, namespaceStack, pw, java2XMLEncoding(javaEncoding));
+ }
+
+ private static void print(Node node, ObjectRegistry namespaceStack,
+ PrintWriter out, String xmlEncoding)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ boolean hasChildren = false;
+ int type = node.getNodeType();
+
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE :
+ {
+ if (xmlEncoding != null)
+ {
+ out.println(Constants.XML_DECL_START +
+ xmlEncoding +
+ Constants.XML_DECL_END);
+ }
+ else
+ {
+ out.println("<?xml version=\"1.0\"?>");
+ }
+
+ NodeList children = node.getChildNodes();
+
+ if (children != null)
+ {
+ int numChildren = children.getLength();
+
+ for (int i = 0; i < numChildren; i++)
+ {
+ print(children.item(i), namespaceStack, out, xmlEncoding);
+ }
+ }
+ break;
+ }
+
+ case Node.ELEMENT_NODE :
+ {
+ namespaceStack = new ObjectRegistry(namespaceStack);
+
+ out.print('<' + node.getNodeName());
+
+ String elPrefix = node.getPrefix();
+ String elNamespaceURI = node.getNamespaceURI();
+
+ if (elPrefix != null && elNamespaceURI != null)
+ {
+ boolean prefixIsDeclared = false;
+
+ try
+ {
+ String namespaceURI = (String)namespaceStack.lookup(elPrefix);
+
+ if (elNamespaceURI.equals(namespaceURI))
+ {
+ prefixIsDeclared = true;
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ // ignore this and carry on
+ }
+
+ if (!prefixIsDeclared)
+ {
+ printNamespaceDecl(node, namespaceStack, out);
+ }
+ }
+
+ NamedNodeMap attrs = node.getAttributes();
+ int len = (attrs != null) ? attrs.getLength() : 0;
+
+ for (int i = 0; i < len; i++)
+ {
+ Attr attr = (Attr)attrs.item(i);
+
+ out.print(' ' + attr.getNodeName() +"=\"" +
+ normalize(attr.getValue()) + '\"');
+
+ String attrPrefix = attr.getPrefix();
+ String attrNamespaceURI = attr.getNamespaceURI();
+
+ if (attrPrefix != null && attrNamespaceURI != null)
+ {
+ boolean prefixIsDeclared = false;
+
+ try
+ {
+ String namespaceURI = (String)namespaceStack.lookup(attrPrefix);
+
+ if (attrNamespaceURI.equals(namespaceURI))
+ {
+ prefixIsDeclared = true;
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ // ignore this and carry on
+ }
+
+ if (!prefixIsDeclared)
+ {
+ printNamespaceDecl(attr, namespaceStack, out);
+ }
+ }
+ }
+
+ NodeList children = node.getChildNodes();
+
+ if (children != null)
+ {
+ int numChildren = children.getLength();
+
+ hasChildren = (numChildren > 0);
+
+ if (hasChildren)
+ {
+ out.print('>');
+ }
+
+ for (int i = 0; i < numChildren; i++)
+ {
+ print(children.item(i), namespaceStack, out, xmlEncoding);
+ }
+ }
+ else
+ {
+ hasChildren = false;
+ }
+
+ if (!hasChildren)
+ {
+ out.print("/>");
+ }
+ break;
+ }
+
+ case Node.ENTITY_REFERENCE_NODE :
+ {
+ out.print('&');
+ out.print(node.getNodeName());
+ out.print(';');
+ break;
+ }
+
+ case Node.CDATA_SECTION_NODE :
+ {
+ out.print("<![CDATA[");
+ out.print(node.getNodeValue());
+ out.print("]]>");
+ break;
+ }
+
+ case Node.TEXT_NODE :
+ {
+ out.print(normalize(node.getNodeValue()));
+ break;
+ }
+
+ case Node.COMMENT_NODE :
+ {
+ out.print("<!--");
+ out.print(node.getNodeValue());
+ out.print("-->");
+ break;
+ }
+
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ {
+ out.print("<?");
+ out.print(node.getNodeName());
+
+ String data = node.getNodeValue();
+
+ if (data != null && data.length() > 0)
+ {
+ out.print(' ');
+ out.print(data);
+ }
+
+ out.println("?>");
+ break;
+ }
+ }
+
+ if (type == Node.ELEMENT_NODE && hasChildren == true)
+ {
+ out.print("</");
+ out.print(node.getNodeName());
+ out.print('>');
+ hasChildren = false;
+ }
+ }
+
+ public static String java2XMLEncoding(String javaEnc)
+ {
+ return (String)xmlEncodingMap.get(javaEnc);
+ }
+
+
+ private static void printNamespaceDecl(Node node,
+ ObjectRegistry namespaceStack,
+ PrintWriter out)
+ {
+ switch (node.getNodeType())
+ {
+ case Node.ATTRIBUTE_NODE :
+ {
+ printNamespaceDecl(((Attr)node).getOwnerElement(), node,
+ namespaceStack, out);
+ break;
+ }
+
+ case Node.ELEMENT_NODE :
+ {
+ printNamespaceDecl((Element)node, node, namespaceStack, out);
+ break;
+ }
+ }
+ }
+
+ private static void printNamespaceDecl(Element owner, Node node,
+ ObjectRegistry namespaceStack,
+ PrintWriter out)
+ {
+ String namespaceURI = node.getNamespaceURI();
+ String prefix = node.getPrefix();
+
+ if (!(namespaceURI.equals(NS_URI_XMLNS) && prefix.equals("xmlns")))
+ {
+ if (DOMUtils.getAttributeNS(owner, NS_URI_XMLNS, prefix) == null)
+ {
+ out.print(" xmlns:" + prefix + "=\"" + namespaceURI + '\"');
+ }
+ }
+ else
+ {
+ prefix = node.getLocalName();
+ namespaceURI = node.getNodeValue();
+ }
+
+ namespaceStack.register(prefix, namespaceURI);
+ }
+
+ private static String normalize(String s)
+ {
+ StringBuffer str = new StringBuffer();
+ int len = (s != null) ? s.length() : 0;
+
+ for (int i = 0; i < len; i++)
+ {
+ char ch = s.charAt(i);
+
+ switch (ch)
+ {
+ case '<' :
+ {
+ str.append("<");
+ break;
+ }
+ case '>' :
+ {
+ str.append(">");
+ break;
+ }
+ case '&' :
+ {
+ str.append("&");
+ break;
+ }
+ case '"' :
+ {
+ str.append(""");
+ break;
+ }
+ case '\n' :
+ {
+ if (i > 0)
+ {
+ char lastChar = str.charAt(str.length() - 1);
+
+ if (lastChar != '\r')
+ {
+ str.append(StringUtils.lineSeparator);
+ }
+ else
+ {
+ str.append('\n');
+ }
+ }
+ else
+ {
+ str.append(StringUtils.lineSeparator);
+ }
+ break;
+ }
+ default :
+ {
+ str.append(ch);
+ }
+ }
+ }
+
+ return (str.toString());
+ }
+}
\ No newline at end of file
Added: webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMQNameUtils.java
URL: http://svn.apache.org/viewvc/webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMQNameUtils.java?rev=809836&view=auto
==============================================================================
--- webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMQNameUtils.java (added)
+++ webservices/woden/trunk/java/woden-dom/src/main/java/org/apache/woden/internal/util/dom/DOMQNameUtils.java Tue Sep 1 05:55:10 2009
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.woden.internal.util.dom;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+/**
+ * This class originated from WSDL4J
+ *
+ * @author jkaputin@apache.org (Woden changes)
+ *
+ */
+public class DOMQNameUtils
+{
+ public static boolean matches(QName qname, Node node)
+ {
+ return (node != null && qname.equals(newQName(node)));
+ }
+
+ public static QName newQName(Node node)
+ {
+ if (node != null)
+ {
+ return new QName(node.getNamespaceURI(), node.getLocalName());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org