Author: mukulg
Date: Tue Nov 17 00:06:28 2009
New Revision: 881066
URL: http://svn.apache.org/viewvc?rev=881066&view=rev
Log:
improving assertions runtime evaluation performance, by optimizing XPath
expression storage.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
Tue Nov 17 00:06:28 2009
@@ -106,7 +106,7 @@
cvc-type.3.1.2 = cvc-type.3.1.2: Element ''{0}'' is a simple type, so
it must have no element information item [children].
cvc-type.3.1.3 = cvc-type.3.1.3: The value ''{1}'' of element ''{0}''
is not valid.
cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation
(''{1}'') for element ''{0}'' with type ''{2}'' did not succeed.
- cvc-xpath.3.13.4.2 = cvc-xpath.3.13.4.2: Assertion evaluation
(''{1}'') for element ''{0}'' with type ''{2}'' did not succeed.
+ cvc-xpath.3.13.4.2 = cvc-xpath.3.13.4.2: Assertion XPath expression,
(''{0}'') on the Schema type (''{1}'') couldn''t compile successfully.
#schema valid (3.X.3)
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
Tue Nov 17 00:06:28 2009
@@ -20,18 +20,24 @@
import java.util.Enumeration;
import java.util.Map;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
+import org.apache.xerces.impl.xs.traversers.XSDHandler;
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.xs.XSModel;
+import org.apache.xerces.xs.XSTypeDefinition;
import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
import org.eclipse.wst.xml.xpath2.processor.Evaluator;
+import org.eclipse.wst.xml.xpath2.processor.JFlexCupParser;
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
import org.eclipse.wst.xml.xpath2.processor.StaticChecker;
import org.eclipse.wst.xml.xpath2.processor.StaticError;
import org.eclipse.wst.xml.xpath2.processor.StaticNameResolver;
+import org.eclipse.wst.xml.xpath2.processor.XPathParser;
+import org.eclipse.wst.xml.xpath2.processor.XPathParserException;
import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
import org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary;
import org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary;
@@ -56,13 +62,17 @@
private DynamicContext fDynamicContext = null;
private Document domDoc = null;
+ /*
+ * Initialize the PsychoPath XPath 2 dynamic context
+ */
protected DynamicContext initDynamicContext(XSModel schema,
Document document,
Map psychoPathParams) {
fDynamicContext = new DefaultDynamicContext(schema, document);
+
// populate the PsychoPath XPath 2.0 static context, with namespace
bindings
- // derived from the XSD Schema
+ // derived from the XSD Schema document
NamespaceSupport xpath2NamespaceContext = (NamespaceSupport)
psychoPathParams.get("XPATH2_NS_CONTEXT");
Enumeration currPrefixes = xpath2NamespaceContext.getAllPrefixes();
while (currPrefixes.hasMoreElements()) {
@@ -70,6 +80,7 @@
String uri = xpath2NamespaceContext.getURI(prefix);
fDynamicContext.add_namespace(prefix, uri);
}
+
fDynamicContext.add_function_library(new FnFunctionLibrary());
fDynamicContext.add_function_library(new XSCtrLibrary());
domDoc = document;
@@ -77,6 +88,9 @@
return fDynamicContext;
} //initDynamicContext
+ /*
+ * Evaluate XPath expression with PsychoPath engine
+ */
protected boolean evaluatePsychoPathExpr(XPath xp,
String xPathDefaultNamespace,
Element contextNode)
@@ -119,4 +133,43 @@
return result;
} //evaluatePsychoPathExpr
+ /*
+ * Compile the XPath string, and return the compiled XPath expression
+ */
+ protected XPath compileXPathStr(String xpathStr,
+ XSAssertImpl assertImpl,
+ XSDHandler fSchemaHandler) {
+ XPathParser xpp = new JFlexCupParser();
+ XPath xp = null;
+
+ try {
+ xp = xpp.parse("boolean(" + xpathStr + ")");
+ } catch (XPathParserException ex) {
+ // error compiling XPath expression
+ reportError("cvc-xpath.3.13.4.2", assertImpl, fSchemaHandler);
+ }
+
+ return xp;
+ }
+
+ /*
+ * Method to report error messages
+ */
+ private void reportError(String key, XSAssertImpl assertImpl,
+ XSDHandler fSchemaHandler) {
+ XSTypeDefinition typeDef = assertImpl.getTypeDefinition();
+ String typeString = "";
+
+ if (typeDef != null) {
+ typeString = (typeDef.getName() != null) ? typeDef.getName() :
"#anonymous";
+ }
+ else {
+ typeString = "#anonymous";
+ }
+
+ fSchemaHandler.reportSchemaError(key, new Object[] {
+ assertImpl.getTest().getXPath().toString(),
+ typeString }, null);
+ }
+
} //AbstractPsychoPathImpl
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=881066&r1=881065&r2=881066&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
Tue Nov 17 00:06:28 2009
@@ -36,9 +36,6 @@
import org.apache.xerces.xs.XSObjectList;
import org.apache.xerces.xs.XSTypeDefinition;
import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
-import org.eclipse.wst.xml.xpath2.processor.JFlexCupParser;
-import org.eclipse.wst.xml.xpath2.processor.XPathParser;
-import org.eclipse.wst.xml.xpath2.processor.XPathParserException;
import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
import org.w3c.dom.Document;
@@ -82,16 +79,17 @@
// itself.
XMLSchemaValidator validator = null;
+ // parameters to pass to PsychoPath engine (like, namespace bindings)
Map assertParams = null;
/*
* The class constructor
*/
public XMLAssertPsychopathImpl(Map assertParams) {
- // initializing the class variables
+ // initializing the class variables.
// we use the PSVI enabled DOM implementation, so as to have typed
// XDM nodes.
- this.assertDocument = new PSVIDocumentImpl();
+ this.assertDocument = new PSVIDocumentImpl();
this.assertRootStack = new Stack();
this.assertListStack = new Stack();
this.assertParams = assertParams;
@@ -178,8 +176,11 @@
if (!assertRootStack.empty() && (currentAssertDomNode ==
assertRootStack.peek())) {
// get XSModel
fSchema =
((PSVIElementNSImpl)currentAssertDomNode).getSchemaInformation();
- assertRootStack.pop(); // pop the stack, to go one level up
- Object assertions = assertListStack.pop(); // get assertions,
and go one level up
+
+ // pop the stack, to go one level up
+ assertRootStack.pop();
+ // get assertions, and go one level up
+ Object assertions = assertListStack.pop();
// initialize the XPath engine
initXPathProcessor();
@@ -222,21 +223,11 @@
}
/*
- * Method to evaluate an assertion, XPath expression
+ * Method to evaluate an assertions, XPath expression
*/
private void evaluateAssertion(QName element, XSAssertImpl assertImpl) {
-
- XPathParser xpp = new JFlexCupParser();
- XPath xp = null;
- try {
- xp = xpp.parse("boolean("
- + assertImpl.getTest().getXPath().toString() + ")");
- } catch (XPathParserException ex) {
- // error compiling XPath expression
- reportError("cvc-xpath.3.13.4.2", element, assertImpl);
- }
-
- try {
+ try {
+ XPath xp = assertImpl.getCompiledXPath();
boolean result = abstrPsychopathImpl.evaluatePsychoPathExpr(xp,
assertImpl.getXPathDefaultNamespace(),
currentAssertDomNode);
@@ -248,23 +239,24 @@
} catch (Exception ex) {
reportError("cvc-assertion.3.13.4.1", element, assertImpl);
}
-
}
-
+
/*
- * Method to report assertions error messages
+ * Method to report error messages
*/
private void reportError(String key, QName element, XSAssertImpl
assertImpl) {
XSTypeDefinition typeDef = assertImpl.getTypeDefinition();
String typeString = "";
+
if (typeDef != null) {
typeString = (typeDef.getName() != null) ? typeDef.getName() :
"#anonymous";
}
else {
typeString = "#anonymous";
}
+
validator.reportSchemaError(key, new Object[] { element.rawname,
assertImpl.getTest().getXPath().toString(),
- typeString });
+ typeString } );
}
}
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
Tue Nov 17 00:06:28 2009
@@ -809,7 +809,7 @@
/*
- * Helper method to initialize the assertion processor
+ * Method initializing the assertions processor.
*
* @param assertParams Parameters that are passed, to the assertions
processor
*/
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
Tue Nov 17 00:06:28 2009
@@ -20,10 +20,8 @@
import java.util.HashMap;
import java.util.Map;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
+import org.apache.xerces.dom.PSVIAttrNSImpl;
+import org.apache.xerces.dom.PSVIDocumentImpl;
import org.apache.xerces.impl.xpath.XPath20;
import org.apache.xerces.impl.xs.AbstractPsychoPathImpl;
import org.apache.xerces.util.NamespaceSupport;
@@ -58,7 +56,8 @@
protected NamespaceSupport fXPath2NamespaceContext = null;
/** Constructs a "test" for type alternatives */
- public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative,
NamespaceSupport namespaceContext) {
+ public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative,
+ NamespaceSupport namespaceContext) {
fXPath = xpath;
fTypeAlternative = typeAlternative;
fXPath2NamespaceContext = namespaceContext;
@@ -68,7 +67,8 @@
* Constructs a "test" for type alternatives. An overloaded constructor,
* for PsychoPath XPath processor.
*/
- public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative,
NamespaceSupport namespaceContext) {
+ public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative,
+ NamespaceSupport namespaceContext) {
fXPathPsychoPath = xpath;
fTypeAlternative = typeAlternative;
fXPath2NamespaceContext = namespaceContext;
@@ -119,16 +119,20 @@
boolean result = false;
try {
- // construct a DOM document (an XPath XDM instance), for XPath
evaluation
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
- Document document = docBuilder.newDocument();
-
+ // construct a DOM document (used by psychopath engine as XPath XDM
+ // instance). A PSVI DOM is constructed, to comply to PsychoPath
+ // architecture. This doesn't seem to affect CTA psychopath
evaluations.
+ // CTA spec, doesn't require a typed XDM tree.
+ // relook...
+ Document document = new PSVIDocumentImpl();
+
Element elem = document.createElementNS(element.uri, element.rawname);
- for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++)
{
- elem.setAttributeNS(attributes.getURI(attrIndx),
- attributes.getQName(attrIndx),
- attributes.getValue(attrIndx));
+ for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++)
{
+ PSVIAttrNSImpl attrNode = new
PSVIAttrNSImpl((PSVIDocumentImpl)document,
+
attributes.getURI(attrIndx),
+
attributes.getQName(attrIndx));
+ attrNode.setNodeValue(attributes.getValue(attrIndx));
+ elem.setAttributeNode(attrNode);
}
document.appendChild(elem);
@@ -141,8 +145,6 @@
result = evaluatePsychoPathExpr(fXPathPsychoPath,
fTypeAlternative.fXPathDefaultNamespace,
elem);
- } catch(ParserConfigurationException ex) {
- result = false;
} catch (StaticError ex) {
result = false;
} catch(DynamicError ex) {
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
Tue Nov 17 00:06:28 2009
@@ -17,12 +17,15 @@
package org.apache.xerces.impl.xs.assertion;
+import org.apache.xerces.impl.xs.AbstractPsychoPathImpl;
+import org.apache.xerces.impl.xs.traversers.XSDHandler;
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.xs.XSAssert;
import org.apache.xerces.xs.XSConstants;
import org.apache.xerces.xs.XSNamespaceItem;
import org.apache.xerces.xs.XSObjectList;
import org.apache.xerces.xs.XSTypeDefinition;
+import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
/**
* XML Schema 1.1 'assertion' component.
@@ -32,14 +35,17 @@
* @author Mukul Gandhi, IBM
* @version $Id$
*/
-public class XSAssertImpl implements XSAssert {
+public class XSAssertImpl extends AbstractPsychoPathImpl implements XSAssert {
/** The type definition associated with the assertion component */
protected XSTypeDefinition fTypeDefinition;
- /** An XPath 2.0 expression that represents the assert 'test' attribute */
+ /** Xerces object representing the assert 'test' attribute */
protected Test fTestExpr = null;
+ /** Compiled XPath 2.0 expression */
+ protected XPath fCompiledXPath = null;
+
/** Optional annotations */
protected XSObjectList fAnnotations = null;
@@ -48,18 +54,27 @@
/** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD
traversers. */
protected NamespaceSupport fXPath2NamespaceContext = null;
+
+ // XSDHandler object, passed on from the tarversers
+ protected XSDHandler fSchemaHandler = null;
/** Constructor */
public XSAssertImpl(XSTypeDefinition type,
- XSObjectList annotations) {
- // An assert component must correspond to a type
+ XSObjectList annotations, XSDHandler schemaHandler) {
+ // An assert component must correspond to a schema type
fTypeDefinition = type;
+
+ fSchemaHandler = schemaHandler;
fAnnotations = annotations;
}
/** Sets the test attribute value */
public void setTest(Test expr) {
- fTestExpr = expr;
+ fTestExpr = expr;
+ // compile the XPath string, into an object
+ fCompiledXPath = compileXPathStr(expr.toString(),
+ this,
+ fSchemaHandler);
}
/** Sets the assertion annotations */
@@ -84,6 +99,10 @@
public String getTestStr() {
return fTestExpr.toString();
}
+
+ public XPath getCompiledXPath() {
+ return fCompiledXPath;
+ }
public Test getTest() {
return fTestExpr;
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
Tue Nov 17 00:06:28 2009
@@ -493,7 +493,9 @@
}
// create an assertion object
- XSAssertImpl assertImpl = new XSAssertImpl(typeDef,
annotations);
+ XSAssertImpl assertImpl = new XSAssertImpl(typeDef,
+ annotations,
+ fSchemaHandler);
Test testExpr = new Test(new XPath20Assert(test,
fSymbolTable,
schemaDoc.fNamespaceSupport),
assertImpl);
assertImpl.setTest(testExpr);
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
Tue Nov 17 00:06:28 2009
@@ -1591,7 +1591,9 @@
}
// create an assertion object
- XSAssertImpl assertImpl = new XSAssertImpl(enclosingCT,
annotations);
+ XSAssertImpl assertImpl = new XSAssertImpl(enclosingCT,
+ annotations,
+ fSchemaHandler);
Test testExpr = new Test(new XPath20Assert(test, fSymbolTable,
schemaDoc.fNamespaceSupport),
assertImpl);
assertImpl.setTest(testExpr);
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java?rev=881066&r1=881065&r2=881066&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
Tue Nov 17 00:06:28 2009
@@ -68,7 +68,6 @@
import org.apache.xerces.util.XMLSymbols;
import org.apache.xerces.util.URI.MalformedURIException;
import org.apache.xerces.xni.QName;
-import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
@@ -2828,7 +2827,7 @@
return false;
}
- void reportSchemaError(String key, Object[] args, Element ele) {
+ public void reportSchemaError(String key, Object[] args, Element ele) {
reportSchemaError(key, args, ele, null);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]