[prev in list] [next in list] [prev in thread] [next in thread]
List: xerces-cvs
Subject: svn commit: r779293 - in /xerces/java/branches/xml-schema-1.1-dev:
From: knoaman () apache ! org
Date: 2009-05-27 20:04:26
Message-ID: 20090527200427.A5A192388871 () eris ! apache ! org
[Download RAW message or body]
Author: knoaman
Date: Wed May 27 20:04:26 2009
New Revision: 779293
URL: http://svn.apache.org/viewvc?rev=779293&view=rev
Log:
[Jira 1365] Assertion evaludation - patch by Mukul Gandhi
https://issues.apache.org/jira/browse/XERCESJ-1365
Added:
xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java (with \
props) xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java \
(with props) xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java \
(with props) xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java \
(with props) xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java \
(with props) xerces/java/branches/xml-schema-1.1-dev/tools/cupv10k-runtime.jar \
(with props) xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.0.0.jar \
(with props) Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/XSFacets.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
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/XMLSchemaValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/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/XSDSimpleTypeTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSAssert.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSMultiValueFacet.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSSimpleTypeDefinition.java
Added: xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java?rev=779293&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java (added)
+++ xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java Wed May \
27 20:04:26 2009 @@ -0,0 +1,48 @@
+package xni;
+
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class XMLSchema11Test implements ErrorHandler {
+
+ public static void main (String [] args) {
+
+ XMLSchema11Test test = new XMLSchema11Test();
+ test.run(args[0], args[1]);
+ }
+
+ private void run(String xmlfile, String schemapath) {
+ try {
+ System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema/v1.1",
+ "org.apache.xerces.jaxp.validation.XMLSchema11Factory");
+ SchemaFactory sf = \
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema/v1.1"); + \
Schema s = sf.newSchema(new StreamSource(schemapath)); + Validator v = \
s.newValidator(); + v.setErrorHandler(this);
+ v.validate(new StreamSource(xmlfile));
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void error(SAXParseException exception)
+ throws SAXException {
+ System.out.println(exception.getSystemId() + ":" + exception.getLineNumber() \
+ ":" + exception.getColumnNumber() + ":" + exception.getMessage()); + }
+
+ public void fatalError(SAXParseException exception)
+ throws SAXException {
+ System.out.println(exception.getSystemId() + ":" + exception.getLineNumber() + \
":" + exception.getColumnNumber() + ":" + exception.getMessage()); + }
+
+ public void warning(SAXParseException exception)
+ throws SAXException {
+ System.out.println(exception.getSystemId() + ":" + exception.getLineNumber() + \
":" + exception.getColumnNumber() + ":" + exception.getMessage()); + }
+}
\ No newline at end of file
Propchange: xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/xml-schema-1.1-dev/samples/xni/XMLSchema11Test.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/XSFacets.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/XSFacets.java?rev=779293&r1=779292&r2=779293&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/XSFacets.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/XSFacets.java \
Wed May 27 20:04:26 2009 @@ -29,7 +29,6 @@
* @xerces.internal
*
* @author Sandy Gao, IBM
- * @author Mukul Gandhi, IBM, modified to support XML Schema 1.1 'assertions'
*
* @version $Id$
*/
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apac \
he/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=779293&r1=779292&r2=779293&view=diff \
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java \
Wed May 27 20:04:26 2009 @@ -268,6 +268,7 @@
private Object fMaxExclusive;
private Object fMinExclusive;
private Object fMinInclusive;
+ private Vector fAssertion; // added for XML Schema 1.1, assertions
// annotations for constraining facets
public XSAnnotation lengthAnnotation;
@@ -375,6 +376,7 @@
fEnumeration = fBase.fEnumeration;
fEnumerationType = fBase.fEnumerationType;
fEnumerationItemType = fBase.fEnumerationItemType;
+ fAssertion = fBase.fAssertion; // added for XML Schema 1.1
fWhiteSpace = fBase.fWhiteSpace;
fMaxExclusive = fBase.fMaxExclusive;
fMaxInclusive = fBase.fMaxInclusive;
@@ -873,6 +875,19 @@
fFixedFacet |= FACET_ENUMERATION;
}
}
+
+ // assertion. added for XML Schema 1.1
+ if ((presentFacet & FACET_ASSERT) != 0) {
+ fAssertion = new Vector();
+ Vector asserts = facets.assertFacets;
+ for (int i = 0; i < asserts.size(); i++) {
+ fAssertion.addElement(asserts.elementAt(i));
+ }
+ fFacetsDefined |= FACET_ASSERT;
+ if ((fixedFacet & FACET_ASSERT) != 0)
+ fFixedFacet |= FACET_ASSERT;
+ }
+
// whiteSpace
if ((presentFacet & FACET_WHITESPACE) != 0) {
if ((allowedFacet & FACET_WHITESPACE) == 0) {
@@ -3133,11 +3148,12 @@
public XSObjectList getMultiValueFacets() {
if (fMultiValueFacets == null &&
((fFacetsDefined & FACET_ENUMERATION) != 0 ||
+ (fFacetsDefined & FACET_ASSERT) != 0 ||
(fFacetsDefined & FACET_PATTERN) != 0 ||
fPatternType != SPECIAL_PATTERN_NONE ||
fValidationDV == DV_INTEGER)) {
- XSMVFacetImpl[] facets = new XSMVFacetImpl[2];
+ XSMVFacetImpl[] facets = new XSMVFacetImpl[3];
int count = 0;
if ((fFacetsDefined & FACET_PATTERN) != 0 ||
fPatternType != SPECIAL_PATTERN_NONE ||
@@ -3157,6 +3173,10 @@
enumerationAnnotations);
count++;
}
+ if (fAssertion != null) {
+ facets[count] = new XSMVFacetImpl(FACET_ASSERT, fAssertion);
+ count++;
+ }
fMultiValueFacets = new XSObjectListImpl(facets, count);
}
return (fMultiValueFacets != null) ?
@@ -3283,12 +3303,23 @@
final short kind;
final XSObjectList annotations;
final StringList values;
+ final Vector asserts;
public XSMVFacetImpl(short kind, StringList values, XSObjectList \
annotations) { this.kind = kind;
this.values = values;
this.annotations = (annotations != null) ? annotations : \
XSObjectListImpl.EMPTY_LIST; + this.asserts = null;
}
+ /*
+ * overloaded constructor. added to support assertions.
+ */
+ public XSMVFacetImpl(short kind, Vector asserts) {
+ this.kind = kind;
+ this.asserts = asserts;
+ this.values = null;
+ this.annotations = null;
+ }
/* (non-Javadoc)
* @see org.apache.xerces.xs.XSFacet#getFacetKind()
@@ -3339,6 +3370,10 @@
public short getType() {
return XSConstants.MULTIVALUE_FACET;
}
+
+ public Vector getAsserts() {
+ return asserts;
+ }
}
private static abstract class AbstractObjectList extends AbstractList implements \
ObjectList {
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/apac \
he/xerces/impl/msg/XMLSchemaMessages.properties?rev=779293&r1=779292&r2=779293&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 \
Wed May 27 20:04:26 2009 @@ -99,6 +99,8 @@
cvc-type.3.1.1 = cvc-type.3.1.1: Element ''{0}'' is a simple type, so it \
cannot have attributes, excepting those whose namespace name is identical to \
''http://www.w3.org/2001/XMLSchema-instance'' and whose [local name] is one of \
''type'', ''nil'', ''schemaLocation'' or ''noNamespaceSchemaLocation''. However, the \
attribute, ''{1}'' was found.
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.
#schema valid (3.X.3)
Added: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java?rev=779293&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java \
(added)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java \
Wed May 27 20:04:26 2009 @@ -0,0 +1,43 @@
+/*
+ * 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.xerces.impl.xpath;
+
+import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.xni.NamespaceContext;
+
+/**
+ * A class representing a XPath 2.0 expression for, assertions evaluation.
+ *
+ * @author Mukul Gandhi, IBM
+ * @version $Id$
+ */
+public class XPath20Assert {
+
+ protected final String fExpression;
+ protected final NamespaceContext fContext;
+
+ public XPath20Assert(String xpath, SymbolTable symbolTable,
+ NamespaceContext context) throws XPathException {
+ fExpression = xpath;
+ fContext = context;
+ }
+
+ public String toString() {
+ return fExpression;
+ }
+}
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20Assert.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=779293&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java \
(added)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java \
Wed May 27 20:04:26 2009 @@ -0,0 +1,319 @@
+/*
+ * 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.xerces.impl.xs;
+
+import java.util.Stack;
+import java.util.Vector;
+
+import org.apache.xerces.dom.PSVIAttrNSImpl;
+import org.apache.xerces.dom.PSVIDocumentImpl;
+import org.apache.xerces.dom.PSVIElementNSImpl;
+import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.XNIException;
+import org.apache.xerces.xni.parser.XMLAssertAdapter;
+import org.apache.xerces.xs.ElementPSVI;
+import org.apache.xerces.xs.XSModel;
+import org.apache.xerces.xs.XSObjectList;
+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.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.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;
+import org.eclipse.wst.xml.xpath2.processor.internal.Focus;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Id$
+ * @author Mukul Gandhi, IBM
+ * @author Ken Cai, IBM
+ */
+
+public class XMLAssertPsychopathImpl extends XMLAssertAdapter {
+
+ // class variable declarations
+ DynamicContext fDynamicContext;
+ XSModel fSchema;
+
+ // a factory Document object to construct DOM tree nodes
+ Document assertDocument = null;
+
+ // an element to track construction of assertion DOM tree. This object changes
+ // as per the XNI document events.
+ Element currentAssertDomNode = null;
+
+ // a stack holding the DOM root for assertions evaluation
+ Stack assertRootStack = null;
+
+ // a stack parallel to 'assertRootStack' storing all assertions for a single
+ // assert tree
+ Stack assertListStack = null;
+
+ // XMLSchemaValidator reference. set from the XMLSchemaValidator object
+ // itself.
+ XMLSchemaValidator validator = null;
+
+ /*
+ * The class constructor
+ */
+ public XMLAssertPsychopathImpl() {
+ // initializing the class variables
+ this.assertDocument = new PSVIDocumentImpl();
+ this.assertRootStack = new Stack();
+ this.assertListStack = new Stack();
+ }
+
+
+ private void initXPathProcessor() throws Exception {
+ validator = (XMLSchemaValidator) \
getAttribute("http://apache.org/xml/properties/assert/validator"); + \
fDynamicContext = new DefaultDynamicContext(fSchema, assertDocument); + // add \
variable "value" to the XPath context + fDynamicContext.add_variable(new \
org.eclipse.wst.xml.xpath2.processor.internal.types.QName( + \
"value")); + fDynamicContext.add_namespace("xs", \
"http://www.w3.org/2001/XMLSchema"); + fDynamicContext.add_namespace("fn", \
"http://www.w3.org/2005/xpath-functions"); + }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.xerces.xni.parser.XMLAssertAdapter#startElement(org.apache.xerces.xni.QName, \
org.apache.xerces.xni.XMLAttributes, java.lang.Object) + */
+ public void startElement(QName element, XMLAttributes attributes,
+ Object assertObject) {
+ if (currentAssertDomNode == null) {
+ currentAssertDomNode = assertDocument.createElementNS(
+ element.uri, element.rawname);
+ assertDocument.appendChild(currentAssertDomNode);
+ } else {
+ Element elem = assertDocument.createElementNS(element.uri, \
element.rawname); + currentAssertDomNode.appendChild(elem);
+ currentAssertDomNode = elem;
+ }
+
+ // add attributes to the element
+ for (int attIndex = 0; attIndex < attributes.getLength(); attIndex++) {
+ String attrUri = attributes.getURI(attIndex);
+ String attQName = attributes.getQName(attIndex);
+ String attValue = attributes.getValue(attIndex);
+
+ PSVIAttrNSImpl attrNode = new \
PSVIAttrNSImpl((PSVIDocumentImpl)assertDocument, attrUri, attQName); + \
attrNode.setNodeValue(attValue); +
+ // set PSVI information for the attribute
+ Augmentations attrAugs = attributes.getAugmentations(attIndex);
+ AttributePSVImpl attrPSVI = \
(AttributePSVImpl)attrAugs.getItem(Constants.ATTRIBUTE_PSVI); + \
attrNode.setPSVI(attrPSVI); +
+ currentAssertDomNode.setAttributeNode(attrNode);
+ }
+
+ // if we have assertion on this element, store the element reference
+ // and the assertions on it, on the stacks
+ if (assertObject != null) {
+ assertRootStack.push(currentAssertDomNode);
+ assertListStack.push(assertObject);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.xerces.xni.parser.XMLAssertAdapter#endElement(org.apache.xerces.xni.QName, \
org.apache.xerces.xni.Augmentations) + */
+ public void endElement(QName element, Augmentations augs) throws Exception {
+ if (currentAssertDomNode != null) {
+ // set PSVI information on the element
+ ElementPSVI elemPSVI = \
(ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI); + \
((PSVIElementNSImpl)currentAssertDomNode).setPSVI(elemPSVI); +
+ if (!assertRootStack.empty() && (currentAssertDomNode == \
assertRootStack.peek())) { + // get XSModel \
+ fSchema = elemPSVI.getSchemaInformation();
+
+ /*
+ // debugging code. can be present till the code is final.
+ try {
+ DOMImplementationRegistry registry = \
DOMImplementationRegistry.newInstance(); + DOMImplementationLS impl \
= (DOMImplementationLS) registry + \
.getDOMImplementation("LS"); + LSSerializer writer = \
impl.createLSSerializer(); + LSOutput output = \
impl.createLSOutput(); + output.setByteStream(System.out);
+ writer.write(currentAssertDomNode, output);
+ System.out.println("\n");
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ */
+
+ assertRootStack.pop(); // pop the stack, to go one level up
+ Object assertions = assertListStack.pop(); // get assertions, and \
go one level up +
+ // evaluate assertions
+ if (assertions instanceof XSObjectList) {
+ // assertions from a complex type definition
+ XSObjectList assertList = (XSObjectList) assertions;
+ initXPathProcessor();
+ for (int i = 0; i < assertList.size(); i++) {
+ XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
+ evaluateAssertion(element, assertImpl);
+ }
+ } else if (assertions instanceof Vector) {
+ // assertions from a simple type definition
+ Vector assertList = (Vector) assertions;
+ initXPathProcessor();
+ for (int i = 0; i < assertList.size(); i++) {
+ XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
+ evaluateAssertion(element, assertImpl);
+ }
+ }
+ }
+
+ if (currentAssertDomNode.getParentNode() instanceof Element) {
+ currentAssertDomNode = (Element)currentAssertDomNode.getParentNode();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.xerces.xni.parser.XMLAssertAdapter#characters(org.apache.xerces.xni.XMLString)
+ */
+ public void characters(XMLString text) {
+ // add a child text node to the assertions, DOM tree
+ if (currentAssertDomNode != null) {
+ currentAssertDomNode.appendChild(assertDocument
+ .createTextNode(new String(text.ch, text.offset,
+ text.length)));
+ }
+ }
+
+ /*
+ * Helper method to evaluate assertions
+ */
+ private void evaluateAssertion(QName element, XSAssertImpl assertImpl) {
+ fDynamicContext.add_function_library(new FnFunctionLibrary());
+ fDynamicContext.add_function_library(new XSCtrLibrary());
+
+ XPathParser xpp = new JFlexCupParser();
+ XPath xp = null;
+ try {
+ xp = xpp.parse("boolean("
+ + assertImpl.getTest().getXPath().toString() + ")");
+ } catch (XPathParserException ex) {
+ // error compiling the XPath expression
+ reportError("cvc-xpath.3.13.4.2", element, assertImpl);
+ throw new XNIException(ex.getMessage(), ex);
+ }
+
+ StaticChecker sc = new StaticNameResolver(fDynamicContext);
+
+ try {
+ sc.check(xp);
+
+ // assign value to variable, "value"
+ String value = "";
+ //Element rootElem = (Element) fDOM.getFirstChild();
+ NodeList childList = currentAssertDomNode.getChildNodes();
+ if (childList.getLength() == 1) {
+ Node node = childList.item(0);
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ value = node.getNodeValue();
+ }
+ }
+
+ fDynamicContext.set_variable(
+ new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+ "value"), new XSString(value));
+
+ Evaluator eval = new DefaultEvaluator(fDynamicContext, assertDocument);
+
+ // change focus to the top most element
+ ResultSequence nodeEvalRS = ResultSequenceFactory.create_new();
+ nodeEvalRS.add(new ElementType(currentAssertDomNode,
+ \
fDynamicContext.node_position(currentAssertDomNode))); + \
fDynamicContext.set_focus(new Focus(nodeEvalRS)); +
+ ResultSequence rs = eval.evaluate(xp);
+
+ boolean result = false;
+
+ if (rs == null) {
+ 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;
+ }
+ }
+
+ if (!result) {
+ // assertion evaluation is false
+ reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+ }
+
+ } catch (Exception ex) {
+ reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+ throw new XNIException(ex.getMessage(), ex);
+ }
+
+ }
+
+ 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 });
+ }
+
+}
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
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/apac \
he/xerces/impl/xs/XMLSchemaValidator.java?rev=779293&r1=779292&r2=779293&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 \
Wed May 27 20:04:26 2009 @@ -67,6 +67,7 @@
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
import org.apache.xerces.xni.grammars.XMLGrammarPool;
+import org.apache.xerces.xni.parser.XMLAssertHandler;
import org.apache.xerces.xni.parser.XMLComponent;
import org.apache.xerces.xni.parser.XMLComponentManager;
import org.apache.xerces.xni.parser.XMLConfigurationException;
@@ -77,9 +78,14 @@
import org.apache.xerces.xs.AttributePSVI;
import org.apache.xerces.xs.ElementPSVI;
import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.XSComplexTypeDefinition;
import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSMultiValueFacet;
import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
import org.apache.xerces.xs.XSTypeDefinition;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
/**
* The XML Schema validator. The validator implements a document
@@ -375,6 +381,9 @@
*/
private XMLLocator fLocator;
+ // assertion processor object reference
+ private XMLAssertHandler assertionProcessor = null;
+
/**
* A wrapper of the standard error reporter. We'll store all schema errors
* in this wrapper object, so that we can get all errors (error codes) of
@@ -787,6 +796,34 @@
} // startElement(QName,XMLAttributes, Augmentations)
+
+ /*
+ * Helper method to initialize the assertion processor
+ */
+ private void initializeAssertProcessor() {
+ String assertProcessorProp = System
+ .getProperty("org.apache.xerces.assertProcessor");
+ if (assertProcessorProp == null || assertProcessorProp.equals("")) {
+ // if assertion processor is not specified via a system
+ // property, default to the Psychopath processor
+ assertionProcessor = new XMLAssertPsychopathImpl();
+ } else {
+ try {
+ Class assertClass = ClassLoader.getSystemClassLoader()
+ .loadClass(assertProcessorProp);
+ assertionProcessor = (XMLAssertHandler) assertClass.newInstance();
+ } catch (ClassNotFoundException ex) {
+ throw new XNIException(ex.getMessage(), ex);
+ } catch (InstantiationException ex) {
+ throw new XNIException(ex.getMessage(), ex);
+ } catch (IllegalAccessException ex) {
+ throw new XNIException(ex.getMessage(), ex);
+ }
+ }
+ assertionProcessor.setAttribute("http://apache.org/xml/properties/assert/validator", \
this); + }
+
+
/**
* An empty element.
*
@@ -1749,6 +1786,11 @@
}
}
}
+
+ // invoke the assertions processor method
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && assertionProcessor != \
null) { + assertionProcessor.characters(text);
+ }
return text;
} // handleCharacters(XMLString)
@@ -2290,6 +2332,43 @@
// PSVI: add nil
fCurrentPSVI.fNil = fNil;
}
+
+ // process assertions
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+ XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
+
+ Object assertObject = null;
+ if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
+ XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) \
typeDef; + XSObjectList assertions = complexTypeDef.getAssertions();
+ if (assertions.getLength() > 0) {
+ assertObject = assertions;
+ // instantiate the assertions processor
+ if (assertionProcessor == null) {
+ initializeAssertProcessor();
+ }
+ }
+ } else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+ XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) \
typeDef; + XSObjectList facets = simpleTypeDef.getMultiValueFacets();
+ for (int i = 0; i < facets.getLength(); i++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) \
{ + assertObject = facet.getAsserts();
+ // instantiate the assertions processor
+ if (assertionProcessor == null) {
+ initializeAssertProcessor();
+ }
+ break;
+ }
+ }
+ }
+
+ // invoke the assertions processor method
+ if (assertionProcessor != null) {
+ assertionProcessor.startElement(element, attributes, assertObject);
+ }
+ }
return augs;
@@ -2476,6 +2555,21 @@
// same here.
fUnionType = false;
}
+
+ // invoke the assertions processor method
+ // TODO: This code should be after Identity constraint checking and
+ // should create its own PSVIElement and set the grammars info
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && assertionProcessor != \
null) { + try {
+ // construct the augmentations object, for assertions
+ AugmentationsImpl assertAugs = new AugmentationsImpl();
+ assertAugs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI);
+
+ assertionProcessor.endElement(element, assertAugs);
+ } catch (Exception ex) {
+ throw new XNIException(ex.getMessage(), ex);
+ }
+ }
return augs;
} // handleEndElement(QName,boolean)*/
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/Test.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/Test.java?rev=779293&r1=779292&r2=779293&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/Test.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/Test.java \
Wed May 27 20:04:26 2009 @@ -17,7 +17,7 @@
package org.apache.xerces.impl.xs.assertion;
-import org.apache.xerces.impl.xpath.XPath20;
+import org.apache.xerces.impl.xpath.XPath20Assert;
import org.apache.xerces.xs.XSAssert;
/**
@@ -32,10 +32,10 @@
protected final XSAssert fAssert;
/** XPath 2.0 expression */
- protected final XPath20 fXPath;
+ protected final XPath20Assert fXPath;
/** Constructs a test for assertion component */
- public Test(XPath20 xpath, XSAssert assertion) {
+ public Test(XPath20Assert xpath, XSAssert assertion) {
fXPath = xpath;
fAssert = assertion;
}
@@ -45,7 +45,7 @@
}
/** Returns the test XPath */
- public XPath20 getXPath() {
+ public XPath20Assert getXPath() {
return fXPath;
}
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/apac \
he/xerces/impl/xs/assertion/XSAssertImpl.java?rev=779293&r1=779292&r2=779293&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 \
Wed May 27 20:04:26 2009 @@ -31,7 +31,6 @@
public class XSAssertImpl implements XSAssert {
/** The type definition associated with the assertion component */
- // This could be a simple type, or a complex type
protected XSTypeDefinition fTypeDefinition;
/** The restricted XPath 2.0 expression that represents the test attribute */
@@ -82,9 +81,23 @@
return s;
}
+ /*
+ * Tests if two asserts are equal
+ */
public boolean equals(XSAssertImpl assertComponent) {
- // ToDo
- return false;
+ boolean returnVal = false;
+
+ String typeNameP = assertComponent.getTypeDefinition().getName();
+ String xpathStrP = assertComponent.getTest().getXPath().toString();
+ String typeNameThis = this.fTypeDefinition.getName();
+ String xpathStrThis = this.getTest().getXPath().toString();
+
+ // if type and the xpath string are same, the asserts are equal
+ if (typeNameThis.equals(typeNameP) && xpathStrThis.equals(xpathStrP)) {
+ returnVal = true;
+ }
+
+ return returnVal;
}
/** Get the optional annotations */
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/apac \
he/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=779293&r1=779292&r2=779293&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 \
Wed May 27 20:04:26 2009 @@ -25,7 +25,7 @@
import org.apache.xerces.impl.dv.XSFacets;
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.validation.ValidationState;
-import org.apache.xerces.impl.xpath.XPath20;
+import org.apache.xerces.impl.xpath.XPath20Assert;
import org.apache.xerces.impl.xpath.XPathException;
import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.impl.xs.SchemaSymbols;
@@ -44,7 +44,9 @@
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.xni.QName;
+import org.apache.xerces.xs.XSMultiValueFacet;
import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
import org.apache.xerces.xs.XSTypeDefinition;
import org.w3c.dom.Element;
@@ -58,7 +60,6 @@
* @author Elena Litani, IBM
* @author Rahul Srivastava, Sun Microsystems Inc.
* @author Neeraj Bajaj, Sun Microsystems Inc.
- * @author Mukul Gandhi, IBM, modified to support XML Schema 1.1 'assertions'
*
* @version $Id$
*/
@@ -86,6 +87,9 @@
protected XSAttributeChecker fAttrChecker = null;
protected boolean fValidateAnnotations = false;
+ // a vector holding all the asserts up in the type hierarchy
+ private Vector baseAsserts = new Vector();
+
// used to validate default/fixed attribute values
ValidationState fValidationState = new ValidationState();
@@ -278,7 +282,53 @@
}
}
+ /*
+ * Helper method to find all assertions up in the type hierarchy
+ */
+ private void getAssertsFromBaseTypes(XSSimpleType baseValidator) {
+ XSObjectList multiValFacetsOfBaseType = baseValidator.getMultiValueFacets();
+
+ for (int i = 0; i < multiValFacetsOfBaseType.getLength(); i++) {
+ XSMultiValueFacet mvFacet = (XSMultiValueFacet) \
multiValFacetsOfBaseType.item(i); + if (mvFacet.getFacetKind() == \
XSSimpleTypeDefinition.FACET_ASSERT) { + // add asserts of this type \
to the global Vector object + Vector assertsToAdd = \
mvFacet.getAsserts(); + for (int j = 0; j < assertsToAdd.size(); j++) \
{ + // add assertion to the list, only if it's already not present
+ if (!assertExists((XSAssertImpl)assertsToAdd.get(j))) {
+ baseAsserts.add(assertsToAdd.get(j));
+ }
+ }
+ break;
+ }
+ }
+
+ // invoke the method recursively. go up the type hierarchy.
+ if (baseValidator.getBaseType() != null) {
+ getAssertsFromBaseTypes((XSSimpleType)baseValidator.getBaseType());
+ }
+ }
+
+ /*
+ * Check if an assertion already exists in the buffer
+ */
+ private boolean assertExists(XSAssertImpl assertVal) {
+ boolean assertExists = false;
+
+ for (int i = 0; i < baseAsserts.size(); i++) {
+ if (((XSAssertImpl)baseAsserts.get(i)).equals(assertVal)) {
+ assertExists = true;
+ break;
+ }
+ }
+
+ return assertExists;
+ } // end of method, assertExists
+
+
+
FacetInfo traverseFacets(Element content,
+ XSTypeDefinition typeDef,
XSSimpleType baseValidator,
XSDocumentInfo schemaDoc) {
@@ -400,9 +450,8 @@
if (childNode != null) {
// it's an error to have something after the annotation, in \
'assert'
- reportSchemaError("xxx-define this",
- new Object[] { DOMUtil.getLocalName(childNode) },
- childNode);
+ reportSchemaError("s4s-elt-invalid-content.1", new \
Object[]{DOMUtil.getLocalName(content), + \
DOMUtil.getLocalName(childNode)}, childNode); }
} else {
String text = DOMUtil.getSyntheticAnnotation(childNode);
@@ -422,11 +471,11 @@
annotations = XSObjectListImpl.EMPTY_LIST;
}
- XSAssertImpl assertImpl = new XSAssertImpl(baseValidator, \
annotations); + XSAssertImpl assertImpl = new \
XSAssertImpl(typeDef, annotations); Test testExpr = null;
//set the test attribute value
try {
- testExpr = new Test(new XPath20(test, fSymbolTable,
+ testExpr = new Test(new XPath20Assert(test, fSymbolTable,
schemaDoc.fNamespaceSupport), assertImpl);
}
catch (XPathException e) {
@@ -580,6 +629,22 @@
fAttrChecker.returnAttrArray (attrs, schemaDoc);
content = DOMUtil.getNextSiblingElement(content);
}
+
+ // retrieve all assert definitions from all base types all the way up in the
+ // type hierarchy. sets a global variable, 'baseAsserts' with all the base
+ // asserts.
+ if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+ getAssertsFromBaseTypes(baseValidator);
+
+ // add all base assertions to the list of assertions to be processed
+ if (baseAsserts.size() > 0) {
+ if (assertData == null) {
+ assertData = new Vector();
+ }
+ assertData.addAll(baseAsserts);
+ }
+ }
+
if (enumData !=null) {
facetsPresent |= XSSimpleType.FACET_ENUMERATION;
xsFacets.enumeration = enumData;
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/apac \
he/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=779293&r1=779292&r2=779293&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 \
Wed May 27 20:04:26 2009 @@ -22,7 +22,7 @@
import org.apache.xerces.impl.dv.XSFacets;
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
-import org.apache.xerces.impl.xpath.XPath20;
+import org.apache.xerces.impl.xpath.XPath20Assert;
import org.apache.xerces.impl.xpath.XPathException;
import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.impl.xs.SchemaSymbols;
@@ -41,6 +41,7 @@
import org.apache.xerces.util.DOMUtil;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xs.XSAttributeUse;
+import org.apache.xerces.xs.XSComplexTypeDefinition;
import org.apache.xerces.xs.XSConstants;
import org.apache.xerces.xs.XSObjectList;
import org.apache.xerces.xs.XSTypeDefinition;
@@ -392,7 +393,8 @@
else {
//
// We must have ....
- // GROUP, ALL, SEQUENCE or CHOICE, followed by optional attributes
+ // GROUP, ALL, SEQUENCE or CHOICE, followed by optional
+ // attributes and assertions
// Note that it's possible that only attributes are specified.
//
@@ -663,7 +665,7 @@
short fixedFacets = 0 ;
if (simpleContent!=null) {
- FacetInfo fi = traverseFacets(simpleContent, baseValidator, \
schemaDoc); + FacetInfo fi = traverseFacets(simpleContent, \
fComplexTypeDecl, baseValidator, schemaDoc); attrOrAssertNode = fi.nodeAfterFacets;
facetData = fi.facetdata;
presentFacets = fi.fPresentFacets;
@@ -950,6 +952,12 @@
addAnnotation(traverseSyntheticAnnotation(complexContent, text, \
derivationTypeAttrValues, false, schemaDoc)); }
}
+
+ // add any assertions from the base types, for assertions to be processed
+ if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+ getAssertsFromBaseTypes(fBaseType);
+ }
+
// -----------------------------------------------------------------------
// Process the content. Note: should I try to catch any complexType errors
// here in order to return the attr array?
@@ -1274,10 +1282,50 @@
throw new ComplexTypeRecoverableError("src-ct.5", new \
Object[]{typeName}, elem); }
}
-
}
}
+
+ /*
+ * Helper method to find all assertions up in the type hierarchy
+ */
+ private void getAssertsFromBaseTypes(XSTypeDefinition baseValidator) {
+ if (baseValidator != null && baseValidator instanceof \
XSComplexTypeDefinition) { + XSObjectList assertList = \
((XSComplexTypeDefinition) baseValidator) + .getAssertions();
+ for (int i = 0; i < assertList.size(); i++) {
+ // add assertion to the list, only if it's already not present
+ if (!assertExists((XSAssertImpl) assertList.get(i))) {
+ addAssertion((XSAssertImpl) assertList.get(i));
+ }
+ }
+
+ // invoke the method recursively. go up the type hierarchy.
+ if (!baseValidator.getBaseType().getName().equals("anyType")) { \
+ getAssertsFromBaseTypes(baseValidator.getBaseType());
+ }
+ }
+ } // end of method, getAssertsFromBaseTypes
+
+ /*
+ * Check if an assertion already exists in the buffer
+ */
+ private boolean assertExists(XSAssertImpl assertVal) {
+ boolean assertExists = false;
+
+ if (fAssertions != null) {
+ for (int i = 0; i < fAssertions.length; i++) {
+ if (fAssertions[i].equals(assertVal)) {
+ assertExists = true;
+ break;
+ }
+ }
+ }
+
+ return assertExists;
+ } // end of method, assertExists
+
+
private void processComplexContent(Element complexContentChild,
boolean isMixed, boolean isDerivation,
XSDocumentInfo schemaDoc, SchemaGrammar grammar)
@@ -1529,8 +1577,9 @@
if (childNode != null) {
// it's an error to have something after the
// annotation, in 'assert'
- reportSchemaError("xxx-define this", new Object[] { DOMUtil
- .getLocalName(childNode) }, childNode);
+ reportSchemaError("s4s-elt-invalid-content.1", new Object[] {
+ DOMUtil.getLocalName(assertElement),
+ DOMUtil.getLocalName(childNode) }, childNode);
}
} else {
String text = DOMUtil.getSyntheticAnnotation(childNode);
@@ -1554,7 +1603,7 @@
Test testExpr = null;
// set the test attribute value
try {
- testExpr = new Test(new XPath20(test, fSymbolTable,
+ testExpr = new Test(new XPath20Assert(test, fSymbolTable,
schemaDoc.fNamespaceSupport), assertImpl);
} catch (XPathException e) {
// if the xpath is invalid create a Test without an
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apac \
he/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java?rev=779293&r1=779292&r2=779293&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java \
Wed May 27 20:04:26 2009 @@ -397,7 +397,7 @@
}
// now traverse facets, if it's derived by restriction
if (restriction && content != null) {
- FacetInfo fi = traverseFacets(content, baseValidator, schemaDoc);
+ FacetInfo fi = traverseFacets(content, newDecl, baseValidator, \
schemaDoc); content = fi.nodeAfterFacets;
if (!skipFacets) {
Added: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java?rev=779293&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java \
(added)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java \
Wed May 27 20:04:26 2009 @@ -0,0 +1,102 @@
+/*
+ * 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.xerces.xni.parser;
+
+import java.util.Hashtable;
+
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+
+/**
+ * A convenience implementation of the assertions interface. All compliant \
assertions + * processors (using a specific XPath 2.0 engine), should extend this \
class. + *
+ * @version $Id$
+ * @author: Mukul Gandhi, IBM
+ */
+public class XMLAssertAdapter implements XMLAssertHandler {
+
+ // this hashtable contains any implementation specific
+ // attributes/properties
+ private Hashtable attributes = null;
+
+ public void startElement(QName element, XMLAttributes attributes,
+ Object assertObject) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void endElement(QName element, Augmentations augs) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void characters(XMLString text) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Allows the user to set specific attributes on the underlying
+ * implementation.
+ * @param name name of attribute
+ * @param value null means to remove attribute
+ */
+ public void setAttribute(String name, Object value)
+ throws IllegalArgumentException {
+ // This handles removal of attributes
+ if (value == null) {
+ if (attributes != null) {
+ attributes.remove(name);
+ }
+ // Unrecognized attributes do not cause an exception
+ return;
+ }
+
+ // Create Hashtable if none existed before
+ if (attributes == null) {
+ attributes = new Hashtable();
+ }
+
+ attributes.put(name, value);
+ }
+
+
+ /**
+ * Allows the user to retrieve specific attributes on the underlying
+ * implementation.
+ */
+ public Object getAttribute(String name) throws IllegalArgumentException {
+ // See if it's in the attributes Hashtable
+ if (attributes != null) {
+ Object val = attributes.get(name);
+ if (val != null) {
+ return val;
+ }
+ else {
+ throw new IllegalArgumentException("the attribute "+name+" is not set. \
can't find it's value"); + }
+ }
+
+ // unreach
+ return null;
+ }
+
+}
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertAdapter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java?rev=779293&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java \
(added)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java \
Wed May 27 20:04:26 2009 @@ -0,0 +1,95 @@
+/*
+ * 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.xerces.xni.parser;
+
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+
+/**
+ * The implementation of this interface will invoke an external XPath engine, which
+ * would evaluate the XPath 2.0 expressions, in XML Schema 1.1 assertions.
+ * This interface communicates with the XMLSchemaValidator, and accepts information
+ * required by the external XPath engine. If assertions evaluation returns 'true',
+ * validation would proceed further. And while upon assertion failure, validation \
process + * terminates in the implementing classes if this interface.
+ *
+ * @author Mukul Gandhi, IBM
+ * @author Ken Cai, IBM
+ *
+ * @version $Id$
+ *
+ */
+public interface XMLAssertHandler {
+
+ /*
+ * A callback method triggered during startElement method call in, \
XMLSchemaValidator + *
+ * @param element
+ * XML element
+ * @param attributes
+ * attributes of the element
+ * @param assertObject
+ * An object holding the assertions for this element (for the \
element's type) + */
+ public void startElement(QName element, XMLAttributes attributes, Object \
assertObject); +
+ /*
+ * A callback method triggered during endElement method call in, \
XMLSchemaValidator + *
+ * @param element
+ * XML element
+ * @param augs
+ * Augmentations object, to support Schema types
+ */
+ public void endElement(QName element, Augmentations augs) throws Exception;
+
+ /*
+ * A callback method triggered during characters method call in, \
XMLSchemaValidator + *
+ * @param text
+ * Text data received during the call
+ */
+ public void characters(XMLString text);
+
+
+ /**
+ * Allows the user to set specific attributes on the underlying
+ * implementation.
+ * @param name The name of the attribute.
+ * @param value The value of the attribute.
+ * @exception IllegalArgumentException thrown if the underlying
+ * implementation doesn't recognize the attribute.
+ */
+ public void setAttribute(String name, Object value)
+ throws IllegalArgumentException;
+
+
+ /**
+ * Allows the user to retrieve specific attributes on the underlying
+ * implementation.
+ * @param name The name of the attribute.
+ * @return value The value of the attribute.
+ * @exception IllegalArgumentException thrown if the underlying
+ * implementation doesn't recognize the attribute.
+ */
+ public abstract Object getAttribute(String name)
+ throws IllegalArgumentException;
+
+}
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xni/parser/XMLAssertHandler.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSAssert.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSAssert.java?rev=779293&r1=779292&r2=779293&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSAssert.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSAssert.java \
Wed May 27 20:04:26 2009 @@ -17,6 +17,8 @@
package org.apache.xerces.xs;
+import org.apache.xerces.impl.xs.assertion.Test;
+
/**
* This interface represents the XML Schema assertion component. Assertion
* components were first introduced in the XML Schema structures 1.1
@@ -36,10 +38,10 @@
/**
* [test]: a restricted XPath 2.0 expression.
*/
- public String getTestStr();
+ public Test getTest();
/**
- * [type definition]: a valid type definition component
+ * The type associated with the assertion
*/
public XSTypeDefinition getTypeDefinition();
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSMultiValueFacet.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSMultiValueFacet.java?rev=779293&r1=779292&r2=779293&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSMultiValueFacet.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSMultiValueFacet.java \
Wed May 27 20:04:26 2009 @@ -17,6 +17,8 @@
package org.apache.xerces.xs;
+import java.util.Vector;
+
/**
* Describes a multi-value constraining facets: pattern and enumeration.
*/
@@ -36,5 +38,10 @@
* A sequence of [annotations] or an empty <code>XSObjectList</code>.
*/
public XSObjectList getAnnotations();
+
+ /*
+ * Added for XML Schema 1.1, assertions
+ */
+ public Vector getAsserts();
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSSimpleTypeDefinition.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apac \
he/xerces/xs/XSSimpleTypeDefinition.java?rev=779293&r1=779292&r2=779293&view=diff \
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSSimpleTypeDefinition.java \
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSSimpleTypeDefinition.java \
Wed May 27 20:04:26 2009 @@ -98,6 +98,9 @@
*/
public static final short FACET_ENUMERATION = 2048;
+ /**
+ * 'assertion' facet introduced in XML Schema 1.1
+ */
public static final short FACET_ASSERT = 4096;
/**
Added: xerces/java/branches/xml-schema-1.1-dev/tools/cupv10k-runtime.jar
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/tools/cupv10k-runtime.jar?rev=779293&view=auto
==============================================================================
Binary file - no diff available.
Propchange: xerces/java/branches/xml-schema-1.1-dev/tools/cupv10k-runtime.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.0.0.jar
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.0.0.jar?rev=779293&view=auto
==============================================================================
Binary file - no diff available.
Propchange: xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.0.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic