Better support for "lightweight" PSVI, prep for heavyweight


git-svn-id: https://svn.apache.org/repos/asf/xalan/java/branches/Xalan3@336423 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xml/dtm/ref/xni2dtm/DTM2XNI.java b/src/org/apache/xml/dtm/ref/xni2dtm/DTM2XNI.java
index 95fe8dc..0fd16bf 100644
--- a/src/org/apache/xml/dtm/ref/xni2dtm/DTM2XNI.java
+++ b/src/org/apache/xml/dtm/ref/xni2dtm/DTM2XNI.java
@@ -385,8 +385,10 @@
       org.apache.xerces.xni.XMLAttributes attrs = 
                             new org.apache.xerces.util.XMLAttributesImpl();
 
-      for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
-           nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
+	  // Note that this needs to scan the namespaces declared ON THIS NODE,
+	  // *not* the ones inherited.
+      for (int nsn = m_dtm.getFirstNamespaceNode(node, false); DTM.NULL != nsn;
+           nsn = m_dtm.getNextNamespaceNode(node, nsn, false))
       {
         String nsprefix = m_dtm.getLocalName(nsn); //xmlns:whatever
         	
@@ -522,8 +524,8 @@
 				m_dtm.getNodeName(node),ns);
       m_XMLDocumentHandler.endElement(qq,null);
 
-      for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
-           nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
+      for (int nsn = m_dtm.getFirstNamespaceNode(node, false); DTM.NULL != nsn;
+           nsn = m_dtm.getNextNamespaceNode(node, nsn, false))
       {
         // String prefix = m_dtm.getPrefix(nsn);
         String prefix = m_dtm.getNodeNameX(nsn);
diff --git a/src/org/apache/xml/dtm/ref/xni2dtm/FuncValidate.java b/src/org/apache/xml/dtm/ref/xni2dtm/FuncValidate.java
index d5ad16f..6812327 100644
--- a/src/org/apache/xml/dtm/ref/xni2dtm/FuncValidate.java
+++ b/src/org/apache/xml/dtm/ref/xni2dtm/FuncValidate.java
@@ -30,11 +30,19 @@
 		DTM sourceDTM=proxy.getDTM();
 		int sourceHandle=proxy.getDTMNodeNumber();
 		DTMManager dtmmgr=((DTMDefaultBase)sourceDTM).getManager();
-		
-		DTM2XNI d2x=new DTM2XNI(sourceDTM,sourceHandle);
-		XNISource xsrc=new XNISource(d2x,null);
+
+		// Set up an XNI scanner to read from the source DTM,
+		// run that through validation (operates as a filter?),
+		// and pass that into Xalan to produce a new document
 		// %REVIEW% system ID???
-			
+		DTM2XNI d2x=new DTM2XNI(sourceDTM,sourceHandle);
+		
+		// VALIDATION GOES HERE!
+		// Sandy Gao recommends "create a customized parser configuration,
+		// which contains an XNI event source, a validator, and (optionally)
+		// a document handler." See "pipelines" in the XNI docs.
+		
+		XNISource xsrc=new XNISource(d2x,null);
 		DTM newDTM=dtmmgr.getDTM(xsrc,
 			true, // unique
 			null, // whitespace filter
diff --git a/src/org/apache/xml/dtm/ref/xni2dtm/XNI2DTM.java b/src/org/apache/xml/dtm/ref/xni2dtm/XNI2DTM.java
index 9288ef2..6b75daa 100644
--- a/src/org/apache/xml/dtm/ref/xni2dtm/XNI2DTM.java
+++ b/src/org/apache/xml/dtm/ref/xni2dtm/XNI2DTM.java
@@ -104,9 +104,8 @@
  * 
  * Please note that it this is a PROTOTYPE, since the Xerces post-schema 
  * validation infoset (PSVI) APIs it is using are themselves prototypes and
- * subject to change without warning. Also note that currently Xerces only
- * implements a subset of the "light weight" PSVI, whereas the official
- * XPath2 data model requires the heavyweight version. 
+ * subject to change without warning. The most recent such change was from
+ * "lightweight" to "heavyweight" schema models.
  * 
  * This version is derived from SAX2DTM for ease of implementation and
  * support, but deliberately blocks external access to
@@ -1783,6 +1782,10 @@
   	 * */
   	public boolean equals(XPath2Type other)
   	{
+		// Could cache hashCode()'s result and use that to accelerate
+		// doesn't-equal testing at the cost of some storage and
+		// slowing down does-equal tests. Not convinced it's useful here.
+		// %REVIEW%
   		return (m_xniType==other.m_xniType ||
   			m_xniType!=null && m_xniType.equals(other.m_xniType)) &&
   			// These two won't be null
@@ -1795,6 +1798,8 @@
   	 * */
   	public int hashCode()
   	{
+  		// Could cache hashCode(). See discussion in equals().
+  		// %REVIEW%
   		return m_namespace.hashCode()+m_localName.hashCode()+
   			(m_xniType==null ? 0 : m_xniType.hashCode());
   	}
@@ -1888,7 +1893,8 @@
    * */  
   protected void heavyResolveTypeName(ItemPSVI psvi, boolean attr)
   {
-  /*
+  	/* Not compatable with old light-weight schema APIs
+
   	// NAME OF THIS CONSTANT IS IN FLUX
   	//int VALID=ItemPSVI.VALIDITY_VALID;
   	int VALID=ItemPSVI.VALID_VALIDITY;
@@ -1926,7 +1932,7 @@
         m_namespace = "http://www.w3.org/2001/XMLSchema";
         m_localName = attr ? "anySimpleType" : "anyType";
         return;
-  */ throw new java.lang.UnsupportedOperationException("Xerces Heavyweight not yet available");
+  */ throw new java.lang.UnsupportedOperationException("Xerces Heavyweight PSVI not yet avaialble"); /**/       
   }
   
   /** Modification of the XPath2 type-name resolution algorithm
@@ -1943,7 +1949,8 @@
    * */  
   protected void proposedHeavyResolveTypeName(ItemPSVI psvi, boolean attr)
   {
-  /*
+  	/* Not compatable with old light-weight schema APIs
+
   	// NAME OF THIS CONSTANT IS IN FLUX
   	//int VALID=ItemPSVI.VALIDITY_VALID;
   	int VALID=ItemPSVI.VALID_VALIDITY;
@@ -1980,7 +1987,7 @@
         m_namespace = "http://www.w3.org/2001/XMLSchema";
         m_localName = attr ? "anySimpleType" : "anyType";
         return;
-  */ throw new java.lang.UnsupportedOperationException("Xerces Heavyweight not yet available");
+  */ throw new java.lang.UnsupportedOperationException("Xerces Heavyweight PSVI not yet avaialble"); /**/       
   }
   
   /** Attempt to write a simplified version of the type resolution
@@ -1999,8 +2006,9 @@
    * */  
   protected void lightResolveTypeName(ItemPSVI psvi, boolean attr)
   {
-  	// NAME OF THIS CONSTANT IS IN FLUX
-  	//int VALID=ItemPSVI.VALIDITY_VALID;
+  	/* Not compatable with new heavy-weight schema APIs
+  	*/
+  	
   	int VALID=ItemPSVI.VALID_VALIDITY;
   	
         // check whether the node is valid
@@ -2033,6 +2041,7 @@
         m_namespace = "http://www.w3.org/2001/XMLSchema";
         m_localName = attr ? "anySimpleType" : "anyType";
         return;
+  // throw new java.lang.UnsupportedOperationException("Xerces Lightweight PSVI phased out"); /**/
   }
   } // XPath2Type
 } // XNI2DTM