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;
if (baseComplexType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_SIMPLE) {
throw new ComplexTypeRecoverableError("src-ct.2",
new Object[]{fName}, simpleContent);
}
baseFinalSet = baseComplexType.getFinal();
baseValidator = (XSSimpleType)baseComplexType.getSimpleType();
}
else {
baseValidator = (XSSimpleType)type;
if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) {
throw new ComplexTypeRecoverableError("src-ct.2",
new Object[]{fName}, simpleContent);
}
baseFinalSet=baseValidator.getFinal();
}
// -----------------------------------------------------------------------
// Check that the base permits the derivation
// -----------------------------------------------------------------------
if ((baseFinalSet & fDerivedBy)!=0) {
String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ?
"cos-ct-extends.1.1" : "derivation-ok-restriction.1";
throw new ComplexTypeRecoverableError(errorKey,
new Object[]{fName}, simpleContent);
}
// -----------------------------------------------------------------------
// Skip over any potential annotations
// -----------------------------------------------------------------------
simpleContent = DOMUtil.getFirstChildElement(simpleContent);
if (simpleContent != null) {
// traverse annotation if any
if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
traverseAnnotationDecl(simpleContent, null, false, schemaDoc);
simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
}
if (simpleContent !=null &&
DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)){
throw new ComplexTypeRecoverableError("src-ct.0.1",
new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
simpleContent);
}
}
// -----------------------------------------------------------------------
// 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)
throw new ComplexTypeRecoverableError();
//check that this datatype validator is validly derived from the base
//according to derivation-ok-restriction 5.1.2.1
if (!XSConstraints.checkSimpleDerivationOk(dv, baseValidator,
baseValidator.getFinal())) {
throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.1.2.1",
new Object[]{fName},
simpleContent);
}
baseValidator = dv;
simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
}
// -----------------------------------------------------------------------
// Traverse any facets
// -----------------------------------------------------------------------
Element attrNode = null;
XSFacets facetData = null;
short presentFacets = 0 ;
short fixedFacets = 0 ;
if (simpleContent!=null) {
FacetInfo fi = traverseFacets(simpleContent, baseValidator, schemaDoc);
attrNode = fi.nodeAfterFacets;
facetData = fi.facetdata;
presentFacets = fi.fPresentFacets;
fixedFacets = fi.fFixedFacets;
}
fXSSimpleType = schemaFactory.createTypeRestriction(null,schemaDoc.fTargetNamespace,(short)0,baseValidator);
try{
fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
fXSSimpleType.applyFacets(facetData, presentFacets, fixedFacets, fValidationState);
}catch(InvalidDatatypeFacetException ex){
reportSchemaError(ex.getKey(), ex.getArgs(), simpleContent);
}
// -----------------------------------------------------------------------
// Traverse any attributes
// -----------------------------------------------------------------------
if (attrNode != null) {
if (!isAttrOrAttrGroup(attrNode)) {
throw new ComplexTypeRecoverableError("src-ct.0.1",
new Object[]{fName,DOMUtil.getLocalName(attrNode)},
attrNode);
}
Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp,
schemaDoc,grammar,fComplexTypeDecl);
if (node!=null) {
throw new ComplexTypeRecoverableError("src-ct.0.1",
new Object[]{fName,DOMUtil.getLocalName(node)},
node);
}
}
mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, false, simpleContentElement);
// Prohibited uses must be removed after merge for RESTRICTION
fAttrGrp.removeProhibitedAttrs();
String errorCode=fAttrGrp.validRestrictionOf(baseComplexType.getAttrGrp());
if (errorCode != null) {
throw new ComplexTypeRecoverableError(errorCode,
new Object[]{fName}, attrNode);
}
}
// -----------------------------------------------------------------------
// Process a EXTENSION
// -----------------------------------------------------------------------
else {
fXSSimpleType = baseValidator;
if (simpleContent != null) {
// -----------------------------------------------------------------------
// Traverse any attributes
// -----------------------------------------------------------------------
Element attrNode = simpleContent;
if (!isAttrOrAttrGroup(attrNode)) {
throw new ComplexTypeRecoverableError("src-ct.0.1",
new Object[]{fName,DOMUtil.getLocalName(attrNode)},
attrNode);
}
Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp,
schemaDoc,grammar,fComplexTypeDecl);
if (node!=null) {
throw new ComplexTypeRecoverableError("src-ct.0.1",
new Object[]{fName,DOMUtil.getLocalName(node)},
node);
}
// Remove prohibited uses. Should be done prior to any merge.
fAttrGrp.removeProhibitedAttrs();
}
if (baseComplexType != null) {
mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, true, simpleContentElement);
}
}
}