Author: knoaman
Date: Mon Jul 7 14:16:16 2008
New Revision: 674639
URL: http://svn.apache.org/viewvc?rev=674639&view=rev
Log:
Type Alternative: XSD traversal support - patch by Hiranya Jayathilaka
Added:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
(with props)
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
(with props)
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
(with props)
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
(with props)
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
(with props)
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/SchemaGrammar.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/XSElementDecl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSConstants.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=674639&r1=674638&r2=674639&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
Mon Jul 7 14:16:16 2008
@@ -119,6 +119,7 @@
src-element.2.1 = src-element.2.1: : One of 'ref' or 'name' must be
present in a local element declaration.
src-element.2.2 = src-element.2.2: Since ''{0}'' contains the ''ref''
attribute, its content must match (annotation?). However, ''{1}'' was found.
src-element.3 = src-element.3: Element ''{0}'' has both a ''type''
attribute and a ''anonymous type'' child. Only one of these is allowed for an
element.
+ src-element.5 = src-element.5: Element ''{0}'' has a type alternative
with a missing ''test'' attribute. Only the last type alternative in the type
table is allowed to be without a ''test'' attribute.
src-import.1.1 = src-import.1.1: The namespace attribute ''{0}'' of an
<import> element information item must not be the same as the targetNamespace
of the schema it exists in.
src-import.1.2 = src-import.1.2: If the namespace attribute is not
present on an <import> element information item then the enclosing schema must
have a targetNamespace.
src-import.2 = src-import.2: The root element of document ''{0}'' has
to have the namespace name ''http://www.w3.org/2001/XMLSchema'' and the local
name ''schema''.
@@ -151,6 +152,8 @@
src-simple-type.3.b = src-simple-type.3.b: A <list> element was found
that has neither an itemType [attribute] nor a <simpleType> element among its
[children]. One is required.
src-single-facet-value = src-single-facet-value: The facet ''{0}'' is
defined more than once.
src-union-memberTypes-or-simpleTypes =
src-union-memberTypes-or-simpleTypes: A <union> element must have either a
non-empty memberTypes [attribute] or at least one <simpleType> element among
its [children].
+ src-type-alternative.3.12.13.1 = src-type-alternative.3.12.13.1: Type
atlernative has both a ''type'' attribute and a ''anonymous type'' child. Only
one of these is allowed for a type alternative.
+ src-type-alternative.3.12.13.2 = src-type-alternative.3.12.13.2: Type
definition missing for type atlernative. A ''type'' attribute, or a
''complexType'' child element, or a ''simpleType'' child element must be
present.
#constraint valid (3.X.6)
Added:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java?rev=674639&view=auto
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
(added)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
Mon Jul 7 14:16:16 2008
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+/**
+ * Bare minimal XPath 2.0 implementation for schema
+ * type alternatives
+ *
+ * @author Hiranya Jayathilaka, University of Moratuwa
+ * @version $Id:$
+ */
+public class XPath20 {
+
+ protected final String fExpression;
+
+ protected final SymbolTable fSymbolTable;
+
+ public XPath20(String xpath, SymbolTable symbolTable,
+ NamespaceContext context) throws XPathException {
+ fExpression = xpath;
+ fSymbolTable = symbolTable;
+ parseExpression(context);
+ }
+
+ private void parseExpression(NamespaceContext context)
+ throws XPathException {
+ //TODO: Parse the given XPath expression
+ }
+}
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java?rev=674639&r1=674638&r2=674639&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java
Mon Jul 7 14:16:16 2008
@@ -25,6 +25,7 @@
import org.apache.xerces.impl.dv.ValidatedInfo;
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
import org.apache.xerces.impl.xs.identity.IdentityConstraint;
import org.apache.xerces.impl.xs.util.SimpleLocator;
import org.apache.xerces.impl.xs.util.StringListImpl;
@@ -681,6 +682,13 @@
}
/**
+ * register one type alternative
+ */
+ public final void addTypeAlternative(XSElementDecl elmDecl,
XSTypeAlternativeImpl typeAlt) {
+ elmDecl.addTypeAlternative(typeAlt);
+ }
+
+ /**
* get one global attribute
*/
public final XSAttributeDecl getGlobalAttributeDecl(String declName) {
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=674639&r1=674638&r2=674639&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
Mon Jul 7 14:16:16 2008
@@ -50,6 +50,7 @@
// all possible schema element names
public static final String ELT_ALL = "all".intern();
+ public static final String ELT_ALTERNATIVE =
"alternative".intern();
public static final String ELT_ANNOTATION =
"annotation".intern();
public static final String ELT_ANY = "any".intern();
public static final String ELT_ANYATTRIBUTE =
"anyAttribute".intern();
@@ -122,17 +123,20 @@
public static final String ATT_SYSTEM = "system".intern();
public static final String ATT_PUBLIC = "public".intern();
public static final String ATT_TARGETNAMESPACE =
"targetNamespace".intern();
+ public static final String ATT_TEST = "test".intern();
public static final String ATT_TYPE = "type".intern();
public static final String ATT_USE = "use".intern();
public static final String ATT_VALUE = "value".intern();
public static final String ATT_VERSION = "version".intern();
public static final String ATT_XML_LANG = "xml:lang".intern();
public static final String ATT_XPATH = "xpath".intern();
+ public static final String ATT_XPATH_DEFAULT_NS =
"xpathDefaultNamespace".intern();
public static final String ATT_MINVERSION =
"minVersion".intern();
- public static final String ATT_MAXVERSION =
"maxVersion".intern();
+ public static final String ATT_MAXVERSION =
"maxVersion".intern();
// all possible schema attribute values
public static final String ATTVAL_TWOPOUNDANY = "##any";
+ public static final String ATTVAL_TWOPOUNDDDEFAULTNS=
"##defaultNamespace";
public static final String ATTVAL_TWOPOUNDLOCAL = "##local";
public static final String ATTVAL_TWOPOUNDOTHER = "##other";
public static final String ATTVAL_TWOPOUNDTARGETNS = "##targetNamespace";
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java?rev=674639&r1=674638&r2=674639&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
Mon Jul 7 14:16:16 2008
@@ -18,6 +18,7 @@
package org.apache.xerces.impl.xs;
import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
import org.apache.xerces.impl.xs.identity.IdentityConstraint;
import org.apache.xerces.xs.ShortList;
import org.apache.xerces.xs.XSAnnotation;
@@ -73,6 +74,11 @@
static final int INITIAL_SIZE = 2;
int fIDCPos = 0;
IdentityConstraint[] fIDConstraints = new IdentityConstraint[INITIAL_SIZE];
+
+ int fTypeAlternativePos = 0;
+ XSTypeAlternativeImpl[] fTypeAlternatives = new
XSTypeAlternativeImpl[INITIAL_SIZE];
+ XSTypeAlternativeImpl fDefaultTypeDef = null;
+
// The namespace schema information item corresponding to the target
namespace
// of the element declaration, if it is globally declared; or null
otherwise.
private XSNamespaceItem fNamespaceItem = null;
@@ -126,6 +132,66 @@
}
/**
+ * Checks whether there is a possibility that the type table
+ * is complete. (ie the last alternative element in the table
+ * has no test attribute)
+ */
+ public boolean isTypeTableOK() {
+ if (fTypeAlternativePos > 1) {
+ for (int i=0; i<fTypeAlternativePos-1; i++) {
+ if (fTypeAlternatives[i].getTest() == null) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public void addTypeAlternative(XSTypeAlternativeImpl typeAlternative) {
+ if (fTypeAlternativePos == fTypeAlternatives.length) {
+ fTypeAlternatives = resize(fTypeAlternatives,
fTypeAlternativePos*2);
+ }
+ fTypeAlternatives[fTypeAlternativePos++] = typeAlternative;
+ }
+
+ public XSTypeAlternativeImpl[] getTypeAlternatives() {
+ if (fTypeAlternativePos == 0) {
+ return null;
+ }
+ if (fTypeAlternativePos < fTypeAlternatives.length) {
+ fTypeAlternatives = resize(fTypeAlternatives, fTypeAlternativePos);
+ }
+ return fTypeAlternatives;
+ }
+
+ public XSTypeAlternativeImpl getDefaultTypeDefinition() {
+ return fDefaultTypeDef;
+ }
+
+ public void setDefualtTypeDefinition() {
+ if (fTypeAlternativePos == 0) {
+ //no type alternatives found on the element decl
+ fDefaultTypeDef = null;
+ }
+ else {
+ //now that we have at least one type alternative we can assign a
value
+ //to the default type definition attribute
+ if (fTypeAlternatives[fTypeAlternativePos-1].getTest() == null) {
+ fDefaultTypeDef = fTypeAlternatives[fTypeAlternativePos-1];
+ }
+ else {
+ fDefaultTypeDef = new XSTypeAlternativeImpl(fName, fType,
XSObjectListImpl.EMPTY_LIST);
+ }
+ }
+ }
+
+ static final XSTypeAlternativeImpl[] resize(XSTypeAlternativeImpl[]
oldArray, int newSize) {
+ XSTypeAlternativeImpl[] newArray = new XSTypeAlternativeImpl[newSize];
+ System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length,
newSize));
+ return newArray;
+ }
+
+ /**
* get the string description of this element
*/
private String fDescription = null;
Added:
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=674639&view=auto
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
(added)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
Mon Jul 7 14:16:16 2008
@@ -0,0 +1,54 @@
+/*
+ * 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.alternative;
+
+import org.apache.xerces.impl.xpath.XPath20;
+
+/**
+ * XML schema type alternative test attribute
+ *
+ * @author Hiranya Jayathilaka, University of Moratuwa
+ * @version $Id:$
+ */
+public class Test {
+
+ /** The type alternative to which the test belongs */
+ protected final XSTypeAlternativeImpl fTypeAlternative;
+
+ /** XPath 2.0 expression */
+ protected final XPath20 fXPath;
+
+ /** Constructs a test for type alternatives */
+ public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative) {
+ fXPath = xpath;
+ fTypeAlternative = typeAlternative;
+ }
+
+ public XSTypeAlternativeImpl getTypeAlternative() {
+ return fTypeAlternative;
+ }
+
+ /** Returns the test XPath */
+ public XPath20 getXPath() {
+ return fXPath;
+ }
+
+ public String toString() {
+ return fXPath.toString();
+ }
+}
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java?rev=674639&view=auto
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
(added)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
Mon Jul 7 14:16:16 2008
@@ -0,0 +1,142 @@
+/*
+ * 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.alternative;
+
+import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSNamespaceItem;
+import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSTypeAlternative;
+import org.apache.xerces.xs.XSTypeDefinition;
+
+/**
+ * XML schema type alternative component
+ *
+ * @author Hiranya Jayathilaka, University of Moratuwa
+ * @version $Id:$
+ */
+public class XSTypeAlternativeImpl implements XSTypeAlternative {
+
+ /** Name of the owning element */
+ protected final String fElementName;
+
+ /** The restricted XPath 2.0 expression that represents the test attribute
*/
+ protected Test fTestExpr = null;
+
+ /** The type definition associated with the type alternative component */
+ protected XSTypeDefinition fTypeDefinition;
+
+ /** Optional annotations */
+ protected XSObjectList fAnnotations = null;
+
+ /** Default XPath namespace */
+ protected String fXPathDefaultNamespace = null;
+
+ /** Constructor */
+ public XSTypeAlternativeImpl(String elementName, XSTypeDefinition type,
XSObjectList annotations) {
+ //A type alternative must belong to some element decl and
+ //also must have a type definition property
+ fElementName = elementName;
+ fTypeDefinition = type;
+ }
+
+ /** Sets the test attribute value */
+ public void setTest(Test expr) {
+ fTestExpr = expr;
+ }
+
+ public void setAnnotations(XSObjectList annotations) {
+ fAnnotations = annotations;
+ }
+
+ public void setXPathDefauleNamespace(String namespace) {
+ fXPathDefaultNamespace = namespace;
+ }
+
+ //gets the name of the owning element
+ public String getElementName() {
+ return fElementName;
+ }
+
+ public String getXPathDefaultNamespace() {
+ return fXPathDefaultNamespace;
+ }
+
+ /** Returns a String representation of this object */
+ public String toString() {
+ String s = super.toString();
+ int index1 = s.lastIndexOf('$');
+ if (index1 != -1) {
+ return s.substring(index1 + 1);
+ }
+ int index2 = s.lastIndexOf('.');
+ if (index2 != -1) {
+ return s.substring(index2 + 1);
+ }
+ return s;
+ }
+
+ public boolean equals(XSTypeAlternativeImpl typeAlternative) {
+ //ToDo
+ return false;
+ }
+
+ /** Get the optional annotations */
+ public XSObjectList getAnnotations() {
+ return fAnnotations;
+ }
+
+ public String getTestStr() {
+ return (fTestExpr != null) ? fTestExpr.toString() : null;
+ }
+
+ public Test getTest() {
+ return fTestExpr;
+ }
+
+ public XSTypeDefinition getTypeDefinition() {
+ return fTypeDefinition;
+ }
+
+ /**
+ * @see org.apache.xerces.xs.XSObject#getName()
+ */
+ public String getName() {
+ return null;
+ }
+
+ /**
+ * @see org.apache.xerces.xs.XSObject#getNamespace()
+ */
+ public String getNamespace() {
+ return null;
+ }
+
+ /**
+ * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
+ */
+ public XSNamespaceItem getNamespaceItem() {
+ return null;
+ }
+
+ /**
+ * Get the type of the object
+ */
+ public short getType() {
+ return XSConstants.TYPE_ALTERNATIVE;
+ }
+}
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/XSTypeAlternativeImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java?rev=674639&r1=674638&r2=674639&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
Mon Jul 7 14:16:16 2008
@@ -119,6 +119,9 @@
public static final int ATTIDX_FROMDEFAULT = ATTIDX_COUNT++;
//public static final int ATTIDX_OTHERVALUES = ATTIDX_COUNT++;
public static final int ATTIDX_ISRETURNED = ATTIDX_COUNT++;
+
+ // Schema 1.1
+ public static final int ATTIDX_XPATHDEFAULTNS = ATTIDX_COUNT++;
private static final XIntPool fXIntPool = new XIntPool();
// constants to return
@@ -203,6 +206,7 @@
protected static final int DT_BOOLEAN = -15;
protected static final int DT_NONNEGINT = -16;
protected static final int DT_POSINT = -17;
+ protected static final int DT_XPATH_DEFAULT_NS = -18;
static {
// step 2: all possible attributes for all elements
@@ -255,6 +259,8 @@
int ATT_XML_LANG = attCount++;
int ATT_XPATH_R = attCount++;
int ATT_XPATH1_R = attCount++;
+ int ATT_TEST_XPATH_R = attCount++;
+ int ATT_DEFAULT_XPATH_NS_N = attCount++;
// step 3: store all these attributes in an array
OneAttr[] allAttrs = new OneAttr[attCount];
@@ -450,6 +456,14 @@
DT_XPATH1,
ATTIDX_XPATH,
null);
+ allAttrs[ATT_TEST_XPATH_R] = new OneAttr(SchemaSymbols.ATT_TEST,
+ DT_XPATH1,
+ ATTIDX_XPATH,
+ null);
+ allAttrs[ATT_DEFAULT_XPATH_NS_N]= new
OneAttr(SchemaSymbols.ATT_XPATH_DEFAULT_NS,
+ DT_XPATH_DEFAULT_NS,
+ ATTIDX_XPATHDEFAULTNS,
+ null);
// step 4: for each element, make a list of possible attributes
Container attrList;
@@ -913,6 +927,21 @@
fEleAttrsMapL.put(SchemaSymbols.ELT_MININCLUSIVE, attrList);
// for element "minExclusive" - local
fEleAttrsMapL.put(SchemaSymbols.ELT_MINEXCLUSIVE, attrList);
+
+ // XML Schema 1.1
+
+ // for element "alternative" - local
+ attrList = Container.getContainer(4);
+ // id = ID
+ attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
+ // test = an XPath expression
+ attrList.put(SchemaSymbols.ATT_TEST, allAttrs[ATT_TEST_XPATH_R]);
+ // type = QName
+ attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]);
+ // xpathDefaultNamespace = (anyURI | (##defaultNamespace |
##targetNamespace | ##local))
+ attrList.put(SchemaSymbols.ATT_XPATH_DEFAULT_NS,
allAttrs[ATT_DEFAULT_XPATH_NS_N]);
+ // TODO: use 1.1 map
+ fEleAttrsMapL.put(SchemaSymbols.ELT_ALTERNATIVE, attrList);
}
// used to resolver namespace prefixes
@@ -1517,6 +1546,27 @@
throw new
InvalidDatatypeValueException("cvc-enumeration-valid",
new Object[]{value,
"(preserve | replace | collapse)"});
break;
+ case DT_XPATH_DEFAULT_NS:
+ // value = anyURI | ##defaultNamespace | ##targetNamespace |
##local
+ retValue = null;
+ if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDTARGETNS)) {
+ retValue = schemaDoc.fTargetNamespace;
+ } else if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDDDEFAULTNS)) {
+ retValue =
schemaDoc.fValidationContext.getURI(XMLSymbols.EMPTY_STRING);
+ if (retValue != null) {
+ retValue = fSymbolTable.addSymbol((String)retValue);
+ }
+ } else if (!value.equals(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL)){
+ // we have found namespace URI here
+ // need to add it to the symbol table
+ try {
+ fExtraDVs[DT_ANYURI].validate(value,
schemaDoc.fValidationContext, null);
+ retValue = fSymbolTable.addSymbol(value);
+ } catch (InvalidDatatypeValueException ide) {
+ throw new
InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value,
"anyURI | ##defaultNamespace | ##targetNamespace | ##local"});
+ }
+ }
+ break;
}
return retValue;
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?rev=674639&r1=674638&r2=674639&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
Mon Jul 7 14:16:16 2008
@@ -17,6 +17,7 @@
package org.apache.xerces.impl.xs.traversers;
+import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.dv.ValidatedInfo;
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.xs.SchemaGrammar;
@@ -57,7 +58,7 @@
* substitutionGroup = QName
* type = QName
* {any attributes with non-schema namespace . . .}>
- * Content: (annotation?, ((simpleType | complexType)?, (unique | key |
keyref)*))
+ * Content: (annotation?, ((simpleType | complexType)?, alternative*,
(unique | key | keyref)*))
* </element>
*
* @xerces.internal
@@ -395,6 +396,25 @@
// see if there's something here; it had better be key, keyref or
unique.
if (child != null) {
String childName = DOMUtil.getLocalName(child);
+
+ // if XML Schema 1.1, check for alternative types first
+ if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1)
{
+ while (child.equals(SchemaSymbols.ELT_ALTERNATIVE)) {
+
fSchemaHandler.fTypeAlternativeTraverser.traverse(child, element, schemaDoc,
grammar);
+ child = DOMUtil.getNextSiblingElement(child);
+ if (child != null) {
+ childName = DOMUtil.getLocalName(child);
+ }
+ else {
+ if (!element.isTypeTableOK()) {
+ reportSchemaError("src-element.5", new
Object[]{nameAtt}, elmDecl);
+ }
+ element.setDefualtTypeDefinition();
+ break;
+ }
+ }
+ }
+
while (child != null &&
(childName.equals(SchemaSymbols.ELT_KEY) ||
childName.equals(SchemaSymbols.ELT_KEYREF) ||
@@ -440,7 +460,7 @@
// element
if (child != null) {
- reportSchemaError("s4s-elt-must-match.1", new Object[]{nameAtt,
"(annotation?, (simpleType | complexType)?, (unique | key | keyref)*))",
DOMUtil.getLocalName(child)}, child);
+ reportSchemaError("s4s-elt-must-match.1", new Object[]{nameAtt,
"(annotation?, (simpleType | complexType)?, alternative*, (unique | key |
keyref)*))", DOMUtil.getLocalName(child)}, child);
}
// Step 4: check 3.3.3 constraints
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=674639&r1=674638&r2=674639&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
Mon Jul 7 14:16:16 2008
@@ -361,6 +361,7 @@
XSDKeyrefTraverser fKeyrefTraverser;
XSDNotationTraverser fNotationTraverser;
XSDSimpleTypeTraverser fSimpleTypeTraverser;
+ XSDTypeAlternativeTraverser fTypeAlternativeTraverser;
XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser;
XSDWildcardTraverser fWildCardTraverser;
@@ -1891,6 +1892,7 @@
fKeyrefTraverser = new XSDKeyrefTraverser(this, fAttributeChecker);
fNotationTraverser = new XSDNotationTraverser(this, fAttributeChecker);
fSimpleTypeTraverser = new XSDSimpleTypeTraverser(this,
fAttributeChecker);
+ fTypeAlternativeTraverser = new XSDTypeAlternativeTraverser(this,
fAttributeChecker);
fUniqueOrKeyTraverser = new XSDUniqueOrKeyTraverser(this,
fAttributeChecker);
fWildCardTraverser = new XSDWildcardTraverser(this, fAttributeChecker);
} // createTraversers()
@@ -1965,6 +1967,7 @@
fKeyrefTraverser.reset(fSymbolTable, fValidateAnnotations);
fNotationTraverser.reset(fSymbolTable, fValidateAnnotations);
fSimpleTypeTraverser.reset(fSymbolTable, fValidateAnnotations);
+ fTypeAlternativeTraverser.reset(fSymbolTable, fValidateAnnotations);
fUniqueOrKeyTraverser.reset(fSymbolTable, fValidateAnnotations);
fWildCardTraverser.reset(fSymbolTable, fValidateAnnotations);
Added:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java?rev=674639&view=auto
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
(added)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
Mon Jul 7 14:16:16 2008
@@ -0,0 +1,176 @@
+/*
+ * 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.traversers;
+
+import org.apache.xerces.impl.xpath.XPath20;
+import org.apache.xerces.impl.xpath.XPathException;
+import org.apache.xerces.impl.xs.SchemaGrammar;
+import org.apache.xerces.impl.xs.SchemaSymbols;
+import org.apache.xerces.impl.xs.XSAnnotationImpl;
+import org.apache.xerces.impl.xs.XSElementDecl;
+import org.apache.xerces.impl.xs.alternative.Test;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.util.DOMUtil;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSTypeDefinition;
+import org.w3c.dom.Element;
+
+/**
+ * The traverser implementation for XML schema type alternatives.
+ *
+ * <alternative
+ * id = ID
+ * test = an XPath expression
+ * type = QName
+ * xpathDefaultNamespace = (anyURI | (##defaultNamespace |
##targetNamespace | ##local))
+ * {any attributes with non-schema namespace . . .}>
+ * Content: (annotation?, (simpleType | complexType)?)
+ * </alternative>
+ *
+ * @author Hiranya Jayathilaka, University of Moratuwa
+ * @version $Id:$
+ */
+class XSDTypeAlternativeTraverser extends XSDAbstractTraverser {
+
+ XSDTypeAlternativeTraverser (XSDHandler handler,
+ XSAttributeChecker attrChecker) {
+ super(handler, attrChecker);
+ }
+
+ /**
+ * Traverse the given alternative element and update the
+ * schema grammar. Validate the content of the type alternative
+ * element.
+ */
+ public void traverse(Element altElement, XSElementDecl element,
+ XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
+
+ Object[] attrValues = fAttrChecker.checkAttributes(altElement, false,
schemaDoc);
+ QName typeAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_TYPE];
+ String test = (String) attrValues[XSAttributeChecker.ATTIDX_XPATH];
+ String xpathNS = (String)
attrValues[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS];
+
+ // get 'annotation'
+ Element childNode = DOMUtil.getFirstChildElement(altElement);
+ XSAnnotationImpl annotation = null;
+ //first child could be an annotation
+ if (childNode != null &&
DOMUtil.getLocalName(childNode).equals(SchemaSymbols.ELT_ANNOTATION)) {
+ annotation = traverseAnnotationDecl(childNode, attrValues, false,
schemaDoc);
+ //now move on to the next child element
+ childNode = DOMUtil.getNextSiblingElement(childNode);
+ }
+ else {
+ String text = DOMUtil.getSyntheticAnnotation(altElement);
+ if (text != null) {
+ annotation = traverseSyntheticAnnotation(altElement, text,
attrValues, false, schemaDoc);
+ }
+ //here we remain in the first child element
+ }
+
+ XSObjectList annotations = null;
+ if (annotation != null) {
+ annotations = new XSObjectListImpl();
+ ((XSObjectListImpl)annotations).add(annotation);
+ }
+ else {
+ //if no annotations are present add an empty list to the type
alternative
+ annotations = XSObjectListImpl.EMPTY_LIST;
+ }
+
+ // get 'type definition'
+ XSTypeDefinition alternativeType = null;
+ boolean hasAnonType = false;
+
+ if (typeAtt != null) {
+ alternativeType =
(XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc,
XSDHandler.TYPEDECL_TYPE, typeAtt, altElement);
+ }
+
+ // check whether the childNode still points to something...
+ // if it does it must be an anonymous type declaration
+ if (childNode != null) {
+ // traverse any anonymous type declarations present
+ // do not care whether the type attr is present or not
+ String childName = DOMUtil.getLocalName(childNode);
+ XSTypeDefinition typeDef = null;
+ if (childName.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {
+ typeDef =
fSchemaHandler.fComplexTypeTraverser.traverseLocal(childNode, schemaDoc,
grammar);
+ hasAnonType = true;
+ childNode = DOMUtil.getNextSiblingElement(childNode);
+ }
+ else if (childName.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
+ typeDef =
fSchemaHandler.fSimpleTypeTraverser.traverseLocal(childNode, schemaDoc,
grammar);
+ hasAnonType = true;
+ childNode = DOMUtil.getNextSiblingElement(childNode);
+ }
+
+ if (alternativeType == null) {
+ alternativeType = typeDef;
+ }
+
+ // type and either <simpleType> or <complexType> are mutually
exclusive.
+ if (hasAnonType && (typeAtt != null)) {
+ reportSchemaError("src-type-alternative.3.12.13.1", null,
altElement);
+ }
+ }
+
+ // if the type definition component is not present..
+ // i.e. test attr value is absent, or no anonymous types are defined
+ if (typeAtt == null || !hasAnonType) {
+ reportSchemaError("src-type-alternative.3.12.13.2", null,
altElement);
+ }
+
+ // fall back to the element declaration's type
+ if (alternativeType == null) {
+ alternativeType= element.fType;
+ }
+
+ // not expecting any more children
+ if (childNode != null) {
+ //reportSchemaError("s4s-elt-must-match.1", new Object[] { "type
alternative", "(annotation?, (simpleType|complexType)?)",
childNode.getLocalName() }, altElement);
+ reportSchemaError("s4s-elt-must-match.1", new Object[]{"type
alternative", "(annotation?, (simpleType | complexType)?)",
DOMUtil.getLocalName(childNode)}, childNode);
+ }
+
+ // create type alternative
+ XSTypeAlternativeImpl typeAlternative = new
XSTypeAlternativeImpl(element.fName, alternativeType, annotations);
+
+ // now look for other optional attributes like test and
xpathDefaultNamespace
+ if (test != null) {
+ Test testExpr = null;
+ //set the test attribute value
+ try {
+ testExpr = new Test(new XPath20(test, fSymbolTable,
schemaDoc.fNamespaceSupport), typeAlternative);
+ }
+ catch (XPathException e) {
+ //if the xpath is invalid create a Test without an expression
+ reportSchemaError(e.getKey(), new Object[] { test },
altElement);
+ testExpr = new Test(null, typeAlternative);
+ }
+ typeAlternative.setTest(testExpr);
+ }
+
+ if (xpathNS != null) {
+ //set the xpathDefaultNamespace attribute value
+ typeAlternative.setXPathDefauleNamespace(xpathNS);
+ }
+
+ grammar.addTypeAlternative(element, typeAlternative);
+ fAttrChecker.returnAttrArray(attrValues, schemaDoc);
+ }
+}
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSConstants.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSConstants.java?rev=674639&r1=674638&r2=674639&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSConstants.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSConstants.java
Mon Jul 7 14:16:16 2008
@@ -79,6 +79,11 @@
* The object describes enumeration and pattern facets.
*/
public static final short MULTIVALUE_FACET = 14;
+
+ /**
+ * The object describes a XML schema type alternative
+ */
+ public static final short TYPE_ALTERNATIVE = 15;
// Derivation constants
/**
Added:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java?rev=674639&view=auto
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
(added)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
Mon Jul 7 14:16:16 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.xs;
+
+/**
+ * This interface represents the XML schema type alternative
+ * component. Tyepe alternative component was first introduced
+ * in the XML schema structures 1.1 specification as a means
+ * of implementing conditional type assignment.
+ *
+ * @author Hiranya Jayathilaka, University of Moratuwa
+ * @version $Id:$
+ */
+public interface XSTypeAlternative extends XSObject {
+
+ /**
+ * A sequence of [annotations] or an empty <code>XSObjectList</code>.
+ */
+ public XSObjectList getAnnotations();
+
+ /**
+ * [test]: a restricted XPath 2.0 expression or null.
+ */
+ public String getTestStr();
+
+ /**
+ * [type definition]: a valid type definition component
+ */
+ public XSTypeDefinition getTypeDefinition();
+}
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSTypeAlternative.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]