You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by er...@locus.apache.org on 2000/12/08 19:20:29 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema SchemaMessageProvider.java SchemaSymbols.java TraverseSchema.java
ericye 00/12/08 10:20:29
Modified: java/src/org/apache/xerces/msg SchemaMessages.java
java/src/org/apache/xerces/validators/datatype
DatatypeValidatorFactoryImpl.java
java/src/org/apache/xerces/validators/schema
SchemaMessageProvider.java SchemaSymbols.java
TraverseSchema.java
Added: java/src/org/apache/xerces/validators/datatype
UnionDatatypeValidator.java
Log:
Elena's updates on CR schema support
Revision Changes Path
1.4 +5 -1 xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java
Index: SchemaMessages.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaMessages.java 2000/04/04 21:14:22 1.3
+++ SchemaMessages.java 2000/12/08 18:20:26 1.4
@@ -63,7 +63,7 @@
* This file contains error and warning messages for the Schema validator
* The messages are arranged in key and value tuples in a ListResourceBundle.
*
- * @version $Id: SchemaMessages.java,v 1.3 2000/04/04 21:14:22 andyc Exp $
+ * @version $Id: SchemaMessages.java,v 1.4 2000/12/08 18:20:26 ericye Exp $
*/
public class SchemaMessages extends ListResourceBundle {
/** The list resource bundle contents. */
@@ -93,6 +93,10 @@
{ "TypeAlreadySet", "The type of the element has already been declared." },
{ "GenericError", "Schema error: {0}." },
{ "UnexpectedError", "UnexpectedError" },
+ {"ContentError", "Content (annotation?,..) is incorrect for type {0}"},
+ {"AnnotationError", "Annotation can only appear once: type {0}"},
+ {"ListUnionRestrictionError","List | Union | Restriction content is invalid for type {0}"}
+
};
/** Returns the list resource bundle contents. */
1.17 +16 -1 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java
Index: DatatypeValidatorFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DatatypeValidatorFactoryImpl.java 2000/12/02 01:05:40 1.16
+++ DatatypeValidatorFactoryImpl.java 2000/12/08 18:20:27 1.17
@@ -62,6 +62,7 @@
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.validators.datatype.DatatypeValidatorFactory;
import org.apache.xerces.validators.datatype.InvalidDatatypeFacetException;
+import java.util.Vector;
/**
@@ -86,7 +87,7 @@
*
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.16 2000/12/02 01:05:40 jeffreyr Exp $
+ * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.17 2000/12/08 18:20:27 ericye Exp $
*/
public class DatatypeValidatorFactoryImpl implements DatatypeValidatorFactory {
@@ -343,6 +344,20 @@
//initializeDTDRegistry();
}
}
+
+ public DatatypeValidator createDatatypeValidator(String typeName, Vector validators) {
+ DatatypeValidator simpleType = null;
+ if (validators!=null) {
+ simpleType = new UnionDatatypeValidator(validators);
+ }
+ if (simpleType !=null) {
+ addValidator(typeName, simpleType);
+ }
+ return simpleType;
+ }
+
+
+
public DatatypeValidator createDatatypeValidator(String typeName,
DatatypeValidator base, Hashtable facets, boolean list ) throws InvalidDatatypeFacetException {
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/UnionDatatypeValidator.java
Index: UnionDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
import java.text.Collator;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.utils.regex.RegularExpression;
/**
* @author Jeffrey Rodriguez
* @author Elena Litani
* UnionValidator validates that XML content is a W3C string type.
* Implements the September 22 XML Schema datatype Union Datatype type
*/
public class UnionDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private Vector fBaseValidators = null; // union collection of validators
private DatatypeValidator fBaseValidator = null; // Native datatypes have null
private int fValidatorsSize = 0;
private String fPattern = null;
private Vector fEnumeration = null;
private int fFacetsDefined = 0;
private boolean fDerivedByUnion = false; //default
private StringBuffer errorMsg = null;
private RegularExpression fRegex = null;
public UnionDatatypeValidator () throws InvalidDatatypeFacetException{
this( null, null, false ); // Native, No Facets defined, Restriction
}
public UnionDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedBy ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
fDerivedByUnion = derivedBy; // always false - derived datatype
//facets allowed are: pattern & enumeration
if ( facets != null ) {
for ( Enumeration e = facets.keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_ENUMERATION) ) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
fEnumeration = (Vector)facets.get(key);
} else if ( key.equals(SchemaSymbols.ELT_PATTERN) ) {
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = (String)facets.get(key);
fRegex = new RegularExpression(fPattern, "X");
} else {
throw new InvalidDatatypeFacetException("invalid facet tag : " + key);
}
} //end for
}// End of Facets Setting
}
public UnionDatatypeValidator ( Vector base) {
if ( base !=null ) {
fValidatorsSize = base.size();
fBaseValidators = new Vector(fValidatorsSize);
fDerivedByUnion = true; //native union decl
fBaseValidators = base;
}
}
/**
* validate that a string is a W3C string type
*
* @param content A string containing the content to be validated
* @param list
* @exception throws InvalidDatatypeException if the content is
* not a W3C string type
* @exception InvalidDatatypeValueException
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException
{
if ( content == null && state != null ) {
this.fBaseValidator.validate( content, state );//Passthrough setup information
//for state validators
} else {
checkContent( content, state);
}
return(null);
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
/**
*
* @return A Hashtable containing the facets
* for this datatype.
*/
public Hashtable getFacets(){
return(null);
}
public int compare( String content, String facetValue ){
// if derive by list then this should iterate through
// the tokens in each string and compare using the base type
// compare function.
// if not derived by list just pass the compare down to the
// base type.
return(0);
}
/**
* Returns a copy of this object.
*/
public Object clone() throws CloneNotSupportedException {
UnionDatatypeValidator newObj = null;
try {
newObj = new UnionDatatypeValidator();
newObj.fLocale = this.fLocale;
newObj.fBaseValidator = this.fBaseValidator;
newObj.fBaseValidators = (Vector)this.fBaseValidators.clone();
newObj.fPattern = this.fPattern;
newObj.fEnumeration = this.fEnumeration;
newObj.fFacetsDefined = this.fFacetsDefined;
newObj.fDerivedByUnion = this.fDerivedByUnion;
} catch ( InvalidDatatypeFacetException ex ) {
ex.printStackTrace();
}
return(newObj);
}
// Private methods
private void checkContent( String content, Object state ) throws InvalidDatatypeValueException
{
//Facet pattern can be checked here
//Facet enumeration requires to know if valiadation occurs against ListDatatype
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
if ( fRegex == null || fRegex.matches( content) == false )
throw new InvalidDatatypeValueException("Value '"+content+
"' does not match regular expression facet '" + fPattern + "'." );
}
//validate against parent type
if ( this.fBaseValidator != null ) {
((UnionDatatypeValidator)this.fBaseValidator).checkContent( content, state , fPattern, fEnumeration );
}
}
private void checkContent( String content, Object state, String pattern, Vector enum ) throws InvalidDatatypeValueException
{
int index = -1; //number of validators
boolean valid=false;
DatatypeValidator currentDV = null;
while ( (fValidatorsSize-1) > index++ ) { //check content against each validator in Union
currentDV = (DatatypeValidator)this.fBaseValidators.get(index);
if ( valid ) {//content is valid
break;
}
try {
if ( currentDV instanceof ListDatatypeValidator ) {
if ( pattern != null ) {
throw new InvalidDatatypeValueException("Facet \"Pattern\" can not be applied to a list datatype" );
} else if ( enum != null ) { //Check each token against enumeration
StringTokenizer parsedList = new StringTokenizer( content );
String token = null;
while ( parsedList.hasMoreTokens() ) { //Check each token in list against base type
token = parsedList.nextToken();
if ( enum.contains( token ) == false ) {
throw new InvalidDatatypeValueException("Value '"+
content+"' must be one of "+enum);
}
}
}
((ListDatatypeValidator)currentDV).validate( content, state );
}
else if ( currentDV instanceof UnionDatatypeValidator ) {
((UnionDatatypeValidator)currentDV).checkContent( content, state, pattern, enum );
} else {
if ( enum != null ) {
if ( enum.contains( content ) == false )
throw new InvalidDatatypeValueException("Value '"+
content+"' must be one of "
+ enum);
}
((DatatypeValidator)currentDV).validate( content, state );
}
valid=true;
} catch ( InvalidDatatypeValueException e ) {
//REVIST: is it the right way to record error messages?
if ( errorMsg == null ) {
errorMsg = new StringBuffer();
}
errorMsg.append('\n');
errorMsg.append(e.getMessage());
valid=false;
}
}
if ( !valid ) {
throw new InvalidDatatypeValueException( this.errorMsg.toString());
}
}
private void setBasetype( DatatypeValidator base) {
fBaseValidator = base;
}
}
1.4 +6 -0 xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java
Index: SchemaMessageProvider.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaMessageProvider.java 2000/05/17 18:33:25 1.3
+++ SchemaMessageProvider.java 2000/12/08 18:20:28 1.4
@@ -158,6 +158,9 @@
TypeAlreadySet = 22,
GenericError = 23,
UnclassifiedError = 24,
+ ContentError = 25,
+ AnnotationError = 26,
+ ListUnionRestrictionError = 27,
// ...
MSG_MAX_CODE = 31;
//
@@ -192,5 +195,8 @@
"TypeAlreadySet", // 22, "The type of the element has already been declared."
"GenericError", // 23, "Schema error: {0}."
"UnclassifiedError", // 24, "Unclassified error."
+ "ContentError", // 25, "Content (annotation?,..) is incorrect for type {0}"
+ "AnnotationError", // 26, "Annotation can only appear once: type {0}"
+ "ListUnionRestrictionError" // 27, "List | Union | Restriction content is invalid for type {0}"
};
}
1.7 +4 -0 xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaSymbols.java
Index: SchemaSymbols.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaSymbols.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SchemaSymbols.java 2000/08/01 23:54:17 1.6
+++ SchemaSymbols.java 2000/12/08 18:20:28 1.7
@@ -87,6 +87,7 @@
public static final String ELT_ELEMENT = "element";
public static final String ELT_ENCODING = "encoding";
public static final String ELT_ENUMERATION = "enumeration";
+ public static final String ELT_WHITESPACE = "whiteSpace";
public static final String ELT_GROUP = "group";
public static final String ELT_IMPORT = "import";
public static final String ELT_INCLUDE = "include";
@@ -112,6 +113,8 @@
public static final String ATT_ABSTRACT = "abstract";
public static final String ATT_ATTRIBUTEFORMDEFAULT = "attributeFormDefault";
public static final String ATT_BASE = "base";
+ public static final String ATT_ITEMTYPE = "itemType";
+ public static final String ATT_MEMBERTYPES = "memberTypes";
public static final String ATT_BLOCK = "block";
public static final String ATT_BLOCKDEFAULT = "blockDefault";
public static final String ATT_CONTENT = "content";
@@ -152,6 +155,7 @@
public static final String ATTVAL_HEX = "hex";
public static final String ATTVAL_ID = "ID";
public static final String ATTVAL_LAX = "lax";
+ public static final String ATTVAL_UNION = "union";
public static final String ATTVAL_LIST = "list";
public static final String ATTVAL_MAXLENGTH = "maxLength";
public static final String ATTVAL_MINLENGTH = "minLength";
1.66 +321 -2 xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
Index: TraverseSchema.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- TraverseSchema.java 2000/12/02 01:08:11 1.65
+++ TraverseSchema.java 2000/12/08 18:20:28 1.66
@@ -67,6 +67,7 @@
import org.apache.xerces.validators.schema.XUtil;
import org.apache.xerces.validators.datatype.DatatypeValidator;
import org.apache.xerces.validators.datatype.DatatypeValidatorFactoryImpl;
+import org.apache.xerces.validators.datatype.UnionDatatypeValidator; //CR implementation
import org.apache.xerces.validators.datatype.InvalidDatatypeValueException;
import org.apache.xerces.utils.StringPool;
import org.w3c.dom.Element;
@@ -374,7 +375,7 @@
*
* @see org.apache.xerces.validators.common.Grammar
*
- * @version $Id: TraverseSchema.java,v 1.65 2000/12/02 01:08:11 ericye Exp $
+ * @version $Id: TraverseSchema.java,v 1.66 2000/12/08 18:20:28 ericye Exp $
*/
public class TraverseSchema implements
@@ -387,7 +388,11 @@
//debuggin
private static boolean DEBUGGING = false;
- //private data members
+
+ //CR Implementation
+ private static boolean DEBUG_UNION = false;
+ private static boolean CR_IMPL = false;
+ //private data members
private XMLErrorReporter fErrorReporter = null;
@@ -1055,6 +1060,9 @@
*/
private int traverseSimpleTypeDecl( Element simpleTypeDecl ) throws Exception {
+ if ( CR_IMPL ) {
+ return traverseSimpleType(simpleTypeDecl);
+ }
String varietyProperty = simpleTypeDecl.getAttribute( SchemaSymbols.ATT_DERIVEDBY );
if (varietyProperty.length() == 0) {
varietyProperty = SchemaSymbols.ATTVAL_RESTRICTION;
@@ -1200,6 +1208,317 @@
}
return fStringPool.addSymbol(nameOfType);
}
+
+ //@param: elm - top element
+ //@param: content - content must be annotation? or some other simple content
+ //@param: isEmpty: -- true if (annotation?, smth_else), false if (annotation?)
+ //check for Annotation if it is present
+
+ //REVISIT: this function should be used in all traverse* methods!
+ private Element checkContent( Element elm, Element content, boolean isEmpty ) throws Exception {
+ //isEmpty = true-> means content can be null!
+ if ( content == null) {
+ if (!isEmpty) {
+ reportSchemaError(SchemaMessageProvider.ContentError,
+ new Object [] { elm.getAttribute( SchemaSymbols.ATT_NAME )});
+ }
+ return null;
+ }
+ if (content.getNodeName().equals(SchemaSymbols.ELT_ANNOTATION)) {
+ traverseAnnotationDecl( content );
+ content = XUtil.getNextSiblingElement(content);
+ if (content == null ) { //must be followed by <simpleType?>
+ if (!isEmpty) {
+ reportSchemaError(SchemaMessageProvider.ContentError,
+ new Object [] { elm.getAttribute( SchemaSymbols.ATT_NAME )});
+ }
+ return null;
+ }
+ if (content.getNodeName().equals(SchemaSymbols.ELT_ANNOTATION)) {
+ reportSchemaError(SchemaMessageProvider.AnnotationError,
+ new Object [] { elm.getAttribute( SchemaSymbols.ATT_NAME )});
+ return null;
+ }
+ //return null if expected only annotation?, else returns updated content
+ }
+ return content;
+ }
+
+
+ //@param: elm - top element
+ //@param: baseTypeStr - type (base/itemType/memberTypes)
+ //return DatatypeValidator available for the baseTypeStr.
+ //REVISIT: this function should be used in some|all traverse* methods!
+ private DatatypeValidator findDTValidator (Element elm, String baseTypeStr ) throws Exception{
+ int baseType = fStringPool.addSymbol( baseTypeStr );
+ String prefix = "";
+ DatatypeValidator baseValidator = null;
+ String localpart = baseTypeStr;
+ int colonptr = baseTypeStr.indexOf(":");
+ if ( colonptr > 0) {
+ prefix = baseTypeStr.substring(0,colonptr);
+ localpart = baseTypeStr.substring(colonptr+1);
+ }
+ String uri = resolvePrefixToURI(prefix);
+ baseValidator = getDatatypeValidator(uri, localpart);
+ if (baseValidator == null) {
+ Element baseTypeNode = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
+ if (baseTypeNode != null) {
+ traverseSimpleTypeDecl( baseTypeNode );
+
+ baseValidator = getDatatypeValidator(uri, localpart);
+ }
+ }
+ if ( baseValidator == null ) {
+ reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
+ new Object [] { elm.getAttribute( SchemaSymbols.ATT_BASE ),
+ elm.getAttribute(SchemaSymbols.ATT_NAME)});
+ }
+ return baseValidator;
+ }
+
+ //REVISIT: update comments. CR Implementation
+ private int traverseSimpleType( Element simpleTypeDecl ) throws Exception {
+
+ //REVISIT: remove all DEBUG_UNION.
+ if (DEBUG_UNION) {
+ System.out.println("----------->CR traverseSimpleType()");
+ }
+
+ //REVISIT: are we checking for attributes and other definitions that should not be there?
+ String nameProperty = simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME );
+ boolean list = false;
+ boolean union = false;
+ boolean restriction = false;
+ int newSimpleTypeName = -1;
+ if ( nameProperty.equals("")) { // anonymous simpleType
+ newSimpleTypeName = fStringPool.addSymbol(
+ "#S#"+fSimpleTypeAnonCount++ );
+ }
+ else
+ newSimpleTypeName = fStringPool.addSymbol( nameProperty );
+
+ //annotation?,(list|restriction|union)
+ Element content = XUtil.getFirstChildElement(simpleTypeDecl);
+ content = checkContent(simpleTypeDecl, content, false);
+ if (content == null) {
+ return (-1);
+ }
+ String varietyProperty = content.getNodeName();
+ String baseTypeQNameProperty = null;
+ Vector dTValidators = null;
+ int size = 0;
+ StringTokenizer unionMembers = null;
+ int numOfTypes = 0; //list/restriction = 1, union = "+"
+
+ if (DEBUG_UNION) {
+ System.out.println("[varietyProperty]:"+ varietyProperty );
+ }
+
+ if (varietyProperty.equals(SchemaSymbols.ATTVAL_LIST)) { //traverse List
+ baseTypeQNameProperty = content.getAttribute( SchemaSymbols.ATT_ITEMTYPE );
+ list = true;
+ }
+ else if (varietyProperty.equals(SchemaSymbols.ATTVAL_RESTRICTION)) { //traverse Restriction
+ baseTypeQNameProperty = content.getAttribute( SchemaSymbols.ATT_BASE );
+ restriction= true;
+ }
+ else if (varietyProperty.equals(SchemaSymbols.ATTVAL_UNION)) { //traverse union
+ union = true;
+ baseTypeQNameProperty = content.getAttribute( SchemaSymbols.ATT_MEMBERTYPES);
+ if (baseTypeQNameProperty != "" ) {
+ unionMembers = new StringTokenizer( baseTypeQNameProperty );
+ size = unionMembers.countTokens();
+ }
+ else {
+ size = 1; //at least one must be seen as <simpleType> decl
+ }
+ dTValidators = new Vector (size, 2);
+ }
+ else {
+ reportSchemaError(SchemaMessageProvider.FeatureUnsupported,
+ new Object [] { varietyProperty });
+ return -1;
+ }
+
+ int typeNameIndex;
+ DatatypeValidator baseValidator = null;
+
+ if (DEBUG_UNION) {
+ System.out.println("[nameProperty]= " +nameProperty);
+ System.out.println("[base]= " +baseTypeQNameProperty+";");
+ System.out.println("[size]= " +size);
+ if (unionMembers!=null) {
+ System.out.println("[unionMembers]= " +unionMembers.toString());
+ }
+ }
+ if ( baseTypeQNameProperty == "" ) { //must 'see' <simpleType>
+ //content = {annotation?,simpleType?...}
+ content = XUtil.getFirstChildElement(content);
+ //check content (annotation?, ...)
+ content = checkContent(simpleTypeDecl, content, false);
+ if (content == null) {
+ return (-1);
+ }
+ if (content.getNodeName().equals( SchemaSymbols.ELT_SIMPLETYPE )) { //Test...
+ typeNameIndex = traverseSimpleTypeDecl(content);
+ if (DEBUG_UNION) {
+ System.out.println("[After traverseSimpleTypeDecl]: " +fStringPool.toString(typeNameIndex));
+ System.out.println("[traverseSimpleTypeDecl]: " + nameProperty);
+ }
+ if (typeNameIndex!=-1) {
+ baseValidator=fDatatypeRegistry.getDatatypeValidator(fStringPool.toString(typeNameIndex));
+ if (baseValidator !=null && union) {
+ dTValidators.addElement((DatatypeValidator)baseValidator);
+ }
+ }
+ if ( typeNameIndex == -1 || baseValidator == null) {
+ reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
+ new Object [] { content.getAttribute( SchemaSymbols.ATT_BASE ),
+ content.getAttribute(SchemaSymbols.ATT_NAME) });
+ return -1;
+ }
+ }
+ } //end - must see simpleType?
+ else { //base was provided - get proper validator.
+ numOfTypes = 1;
+ if (union) {
+ numOfTypes= size;
+ }
+ for (int i=0; i<numOfTypes; i++) { //find all validators
+ if (union) {
+ baseTypeQNameProperty = unionMembers.nextToken();
+ }
+ baseValidator = findDTValidator ( simpleTypeDecl, baseTypeQNameProperty);
+ if ( baseValidator == null) {
+ return (-1);
+ }
+ if (union) {
+ dTValidators.addElement((DatatypeValidator)baseValidator); //add validator to structure
+ }
+ //REVISIT: Should we raise exception here?
+ // if baseValidator.isInstanceOf(LIST) and UNION
+ if ( list && (baseValidator instanceof UnionDatatypeValidator)) {
+ reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
+ new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ),
+ simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)});
+ return -1;
+ }
+ }
+ } //end - base is available
+
+ // move to next child
+ // restriction ->[simpleType]->[facets] OR
+ // restriction ->[facets]
+ if (baseTypeQNameProperty == "") { //we already got the first kid of union/list/restriction
+ content = XUtil.getNextSiblingElement( content );
+ }
+ else { //we need to look at first kid of union/list/restriction
+ content = XUtil.getFirstChildElement(content);
+ }
+
+ //get more types for union if any
+ if (union) {
+ int index=size;
+ while (content!=null) {
+ if (DEBUG_UNION) {
+ System.out.println("[start Union types traversal] + " + content.getNodeName());
+ System.out.println(index+"-Getting all other simpletypes");
+ System.out.println("content: " + content.getNodeName());
+ }
+ typeNameIndex = traverseSimpleTypeDecl(content);
+ if (typeNameIndex!=-1) {
+ baseValidator=fDatatypeRegistry.getDatatypeValidator(fStringPool.toString(typeNameIndex));
+ if (baseValidator != null) {
+ if (DEBUG_UNION) {
+ System.out.println("validator to add: " + baseValidator.toString());
+ }
+ dTValidators.addElement((DatatypeValidator)baseValidator);
+ }
+ }
+ if ( baseValidator == null || typeNameIndex == -1) {
+ reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
+ new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ),
+ simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)});
+ return (-1);
+ }
+ content = XUtil.getNextSiblingElement( content );
+ }
+ } // end - traverse Union
+
+
+ Hashtable facetData =null;
+ int numFacets=0;
+
+ if (restriction && content != null) {
+
+ int numEnumerationLiterals = 0;
+ facetData = new Hashtable();
+ Vector enumData = new Vector();
+ while (content != null) {
+ if (content.getNodeType() == Node.ELEMENT_NODE) {
+ numFacets++;
+ if (content.getNodeName().equals(SchemaSymbols.ELT_ENUMERATION)) {
+ numEnumerationLiterals++;
+ String enumVal = content.getAttribute(SchemaSymbols.ATT_VALUE);
+ enumData.addElement(enumVal);
+ //Enumerations can have annotations ? ( 0 | 1 )
+ checkContent(simpleTypeDecl, XUtil.getFirstChildElement( content ), true);
+ }
+ else {
+ facetData.put(content.getNodeName(),content.getAttribute( SchemaSymbols.ATT_VALUE ));
+ }
+ }
+ content = XUtil.getNextSiblingElement(content);
+ }
+ if (numEnumerationLiterals > 0) {
+ facetData.put(SchemaSymbols.ELT_ENUMERATION, enumData);
+ }
+ }
+
+
+ else if (list && content!=null) { // report error - must not have any children!
+ reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
+ new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
+ //REVISIT: should we return?
+
+ }
+ else if (union && content!=null) { //report error - must not have any children!
+ reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
+ new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
+ //REVISIT: should we return?
+ }
+
+ // create & register validator for "generated" type if it doesn't exist
+ String nameOfType = fStringPool.toString( newSimpleTypeName);
+ if (fTargetNSURIString.length () != 0) {
+ nameOfType = fTargetNSURIString+","+nameOfType;
+ }
+ try {
+ DatatypeValidator newValidator =
+ fDatatypeRegistry.getDatatypeValidator( nameOfType );
+
+ if( newValidator == null ) { // not previously registered
+ if (list) {
+ fDatatypeRegistry.createDatatypeValidator( nameOfType, baseValidator,
+ facetData,true);
+ }
+ else if (restriction) {
+ fDatatypeRegistry.createDatatypeValidator( nameOfType, baseValidator,
+ facetData,false);
+ }
+ else { //union
+ fDatatypeRegistry.createDatatypeValidator( nameOfType, dTValidators);
+ }
+
+ }
+
+ } catch (Exception e) {
+ reportSchemaError(SchemaMessageProvider.DatatypeError,new Object [] { e.getMessage() });
+ }
+ return fStringPool.addSymbol(nameOfType);
+ }
+
/*
* <any