throw new ComplexTypeRecoverableError();
}
fBaseType = type;
XSSimpleType baseValidator = null;
XSComplexTypeDecl baseComplexType = null;
int baseFinalSet = 0;
// If the base type is complex, it must have simpleContent
if ((type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)) {
baseComplexType = (XSComplexTypeDecl)type;
baseFinalSet = baseComplexType.getFinal();
// base is a CT with simple content (both restriction and extension are OK)
if (baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) {
baseValidator = (XSSimpleType)baseComplexType.getSimpleType();
}
// base is a CT with mixed/emptiable content (only restriction is OK)
else if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION &&
baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_MIXED &&
((XSParticleDecl)baseComplexType.getParticle()).emptiable()) {
}
else {
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
throw new ComplexTypeRecoverableError("src-ct.2.1",
new Object[]{fName, baseComplexType.getName()}, simpleContent);
}
}
else {
baseValidator = (XSSimpleType)type;
// base is a ST (only extension is OK)
if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) {
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
throw new ComplexTypeRecoverableError("src-ct.2.1",
new Object[]{fName, baseValidator.getName()}, simpleContent);
}
baseFinalSet=baseValidator.getFinal();
}
// -----------------------------------------------------------------------
// Check that the base permits the derivation
// -----------------------------------------------------------------------
if ((baseFinalSet & fDerivedBy)!=0) {
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ?
"cos-ct-extends.1.1" : "derivation-ok-restriction.1";
throw new ComplexTypeRecoverableError(errorKey,
new Object[]{fName, fBaseType.getName()}, simpleContent);
}
// -----------------------------------------------------------------------
// Skip over any potential annotations
// -----------------------------------------------------------------------
Element scElement = simpleContent;
simpleContent = DOMUtil.getFirstChildElement(simpleContent);
if (simpleContent != null) {
// traverse annotation if any
if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
addAnnotation(traverseAnnotationDecl(simpleContent, derivationTypeAttrValues, false, schemaDoc));
simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
}
else {
String text = DOMUtil.getSyntheticAnnotation(scElement);
if (text != null) {
addAnnotation(traverseSyntheticAnnotation(scElement, text, derivationTypeAttrValues, false, schemaDoc));
}
}
if (simpleContent !=null &&
DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)){
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
simpleContent);
}
}
else {
String text = DOMUtil.getSyntheticAnnotation(scElement);
if (text != null) {
addAnnotation(traverseSyntheticAnnotation(scElement, text, derivationTypeAttrValues, false, schemaDoc));
}
}
// -----------------------------------------------------------------------
// Process a RESTRICTION
// -----------------------------------------------------------------------
if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) {
// -----------------------------------------------------------------------
// There may be a simple type definition in the restriction element
// The data type validator will be based on it, if specified
// -----------------------------------------------------------------------
if (simpleContent !=null &&
DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_SIMPLETYPE )) {
XSSimpleType dv = fSchemaHandler.fSimpleTypeTraverser.traverseLocal(
simpleContent, schemaDoc, grammar);
if (dv == null) {
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
throw new ComplexTypeRecoverableError();
}
//check that this datatype validator is validly derived from the base
//according to derivation-ok-restriction 5.1.2.1
if (baseValidator != null &&
!XSConstraints.checkSimpleDerivationOk(dv, baseValidator,
baseValidator.getFinal())) {
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.2.2.1",
new Object[]{fName, dv.getName(), baseValidator.getName()},
simpleContent);
}
baseValidator = dv;
simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
}