Author: mukulg
Date: Thu Mar 24 09:12:21 2011
New Revision: 1084884
URL: http://svn.apache.org/viewvc?rev=1084884&view=rev
Log:
doing minor corrections to schema 1.1 assertions codebase and minor refactoring.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.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
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java?rev=1084884&r1=1084883&r2=1084884&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java
Thu Mar 24 09:12:21 2011
@@ -22,9 +22,9 @@ import java.util.Map;
import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
import org.apache.xerces.impl.xs.traversers.XSDHandler;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
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;
@@ -49,7 +49,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
- * A base class providing common services for XPath expression evaluation,
with 'PsychoPath XPath 2.0' engine.
+ * A class providing common services for XPath expression evaluation, with
'PsychoPath XPath 2.0' engine.
*
* @xerces.internal
*
@@ -59,11 +59,10 @@ import org.w3c.dom.Element;
public class AbstractPsychoPathXPath2Impl {
private DynamicContext fXpath2DynamicContext = null;
- private Document domDoc = null;
- private static final String XPATH_EXPR_COMPILE_ERR_MESG_1 = "Expression
starts with / or //";
+ private Document fDomDoc = null;
/*
- * Initialize the 'PsychoPath XPath 2' dynamic context.
+ * Initialize the "PsychoPath XPath 2" dynamic context.
*/
protected DynamicContext initDynamicContext(XSModel schema, Document
document, Map psychoPathParams) {
@@ -76,11 +75,10 @@ public class AbstractPsychoPathXPath2Imp
String prefix = (String)currPrefixes.nextElement();
String uri = xpath2NamespaceContext.getURI(prefix);
fXpath2DynamicContext.add_namespace(prefix, uri);
- }
-
+ }
fXpath2DynamicContext.add_function_library(new FnFunctionLibrary());
fXpath2DynamicContext.add_function_library(new XSCtrLibrary());
- domDoc = document;
+ fDomDoc = document;
return fXpath2DynamicContext;
@@ -90,41 +88,37 @@ public class AbstractPsychoPathXPath2Imp
/*
* Evaluate XPath expression with PsychoPath XPath2 engine.
*/
- protected boolean evaluateXPathExpr(XPath xp, Element contextNode) throws
StaticError, DynamicError, Exception {
+ protected boolean evaluateXPathExpr(XPath xpathObject, Element
contextNode) throws StaticError, DynamicError, Exception {
StaticChecker sc = new StaticNameResolver(fXpath2DynamicContext);
- sc.check(xp);
-
- Evaluator eval = null;
+ sc.check(xpathObject);
+ Evaluator xpath2Evaluator = null;
if (contextNode != null) {
- eval = new DefaultEvaluator(fXpath2DynamicContext, domDoc);
- // change focus to the top most element
- ResultSequence contextNodeResultSet =
ResultSequenceFactory.create_new();
- contextNodeResultSet.add(new ElementType(contextNode,
fXpath2DynamicContext.node_position(contextNode)));
- fXpath2DynamicContext.set_focus(new Focus(contextNodeResultSet));
+ xpath2Evaluator = new DefaultEvaluator(fXpath2DynamicContext,
fDomDoc);
+ // change focus to the top most element
+ ResultSequence contextNodeResultSet =
ResultSequenceFactory.create_new();
+ contextNodeResultSet.add(new ElementType(contextNode,
fXpath2DynamicContext.node_position(contextNode)));
+ fXpath2DynamicContext.set_focus(new Focus(contextNodeResultSet));
}
else {
- eval = new DefaultEvaluator(fXpath2DynamicContext, null);
+ xpath2Evaluator = new DefaultEvaluator(fXpath2DynamicContext, null);
}
- ResultSequence rs = eval.evaluate(xp);
+ ResultSequence resultSeq = xpath2Evaluator.evaluate(xpathObject);
boolean result = false;
-
- if (rs == null) {
- result = false;
+ if (resultSeq == null) {
+ result = false;
+ } else if (resultSeq.size() == 1) {
+ AnyType rsReturn = resultSeq.get(0);
+ if (rsReturn instanceof XSBoolean) {
+ XSBoolean returnResultBool = (XSBoolean) rsReturn;
+ result = returnResultBool.value();
+ } else {
+ result = false;
+ }
} else {
- if (rs.size() == 1) {
- AnyType rsReturn = rs.get(0);
- if (rsReturn instanceof XSBoolean) {
- XSBoolean returnResultBool = (XSBoolean) rsReturn;
- result = returnResultBool.value();
- } else {
- result = false;
- }
- } else {
- result = false;
- }
+ result = false;
}
return result;
@@ -137,14 +131,14 @@ public class AbstractPsychoPathXPath2Imp
*/
protected XPath compileXPathStr(String xpathStr, XSAssertImpl assertImpl,
XSDHandler fSchemaHandler, Element schemaContextElem) {
- XPathParser xpp = new JFlexCupParser();
- XPath xp = null;
+ XPathParser xpathParser = new JFlexCupParser();
+ XPath xpathObject = null;
try {
- xp = xpp.parse("boolean(" + xpathStr + ")", true);
+ xpathObject = xpathParser.parse("boolean(" + xpathStr + ")", true);
} catch (XPathParserException ex) {
// error compiling XPath expression
- if (XPATH_EXPR_COMPILE_ERR_MESG_1.equals(ex.getMessage())) {
+ if
(SchemaSymbols.ASSERT_XPATHEXPR_COMPILE_ERR_MESG_1.equals(ex.getMessage())) {
reportError("cvc-xpath.3.13.4.2b", assertImpl, fSchemaHandler,
schemaContextElem);
}
else {
@@ -152,7 +146,7 @@ public class AbstractPsychoPathXPath2Imp
}
}
- return xp;
+ return xpathObject;
} // compileXPathStr
@@ -160,20 +154,8 @@ public class AbstractPsychoPathXPath2Imp
/*
* Method to report error messages.
*/
- private void reportError(String key, XSAssertImpl assertImpl, XSDHandler
fSchemaHandler, Element schemaContextElem) {
-
- 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}, schemaContextElem);
-
+ private void reportError(String key, XSAssertImpl assertImpl, XSDHandler
fSchemaHandler, Element schemaContextElem) {
+ fSchemaHandler.reportSchemaError(key, new Object[]
{assertImpl.getTest().getXPath().toString(),
XSTypeHelper.getSchemaTypeName(assertImpl.getTypeDefinition())},
schemaContextElem);
} // reportError
} // class AbstractPsychoPathXPath2Impl
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java?rev=1084884&r1=1084883&r2=1084884&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
Thu Mar 24 09:12:21 2011
@@ -253,5 +253,11 @@ public final class SchemaSymbols {
// maxOccurs = "unbounded"
public static final int OCCURRENCE_UNBOUNDED = -1;
+
+ // a placeholder definition used for assertions error messages
+ public static final String ASSERT_ERRORMSG_PLACEHOLDER_REGEX =
"\\{\\$value\\}";
+
+ // compile error message string when an assert XPath expression starts
with tokens '/' or '//'.
+ public static final String ASSERT_XPATHEXPR_COMPILE_ERR_MESG_1 =
"Expression starts with / or //";
}
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java?rev=1084884&r1=1084883&r2=1084884&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
Thu Mar 24 09:12:21 2011
@@ -75,9 +75,15 @@ public class XMLAssertPsychopathXPath2Im
// class fields declarations
+ // XSModel instance representing the schema information needed by
PsychoPath XPath 2.0 engine
+ private XSModel fSchemaXSmodel = null;
+
+ // XPath 2.0 dynamic context reference
private DynamicContext fXpath2DynamicContext;
- private XSModel fSchema = null;
+
+ // reference to the PsychoPath XPath evaluator
private AbstractPsychoPathXPath2Impl fAbstrPsychopathImpl = null;
+
// the DOM root of assertions tree
private Document fAssertDocument = null;
@@ -87,17 +93,14 @@ public class XMLAssertPsychopathXPath2Im
// a stack holding the DOM roots for assertions evaluation
private Stack fAssertRootStack = null;
- // a stack parallel to 'assertRootStack' storing all assertions for a
single XDM tree
+ // a stack parallel to 'fAssertRootStack' storing all assertions for a
single XDM tree
private Stack fAssertListStack = null;
- // XMLSchemaValidator reference. set from the XMLSchemaValidator object
itself
+ // XMLSchemaValidator reference. set from the XMLSchemaValidator object
itself.
private XMLSchemaValidator fXmlSchemaValidator = null;
- // parameters to pass to PsychoPath engine (like, the XML namespace
bindings)
+ // parameters to pass to PsychoPath XPath engine (for e.g, the XML
namespace bindings)
private Map fAssertParams = null;
-
- // a placeholder definition used for assertions error messages
- private final String ERROR_PLACEHOLDER_REGEX = "\\{\\$value\\}";
/*
@@ -118,7 +121,7 @@ public class XMLAssertPsychopathXPath2Im
private void initXPathProcessor() throws Exception {
fXmlSchemaValidator = (XMLSchemaValidator)
getProperty("http://apache.org/xml/properties/assert/validator");
fAbstrPsychopathImpl = new AbstractPsychoPathXPath2Impl();
- fXpath2DynamicContext =
fAbstrPsychopathImpl.initDynamicContext(fSchema, fAssertDocument,
fAssertParams);
+ fXpath2DynamicContext =
fAbstrPsychopathImpl.initDynamicContext(fSchemaXSmodel, fAssertDocument,
fAssertParams);
} // initXPathProcessor
@@ -227,7 +230,7 @@ public class XMLAssertPsychopathXPath2Im
if (!fAssertRootStack.empty() && (fCurrentAssertDomNode ==
fAssertRootStack.peek())) {
// get XSModel instance
- fSchema = ((PSVIElementNSImpl)
fCurrentAssertDomNode).getSchemaInformation();
+ fSchemaXSmodel = ((PSVIElementNSImpl)
fCurrentAssertDomNode).getSchemaInformation();
// pop the assertion root stack to go one level up
fAssertRootStack.pop();
// get assertions from the stack, and pass on to the
assertions evaluator
@@ -243,8 +246,8 @@ public class XMLAssertPsychopathXPath2Im
/*
- * Method to evaluate all of XML schema 1.1 assertions for an element
tree. This is the root method which evaluates
- * all XML schema assertions in an XML instance validation episode.
+ * Method to evaluate all of XML Schema 1.1 assertions for an element
tree. This is the root method which evaluates
+ * all XML Schema assertions in an XML instance validation episode.
*/
private void processAllAssertionsOnElement(QName element, List assertions,
Augmentations augs) throws Exception {
@@ -493,16 +496,16 @@ public class XMLAssertPsychopathXPath2Im
AssertionError assertionError = null;
try {
- XPath xp = assertImpl.getCompiledXPath();
+ XPath xpathObject = assertImpl.getCompiledXPathExpr();
boolean result;
if ((value == null) ||
(xPathContextExists == true)) {
- result = fAbstrPsychopathImpl.evaluateXPathExpr(xp,
fCurrentAssertDomNode);
+ result = fAbstrPsychopathImpl.evaluateXPathExpr(xpathObject,
fCurrentAssertDomNode);
}
else {
// XPath context is "undefined"
- result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, null);
+ result = fAbstrPsychopathImpl.evaluateXPathExpr(xpathObject,
null);
}
if (!result) {
@@ -636,7 +639,7 @@ public class XMLAssertPsychopathXPath2Im
if (message != null) {
// substitute all placeholder macro instances of "{$value}" with
atomic value stored in variable "value"
if (value != null && !"".equals(value)) {
- message = message.replaceAll(ERROR_PLACEHOLDER_REGEX, value);
+ message =
message.replaceAll(SchemaSymbols.ASSERT_ERRORMSG_PLACEHOLDER_REGEX, value);
}
if (!message.endsWith(".")) {
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java?rev=1084884&r1=1084883&r2=1084884&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
Thu Mar 24 09:12:21 2011
@@ -347,17 +347,4 @@ public class XSDAssertionValidator {
} // initializeAssertProcessor
-
- /*
- * Copy assertion attributes (from object assertA to assertB).
- */
- private void copyAssertAttributes(XSAssertImpl assertA, XSAssertImpl
assertB) {
- assertB.setAssertKind(assertA.getAssertKind());
- assertB.setTest(assertA.getTest(), null);
- assertB.setCompiledExpr(assertA.getCompiledXPath());
- assertB.setXPathDefaultNamespace(assertA.getXPathDefaultNamespace());
- assertB.setXPath2NamespaceContext(assertA.getXPath2NamespaceContext());
- assertB.setMessage(assertA.getMessage());
- } // copyAssertAttributes
-
} // class XSDAssertionValidator
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=1084884&r1=1084883&r2=1084884&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
Thu Mar 24 09:12:21 2011
@@ -51,7 +51,7 @@ public class Test extends AbstractPsycho
/** XPath 2.0 expression. Xerces-J native XPath 2.0 subset. */
protected final XPath20 fXPath;
- /** XPath 2.0 expression. PsychoPath XPath 2.0 expression. */
+ /** XPath 2.0 expression. PsychoPath XPath 2.0 expression object. */
protected final XPath fXPathPsychoPath;
/** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD
traversers. */
@@ -79,10 +79,10 @@ public class Test extends AbstractPsycho
return fTypeAlternative;
}
- /*
- * Returns the test XPath expression object. Return the native Xerces
XPath object or the PsychoPath XPath object,
- * whichever is available.
- */
+ /*
+ * Returns the test XPath expression object. Return the native Xerces
XPath object or the PsychoPath XPath object,
+ * whichever is available.
+ */
public Object getXPath() {
Object xpath = null;
@@ -100,7 +100,7 @@ public class Test extends AbstractPsycho
if (fXPath != null) {
return fXPath.evaluateTest(element, attributes);
} else if (fXPathPsychoPath != null) {
- return evaluateTestExprWithPsychoPath(element, attributes);
+ return evaluateTestExprWithPsychoPathEngine(element, attributes);
}
else {
return false;
@@ -112,18 +112,17 @@ public class Test extends AbstractPsycho
}
/*
- * Evaluate the XPath "test" expression on an XDM instance, consisting of
the specified element
- * and its attributes. Uses PsychoPath XPath 2.0 engine for the
evaluation.
+ * Evaluate the XPath "test" expression on an XDM instance, consisting of
the specified element and its attributes.
+ * Uses PsychoPath XPath 2.0 engine for the evaluation.
*/
- private boolean evaluateTestExprWithPsychoPath(QName element,
XMLAttributes attributes) {
+ private boolean evaluateTestExprWithPsychoPathEngine(QName element,
XMLAttributes attributes) {
boolean evaluationResult = false;
try {
- // construct a DOM document (used by psychopath engine as XPath
XDM instance).
- // A PSVI DOM is constructed to comply to PsychoPath design. This
doesn't seem to
- // affect CTA psychopath evaluations. CTA spec doesn't require a
typed XDM tree.
- // REVISIT ...
+ // construct a DOM document (used by psychopath engine for XPath
XDM instance).
+ // A PSVI DOM is constructed to comply to PsychoPath engine
design. This doesn't seem to affect CTA psychopath evaluations.
+ // CTA spec doesn't require a typed XDM tree. REVISIT ...
Document document = new PSVIDocumentImpl();
Element elem = document.createElementNS(element.uri,
element.rawname);
for (int attrIndx = 0; attrIndx < attributes.getLength();
attrIndx++) {
@@ -131,7 +130,6 @@ public class Test extends AbstractPsycho
attrNode.setNodeValue(attributes.getValue(attrIndx));
elem.setAttributeNode(attrNode);
}
-
document.appendChild(elem);
// construct parameter values for psychopath xpath processor
@@ -155,6 +153,6 @@ public class Test extends AbstractPsycho
return evaluationResult;
- } // evaluateTestExprWithPsychoPath
+ } // evaluateTestExprWithPsychoPathEngine
}
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=1084884&r1=1084883&r2=1084884&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
Thu Mar 24 09:12:21 2011
@@ -149,7 +149,7 @@ public class XSAssertImpl extends Abstra
return fTestExpr.toString();
}
- public XPath getCompiledXPath() {
+ public XPath getCompiledXPathExpr() {
return fCompiledXPathExpr;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]