// REVISIT: Localize
reportGenericSchemaError("error in content of simpleType");
}
int typeNameIndex;
DatatypeValidator baseValidator = null;
if ( baseTypeQNameProperty.length() == 0 ) {
//---------------------------
//must 'see' <simpleType>
//---------------------------
//content = {annotation?,simpleType?...}
content = XUtil.getFirstChildElement(content);
//check content (annotation?, ...)
content = checkContent(simpleTypeDecl, content, false);
if (content == null) {
return resetSimpleTypeNameStack(-1);
}
if (content.getLocalName().equals( SchemaSymbols.ELT_SIMPLETYPE )) {
typeNameIndex = traverseSimpleTypeDecl(content);
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 resetSimpleTypeNameStack(-1);
}
}
else {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
return resetSimpleTypeNameStack(-1);
}
} //end - must see simpleType?
else {
//-----------------------------
//base was provided - get proper validator.
//-----------------------------
numOfTypes = 1;
if (union) {
numOfTypes= size;
}
//--------------------------------------------------------------------
// this loop is also where we need to find out whether the type being used as
// a base (or itemType or whatever) allows such things.
//--------------------------------------------------------------------
int baseRefContext = (restriction? SchemaSymbols.RESTRICTION:0);
baseRefContext = baseRefContext | (union? SchemaSymbols.UNION:0);
baseRefContext = baseRefContext | (list ? SchemaSymbols.LIST:0);
for (int i=0; i<numOfTypes; i++) { //find all validators
if (union) {
baseTypeQNameProperty = unionMembers.nextToken();
}
baseValidator = findDTValidator ( simpleTypeDecl, baseTypeQNameProperty, baseRefContext);
if ( baseValidator == null) {
return resetSimpleTypeNameStack(-1);
}
// ------------------------------
// (variety is list)cos-list-of-atomic
// ------------------------------
if (fListName.length() != 0 ) {
if (baseValidator instanceof ListDatatypeValidator) {
reportCosListOfAtomic();
return resetSimpleTypeNameStack(-1);
}
//-----------------------------------------------------
// if baseValidator is of type (union) need to look
// at Union validators to make sure that List is not one of them
//-----------------------------------------------------
if (isListDatatype(baseValidator)) {
reportCosListOfAtomic();
return resetSimpleTypeNameStack(-1);
}
}
if (union) {
dTValidators.addElement((DatatypeValidator)baseValidator); //add validator to structure
}
}
} //end - base is available
// ------------------------------------------
// move to next child
// <base==empty)->[simpleType]->[facets] OR
// <base!=empty)->[facets]
// ------------------------------------------
if (baseTypeQNameProperty.length() == 0) {
content = XUtil.getNextSiblingElement( content );
}
else {
content = XUtil.getFirstChildElement(content);
}
// ------------------------------------------
//get more types for union if any
// ------------------------------------------
if (union) {
int index=size;
if (baseTypeQNameProperty.length() != 0 ) {
content = checkContent(simpleTypeDecl, content, true);
}
while (content!=null) {
typeNameIndex = traverseSimpleTypeDecl(content);
if (typeNameIndex!=-1) {
baseValidator=fDatatypeRegistry.getDatatypeValidator(fStringPool.toString(typeNameIndex));
if (baseValidator != null) {
if (fListName.length() != 0 && baseValidator instanceof ListDatatypeValidator) {
reportCosListOfAtomic();
return resetSimpleTypeNameStack(-1);
}
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
if (fListName.length() != 0) {
// reset fListName, meaning that we are done with
// traversing <list> and its itemType resolves to atomic value
if (fListName.equals(qualifiedName)) {
fListName = "";
}
}
int numFacets=0;
fFacetData.clear();
if (restriction && content != null) {
short flags = 0; // flag facets that have fixed="true"
int numEnumerationLiterals = 0;
Vector enumData = new Vector();
content = checkContent(simpleTypeDecl, content , true);
StringBuffer pattern = null;
String facet;
while (content != null) {
if (content.getNodeType() == Node.ELEMENT_NODE) {
// General Attribute Checking
contentAttrs = generalCheck(content, scope);
numFacets++;
facet =content.getLocalName();
if (facet.equals(SchemaSymbols.ELT_ENUMERATION)) {
numEnumerationLiterals++;
String enumVal = content.getAttribute(SchemaSymbols.ATT_VALUE);
String localName;
if (baseValidator instanceof NOTATIONDatatypeValidator) {
String prefix = "";
String localpart = enumVal;
int colonptr = enumVal.indexOf(":");
if ( colonptr > 0) {
prefix = enumVal.substring(0,colonptr);
localpart = enumVal.substring(colonptr+1);
}
String uriStr = (prefix.length() != 0)?resolvePrefixToURI(prefix):fTargetNSURIString;
nameProperty=uriStr + ":" + localpart;
localName = (String)fNotationRegistry.get(nameProperty);
if(localName == null){
localName = traverseNotationFromAnotherSchema( localpart, uriStr);
if (localName == null) {
reportGenericSchemaError("Notation '" + localpart +
"' not found in the grammar "+ uriStr);
}
}
enumVal=nameProperty;
}
enumData.addElement(enumVal);
checkContent(simpleTypeDecl, XUtil.getFirstChildElement( content ), true);
}
else if (facet.equals(SchemaSymbols.ELT_ANNOTATION) || facet.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
}
else if (facet.equals(SchemaSymbols.ELT_PATTERN)) {
if (pattern == null) {
pattern = new StringBuffer (content.getAttribute( SchemaSymbols.ATT_VALUE ));
}
else {
// ---------------------------------------------
//datatypes: 5.2.4 pattern: src-multiple-pattern
// ---------------------------------------------
pattern.append("|");
pattern.append(content.getAttribute( SchemaSymbols.ATT_VALUE ));
checkContent(simpleTypeDecl, XUtil.getFirstChildElement( content ), true);
}
}
else {
if ( fFacetData.containsKey(facet) )
reportSchemaError(SchemaMessageProvider.DatatypeError,
new Object [] {"The facet '" + facet + "' is defined more than once."} );
fFacetData.put(facet,content.getAttribute( SchemaSymbols.ATT_VALUE ));
if (content.getAttribute( SchemaSymbols.ATT_FIXED).equals(SchemaSymbols.ATTVAL_TRUE) ||
content.getAttribute( SchemaSymbols.ATT_FIXED).equals(SchemaSymbols.ATTVAL_TRUE_1)){
// --------------------------------------------
// set fixed facet flags
// length - must remain const through derivation
// thus we don't care if it fixed
// --------------------------------------------
if ( facet.equals(SchemaSymbols.ELT_MINLENGTH) ) {
flags |= DatatypeValidator.FACET_MINLENGTH;
}
else if (facet.equals(SchemaSymbols.ELT_MAXLENGTH)) {
flags |= DatatypeValidator.FACET_MAXLENGTH;
}
else if (facet.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
flags |= DatatypeValidator.FACET_MAXEXCLUSIVE;
}
else if (facet.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
flags |= DatatypeValidator.FACET_MAXINCLUSIVE;
}
else if (facet.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
flags |= DatatypeValidator.FACET_MINEXCLUSIVE;
}
else if (facet.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
flags |= DatatypeValidator.FACET_MININCLUSIVE;
}
else if (facet.equals(SchemaSymbols.ELT_TOTALDIGITS)) {
flags |= DatatypeValidator.FACET_TOTALDIGITS;
}
else if (facet.equals(SchemaSymbols.ELT_FRACTIONDIGITS)) {
flags |= DatatypeValidator.FACET_FRACTIONDIGITS;
}
else if (facet.equals(SchemaSymbols.ELT_WHITESPACE) &&
baseValidator instanceof StringDatatypeValidator) {
flags |= DatatypeValidator.FACET_WHITESPACE;
}
}
checkContent(simpleTypeDecl, XUtil.getFirstChildElement( content ), true);
}
}
content = XUtil.getNextSiblingElement(content);
}
if (numEnumerationLiterals > 0) {
fFacetData.put(SchemaSymbols.ELT_ENUMERATION, enumData);
}
if (pattern !=null) {
fFacetData.put(SchemaSymbols.ELT_PATTERN, pattern.toString());
}
if (flags != 0) {
fFacetData.put(DatatypeValidator.FACET_FIXED, new Short(flags));
}
}
else if (list && content!=null) {
// report error - must not have any children!
if (baseTypeQNameProperty.length() != 0) {
content = checkContent(simpleTypeDecl, content, true);
if (content!=null) {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
}
}
else {
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!
if (baseTypeQNameProperty.length() != 0) {
content = checkContent(simpleTypeDecl, content, true);
if (content!=null) {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
}
}
else {
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
// ----------------------------------------------------------------------
try {
DatatypeValidator newValidator =
fDatatypeRegistry.getDatatypeValidator( qualifiedName );
if( newValidator == null ) { // not previously registered
if (list) {
fDatatypeRegistry.createDatatypeValidator( qualifiedName, baseValidator,