You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by bi...@apache.org on 2008/11/17 20:25:45 UTC

svn commit: r718331 - in /webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH: ./ src/main/java/org/apache/ws/commons/schema/ src/main/java/org/apache/ws/commons/schema/utils/

Author: bimargulies
Date: Mon Nov 17 11:25:44 2008
New Revision: 718331

URL: http://svn.apache.org/viewvc?rev=718331&view=rev
Log:
WSCOMMONS-362. When capturing a node list, make a document fragment. Note that the 'set' APIs for AppInfo and Documentation don't do the cloning, the
builder does. So anyone building their own XmlSchema should worry about this issue for themselves.

Added:
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java   (with props)
Modified:
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/build.xml
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/pom.xml
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
    webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java

Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/build.xml
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/build.xml?rev=718331&r1=718330&r2=718331&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/build.xml (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/build.xml Mon Nov 17 11:25:44 2008
@@ -30,16 +30,16 @@
 	<property name="dist.dir" value="${build.dir}/dist"/>
 	<property name="dist.zip" value="${project.name}.zip"/>
 	<property name="srcdist.zip" value="${project.name}-src.zip"/>
-    <property name="test.dir" value="${basedir}/src/test/java"/>
+	<property name="test.dir" value="${basedir}/src/test/java"/>
 	<property name="test_classes.dir" value="${build.dir}/test-classes"/>
-    <property name="test_reports.dir" value="${build.dir}/test-reports"/>
-    <property name="test_reports_w3c.dir" value="${build.dir}/test-reports-w3c"/>
+	<property name="test_reports.dir" value="${build.dir}/test-reports"/>
+	<property name="test_reports_w3c.dir" value="${build.dir}/test-reports-w3c"/>
 
-    <target name="setproxy" if="http.proxyhost">
-        <setproxy proxyhost="${http.proxyHost}" proxyport="${http.proxyPort}"/>
-    </target>
+	<target name="setproxy" if="http.proxyhost">
+	  <setproxy proxyhost="${http.proxyHost}" proxyport="${http.proxyPort}"/>
+	</target>
 
-    <target name="prepare" depends="setproxy">
+	<target name="prepare" depends="setproxy">
 		<mkdir dir="${build_classes.dir}"/>
 		<mkdir dir="${build_lib.dir}"/>
     	
@@ -74,13 +74,13 @@
 	      </not>
 	    </condition>
     	<antcall target="get-xml-schema-tests"/>
-   </target>
+    </target>
     	
-	<target name="get-xml-schema-tests" if="needsTestsDownload">
-		<echo>Downloading 6MB XML Schema test suite. This make take a few minutes...</echo>
-		<get dest="${build.dir}/xsts-2002-01-16.tar.gz" 
-			src="http://www.w3.org/XML/2004/xml-schema-test-suite/xmlschema2002-01-16/xsts-2002-01-16.tar.gz"/>
-		<untar src="${build.dir}/xsts-2002-01-16.tar.gz" compression="gzip" dest="${build.dir}"/>
+    <target name="get-xml-schema-tests" if="needsTestsDownload">
+      <echo>Downloading 6MB XML Schema test suite. This make take a few minutes...</echo>
+      <get dest="${build.dir}/xsts-2002-01-16.tar.gz" 
+	   src="http://www.w3.org/XML/2004/xml-schema-test-suite/xmlschema2002-01-16/xsts-2002-01-16.tar.gz"/>
+      <untar src="${build.dir}/xsts-2002-01-16.tar.gz" compression="gzip" dest="${build.dir}"/>
     </target>
 
     <target name="compile" depends="prepare" description="compiles the src and puts it in build/classes">

Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/pom.xml?rev=718331&r1=718330&r2=718331&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/pom.xml (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/pom.xml Mon Nov 17 11:25:44 2008
@@ -29,7 +29,7 @@
     <version>1.4-SNAPSHOT</version>
     <description>Commons XMLSchema is a light weight schema object model that can be used to manipualte or
         generate a schema. It has a clean, easy to use API and can easily be integrated into an existing project
-        since it has almost no dependancies on third party libraries.</description>
+        since it has almost no dependencies on third party libraries.</description>
     <url>http://ws.apache.org/commons/XmlSchema</url>
     <issueManagement>
         <system>JIRA</system>
@@ -84,7 +84,7 @@
   		     the assembly plugin cannot override the filter properties (as explained
 			 in the docs) and also does not inherit the maven standard properties. This
 		     is the one that points to a seperare filter props file --> 
-		<filters>
+	<filters>
         	<filter>src/main/assembly/filter.properties</filter>
         </filters>
 
@@ -92,8 +92,14 @@
        <resources>
           <resource>
              <directory>src/main/resources</directory>
-       </resource>
-     </resources>
+	  </resource>
+       </resources>
+       <testResources>
+	  <testResource>
+	    <directory>src/test/test-resources</directory>
+	  </testResource>
+       </testResources>
+
 
         <plugins>
             <plugin>
@@ -142,10 +148,6 @@
             </plugin>
             <plugin>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <!--
-                        Required to run the TestW3CSchemaBucket test
-                        <version>2.3-SNAPSHOT</version>
-                -->
                 <configuration>
                     <includes>
                         <include>**/*Test.java</include>
@@ -223,10 +225,6 @@
         		<plugins>
         			<plugin>
         				<artifactId>maven-surefire-plugin</artifactId>
-        				<!--
-        					Required to run the TestW3CSchemaBucket test
-        					<version>2.3-SNAPSHOT</version>
-        				-->
         				<configuration>
         					<includes>
         						<include>**/*Test.java</include>
@@ -281,10 +279,6 @@
         		<plugins>
         			<plugin>
         				<artifactId>maven-surefire-plugin</artifactId>
-        				<!--
-        					Required to run the TestW3CSchemaBucket test
-        					<version>2.3-SNAPSHOT</version>
-        				-->
         				<configuration>
         					<includes>
         						<include>**/*Test.java</include>
@@ -371,7 +365,7 @@
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>jdepend-maven-plugin</artifactId>
-                <version>2.0-beta-1</version>
+                <version>2.0-beta-2</version>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>

Added: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java?rev=718331&view=auto
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java (added)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java Mon Nov 17 11:25:44 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.ws.commons.schema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Class to return a node list without thread-safety issue.
+ *
+ */
+class DocumentFragmentNodeList implements NodeList {
+	private List nodes;
+	private DocumentFragment fragment;
+	
+	/**
+	 * Construct a list of the children of a given node.
+	 * @param parentNode node from which to copy children.
+	 */
+	DocumentFragmentNodeList(Node parentNode) {
+		fragment = parentNode.getOwnerDocument().createDocumentFragment();
+		nodes = new ArrayList();
+		for(Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
+			nodes.add(fragment.appendChild(child.cloneNode(true)));
+		}
+	}
+
+	/**
+	 * Create a list of the children of a given node that are elements with a specified qualified name.
+	 * @param parentNode node from which to copy children.
+	 * @param filterUri Namespace URI of children to copy.
+	 * @param filterLocal Local name of children to copy.
+	 */
+	DocumentFragmentNodeList(Node parentNode, String filterUri, String filterLocal) {
+		fragment = parentNode.getOwnerDocument().createDocumentFragment();
+		nodes = new ArrayList();
+		for(Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
+			if(child.getNodeType() == Node.ELEMENT_NODE 
+					&& child.getNamespaceURI().equals(filterUri)
+					&& child.getLocalName().equals(filterLocal)) {
+				nodes.add(fragment.appendChild(child.cloneNode(true)));
+			}
+		}
+	}
+
+	public int getLength() {
+		return nodes.size(); 
+	}
+
+	public Node item(int index) {
+		if(nodes == null) {
+			return null;
+		} else {
+			return (Node) nodes.get(index);
+		}
+	}
+
+}

Propchange: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/DocumentFragmentNodeList.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=718331&r1=718330&r2=718331&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Mon Nov 17 11:25:44 2008
@@ -34,7 +34,9 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import java.lang.ref.SoftReference;
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -771,7 +773,7 @@
 		
 		return complexContent;
 	}
-
+	
 	private XmlSchemaSimpleContentRestriction handleSimpleContentRestriction(
 			XmlSchema schema, Element restrictionEl, Element schemaEl) {
 
@@ -805,10 +807,7 @@
 				restriction.setAnnotation(handleAnnotation(el));
 			} else {
 				XmlSchemaFacet facet = XmlSchemaFacet.construct(el);
-				NodeList annotations = el.getElementsByTagNameNS(
-						XmlSchema.SCHEMA_NS, "annotation");
-
-				if (annotations.getLength() > 0) {
+				if(XDOMUtil.anyElementsWithNameNS(el, XmlSchema.SCHEMA_NS, "annotation")) {
 					XmlSchemaAnnotation facetAnnotation = handleAnnotation(el);
 					facet.setAnnotation(facetAnnotation);
 				}
@@ -1564,7 +1563,7 @@
 	}
 
 	/**
-	 * Hanlde the import
+	 * Handle the import
 	 * @param schema
 	 * @param importEl
 	 * @param schemaEl
@@ -1734,10 +1733,9 @@
 	 */
 	XmlSchemaAppInfo handleAppInfo(Element content) {
 		XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
-		NodeList markup = getChildren(content);
+		NodeList markup = new DocumentFragmentNodeList(content);
 
-		if (!content.hasAttribute("source")
-				&& (markup == null || markup.getLength() <= 0)) {
+		if (!content.hasAttribute("source")) {
 			return null;
 		}
 		appInfo.setSource(getAttribute(content, "source"));
@@ -1748,16 +1746,16 @@
 	//iterate each documentation element, create new XmlSchemaAppinfo and add to collection
 	XmlSchemaDocumentation handleDocumentation(Element content) {
 		XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
-		NodeList markup = getChildren(content);
+		List markup = getChildren(content);
 
 		if (!content.hasAttribute("source")
 				&& !content.hasAttribute("xml:lang")
-				&& (markup == null || markup.getLength() <= 0))
+				&& markup == null)
 			return null;
 
 		documentation.setSource(getAttribute(content, "source"));
 		documentation.setLanguage(getAttribute(content, "xml:lang"));
-		documentation.setMarkup(getChildren(content));
+		documentation.setMarkup(new DocumentFragmentNodeList(content));
 
 		return documentation;
 	}
@@ -1768,11 +1766,16 @@
 		return null;
 	}
 
-	private NodeList getChildren(Element content) {
-		NodeList childs = content.getChildNodes();
-		if (childs.getLength() > 0)
-			return childs;
-		return null;
+	private List getChildren(Element content) {
+		List result = new ArrayList();
+		for(Node n = content.getFirstChild(); n != null; n = n.getNextSibling()) {
+			result.add(n);
+		}
+		if(result.size() == 0) {
+			return null;
+		} else {
+			return result;
+		}
 	}
 
 	long getMinOccurs(Element el) {

Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=718331&r1=718330&r2=718331&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Mon Nov 17 11:25:44 2008
@@ -1952,7 +1952,7 @@
         if (appInfoObj.markup != null) {
             int markupLength = appInfoObj.markup.getLength();
             for (int j = 0; j < markupLength; j++) {
-                Node n = appInfoObj.markup.item(j);
+                Node n = (Node) appInfoObj.markup.item(j);
                appInfoEl.appendChild(doc.importNode(n,true));
             }
         }
@@ -1998,7 +1998,7 @@
         if (documentationObj.markup != null) {
             int markupLength = documentationObj.markup.getLength();
             for (int j = 0; j < markupLength; j++) {
-                Node n = documentationObj.markup.item(j);
+                Node n = (Node) documentationObj.markup.item(j);
 
                 switch (n.getNodeType()) {
                     case Node.ELEMENT_NODE:

Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java?rev=718331&r1=718330&r2=718331&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java Mon Nov 17 11:25:44 2008
@@ -66,5 +66,15 @@
         return null;
 
     }
+    
+    public static boolean anyElementsWithNameNS(Element element, String uri, String name) {
+    	for (Element el = getFirstChildElementNS(element, uri); el != null; el = XDOMUtil.getNextSiblingElementNS(el, uri)) {
+    		if(el.getLocalName().equals(name) && el.getNamespaceURI().equals(uri)) {
+    			return true;
+    		}
+    	}
+    	return false;
+    }
+    
 
 }