Author: mukulg
Date: Sat Sep 25 10:03:57 2010
New Revision: 1001182
URL: http://svn.apache.org/viewvc?rev=1001182&view=rev
Log:
I think it's good if we provide an option to debug Xerces schema 1.1 assertion
calls, like for example printing serialized DOM trees used for assertion
evaluations. This commit provides this improvement. I personally find this
useful for our internal use.
The assert debug feature can be invoked by setting a JVM system property as
following:
-Dorg.apache.xerces.schema11.assertDebug=true
This could be later removed from Xerces schema 1.1 implementation if so decided.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=1001182&r1=1001181&r2=1001182&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
Sat Sep 25 10:03:57 2010
@@ -64,6 +64,10 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
/**
* Class implementing an XPath interface, for XML Schema 1.1 "assertions"
@@ -114,6 +118,10 @@ public class XMLAssertPsychopathImpl ext
// an instance variable to track the name of an attribute currently
// been processed for assertions.
String fAttrName = null;
+
+ // an instance variable, used for optional debugging of assertion
+ // evaluations.
+ String fAssertDebug = null;
/*
@@ -124,7 +132,9 @@ public class XMLAssertPsychopathImpl ext
this.fAssertDocument = new PSVIDocumentImpl();
this.fAssertRootStack = new Stack();
this.fAssertListStack = new Stack();
- this.fAssertParams = assertParams;
+ this.fAssertParams = assertParams;
+ this.fAssertDebug = System.getProperty
+ ("org.apache.xerces.schema11.assertDebug");
}
@@ -238,7 +248,12 @@ public class XMLAssertPsychopathImpl ext
List assertions = (List) fAssertListStack.pop();
Boolean atomicValueValidity = (Boolean) augs.getItem
("ATOMIC_VALUE_VALIDITY");
- if (atomicValueValidity.booleanValue()) {
+ if (atomicValueValidity.booleanValue()) {
+ // an optional debugging call
+ if ("true".equals(fAssertDebug)) {
+ debugAsserts();
+ }
+
// depending on simple content's validity status from
// XMLSchemaValidator, process XML schema assertions.
processAllAssertionsOnElement(element, itemType,
@@ -254,6 +269,32 @@ public class XMLAssertPsychopathImpl ext
}
} // endElement
+
+
+ /*
+ * Debug assertion calls. For example, serialize assertion DOM trees.
+ */
+ private void debugAsserts() {
+
+ DOMImplementationRegistry registry = null;
+ try {
+ registry = DOMImplementationRegistry.newInstance();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ DOMImplementationLS impl = (DOMImplementationLS) registry.
+ getDOMImplementation("LS");
+ LSSerializer writer = impl.createLSSerializer();
+ writer.getDomConfig().setParameter("format-pretty-print",
+ Boolean.TRUE);
+ LSOutput output = impl.createLSOutput();
+ output.setEncoding("UTF-8");
+ output.setByteStream(System.out);
+ System.out.println("<- assert DOM Tree ->");
+ writer.write(fCurrentAssertDomNode, output);
+ System.out.println("<--->");
+
+ } // debugAsserts
/*
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]