}
if (DOMUtil.getNextSiblingElement(content) != null) {
reportSchemaError("dt-simpleType", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, nameProperty, "(annotation?, (restriction | list | union))"});
}
XSSimpleType baseValidator = null;
if (baseTypeName == null && memberTypes == null) {
//---------------------------
//must 'see' <simpleType>
//---------------------------
//content = {annotation?,simpleType?...}
content = DOMUtil.getFirstChildElement(content);
//check content (annotation?, ...)
if (content != null) {
// traverse annotation if any
if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
traverseAnnotationDecl(content, attrValues, false, schemaDoc);
content = DOMUtil.getNextSiblingElement(content);
}
}
if (content == null) {
reportSchemaError("dt-simpleType", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, nameProperty, "(annotation?, (restriction | list | union))"});
return null;
}
if (DOMUtil.getLocalName(content).equals( SchemaSymbols.ELT_SIMPLETYPE )) {
baseValidator = traverseLocal(content, schemaDoc, grammar);
if (baseValidator != null && union) {
if (baseValidator.getVariety() == XSSimpleType.VARIETY_UNION) {
XSSimpleType[] types = ((XSUnionSimpleType)baseValidator).getMemberTypes();
for (int i = 0; i < types.length; i++)
dTValidators.addElement(types[i]);
} else {
dTValidators.addElement(baseValidator);
}
}
if (baseValidator == null) {
Object[] args = {content.getAttribute( SchemaSymbols.ATT_BASE )};
reportSchemaError("dt-unknown-basetype", args);
return (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
}
}
else {
Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
reportSchemaError("dt-simpleType",new Object[]{SchemaSymbols.ELT_SIMPLETYPE, nameProperty, "(annotation?, (restriction | list | union))"});
return (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
}
}
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.
//--------------------------------------------------------------------
short baseRefContext = restriction ? SchemaSymbols.RESTRICTION :
(union ? SchemaSymbols.UNION : SchemaSymbols.LIST);
for (int i=0; i<numOfTypes; i++) { //find all validators
if (union) {
baseTypeName = (QName)memberTypes.elementAt(i);
}
baseValidator = findDTValidator ( simpleTypeDecl, baseTypeName, baseRefContext, schemaDoc);
if (baseValidator == null) {
Object[] args = { content.getAttribute( SchemaSymbols.ATT_BASE ), nameProperty};
reportSchemaError("dt-unknown-basetype", args);
baseValidator = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
}
// ------------------------------
// (variety is list)cos-list-of-atomic
// ------------------------------
if (fListName.length() != 0) {
if (baseValidator.getVariety() == XSSimpleType.VARIETY_LIST) {
reportCosListOfAtomic(qualifiedName);
return null;
}
//-----------------------------------------------------
// 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(qualifiedName);
return null;
}
}
if (union) {
if (baseValidator.getVariety() == XSSimpleType.VARIETY_UNION) {
XSSimpleType[] types = ((XSUnionSimpleType)baseValidator).getMemberTypes();
for (int j = 0; j < types.length; j++)
dTValidators.addElement(types[j]);
} else {
dTValidators.addElement(baseValidator);
}
}
}
} //end - base is available
// ------------------------------------------
// move to next child
// <base==empty)->[simpleType]->[facets] OR
// <base!=empty)->[facets]
// ------------------------------------------
if (baseTypeName == null) {
content = DOMUtil.getNextSiblingElement( content );
}
else {
content = DOMUtil.getFirstChildElement(content);
if (content != null) {
// traverse annotation if any
if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
traverseAnnotationDecl(content, attrValues, false, schemaDoc);
content = DOMUtil.getNextSiblingElement(content);
}
}
}
// ------------------------------------------
//get more types for union if any
// ------------------------------------------
if (union) {
if (memberTypes != null) {
if (content != null) {
// traverse annotation if any
if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
traverseAnnotationDecl(content, attrValues, false, schemaDoc);
content = DOMUtil.getNextSiblingElement(content);
}
}
if (content !=null) {
if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
Object[] args = {nameProperty};
reportSchemaError("dt-union-memberType", args);
}
}
}
while (content!=null) {
baseValidator = traverseLocal(content, schemaDoc, grammar);
if (baseValidator != null) {
if (fListName.length() != 0 && baseValidator.getVariety() == XSSimpleType.VARIETY_LIST) {
reportCosListOfAtomic(qualifiedName);
return null;
}
if (baseValidator.getVariety() == XSSimpleType.VARIETY_UNION) {
XSSimpleType[] types = ((XSUnionSimpleType)baseValidator).getMemberTypes();
for (int i = 0; i < types.length; i++)
dTValidators.addElement(types[i]);
} else {
dTValidators.addElement(baseValidator);
}
}
if (baseValidator == null) {
Object[] args = { content.getAttribute( SchemaSymbols.ATT_BASE ), nameProperty};
reportSchemaError("dt-unknown-basetype", args);
baseValidator = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
}
content = DOMUtil.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 = SchemaSymbols.EMPTY_STRING;
}
}
XSFacets facetData = null;
short presentFacets = 0;
short fixedFacets = 0 ;
if (restriction && content != null) { //we are on the facets now..
FacetInfo fi = traverseFacets(content, contentAttrs,nameProperty, baseValidator, schemaDoc, grammar);
content = fi.nodeAfterFacets;
if (content != null) {
content = null;
reportSchemaError("s4s-elt-must-match", new Object[]{SchemaSymbols.ELT_RESTRICTION, "(annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))"});
}
facetData = fi.facetdata ;
presentFacets = fi.fPresentFacets;
fixedFacets = fi.fFixedFacets;
}
else if (list && content!=null) {
// report error - must not have any children!
if (baseTypeName !=null) {
// traverse annotation if any
if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
traverseAnnotationDecl(content, attrValues, false, schemaDoc);
content = DOMUtil.getNextSiblingElement(content);
}
if (content !=null) {
Object[] args = {nameProperty};
reportSchemaError("dt-list-itemType", args);
}
}
else {
reportSchemaError("s4s-elt-must-match", new Object[]{SchemaSymbols.ELT_LIST, "(annotation?, (simpleType?))"});
}
}
else if (union && content!=null) {
//report error - must not have any children!
reportSchemaError("s4s-elt-must-match", new Object[]{SchemaSymbols.ELT_UNION, "(annotation?, (simpleType?))"});
}
XSSimpleType newDecl = null;
if (list) {
newDecl = schemaFactory.createTypeList(nameProperty, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator);
}
else if (restriction) {
newDecl = schemaFactory.createTypeRestriction(nameProperty, schemaDoc.fTargetNamespace, (short)finalProperty, baseValidator);
try {
fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
newDecl.applyFacets(facetData , presentFacets , fixedFacets, fValidationState);
} catch (InvalidDatatypeFacetException ex) {
reportGenericSchemaError("facet error when creating type '" + qualifiedName + "': " + ex.getLocalizedMessage());
}
}
else { //union