286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001-2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.xs.traversers;
286N/A
286N/Aimport java.util.Locale;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSConstraints;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.util.XInt;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;
286N/Aimport com.sun.org.apache.xerces.internal.util.DOMUtil;
286N/Aimport com.sun.org.apache.xerces.internal.util.SymbolTable;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLChar;
286N/Aimport com.sun.org.apache.xerces.internal.xni.QName;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSConstants;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSObject;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSObjectList;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
286N/Aimport org.w3c.dom.Attr;
286N/Aimport org.w3c.dom.Element;
286N/A
286N/A/**
286N/A * The element declaration schema component traverser.
286N/A * <element
286N/A * abstract = boolean : false
286N/A * block = (#all | List of (extension | restriction | substitution))
286N/A * default = string
286N/A * final = (#all | List of (extension | restriction))
286N/A * fixed = string
286N/A * form = (qualified | unqualified)
286N/A * id = ID
286N/A * maxOccurs = (nonNegativeInteger | unbounded) : 1
286N/A * minOccurs = nonNegativeInteger : 1
286N/A * name = NCName
286N/A * nillable = boolean : false
286N/A * ref = QName
286N/A * substitutionGroup = QName
286N/A * type = QName
286N/A * {any attributes with non-schema namespace . . .}>
286N/A * Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
286N/A * </element>
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Sandy Gao, IBM
286N/A *
286N/A * @version $Id: XSDElementTraverser.java,v 1.9 2010-11-01 04:40:02 joehw Exp $
286N/A */
286N/Aclass XSDElementTraverser extends XSDAbstractTraverser {
286N/A
286N/A protected final XSElementDecl fTempElementDecl = new XSElementDecl();
286N/A
286N/A // this controls what happens when a local element is encountered.
286N/A // We may not encounter all local elements when first parsing.
286N/A boolean fDeferTraversingLocalElements;
286N/A
286N/A XSDElementTraverser (XSDHandler handler,
286N/A XSAttributeChecker gAttrCheck) {
286N/A super(handler, gAttrCheck);
286N/A }
286N/A
286N/A /**
286N/A * Traverse a locally declared element (or an element reference).
286N/A *
286N/A * To handle the recursive cases efficiently, we delay the traversal
286N/A * and return an empty particle node. We'll fill in this particle node
286N/A * later after we've done with all the global declarations.
286N/A * This method causes a number of data structures in the schema handler to be filled in.
286N/A *
286N/A * @param elmDecl
286N/A * @param schemaDoc
286N/A * @param grammar
286N/A * @return the particle
286N/A */
286N/A XSParticleDecl traverseLocal(Element elmDecl,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar,
286N/A int allContextFlags,
286N/A XSObject parent) {
286N/A
286N/A XSParticleDecl particle = null;
286N/A if (fSchemaHandler.fDeclPool !=null) {
286N/A particle = fSchemaHandler.fDeclPool.getParticleDecl();
286N/A } else {
286N/A particle = new XSParticleDecl();
286N/A }
286N/A if (fDeferTraversingLocalElements) {
286N/A // The only thing we care about now is whether this element has
286N/A // minOccurs=0. This affects (if the element appears in a complex
286N/A // type) whether a type has emptiable content.
286N/A particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
286N/A Attr attr = elmDecl.getAttributeNode(SchemaSymbols.ATT_MINOCCURS);
286N/A if (attr != null) {
286N/A String min = attr.getValue();
286N/A try {
286N/A int m = Integer.parseInt(XMLChar.trim(min));
286N/A if (m >= 0)
286N/A particle.fMinOccurs = m;
286N/A }
286N/A catch (NumberFormatException ex) {
286N/A }
286N/A }
286N/A fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, parent, particle);
286N/A } else {
286N/A traverseLocal(particle, elmDecl, schemaDoc, grammar, allContextFlags, parent, null);
286N/A // If it's an empty particle, return null.
286N/A if (particle.fType == XSParticleDecl.PARTICLE_EMPTY)
286N/A particle = null;
286N/A }
286N/A
286N/A return particle;
286N/A }
286N/A
286N/A /**
286N/A * Traverse a locally declared element (or an element reference).
286N/A *
286N/A * This is the real traversal method. It's called after we've done with
286N/A * all the global declarations.
286N/A *
286N/A * @param index
286N/A */
286N/A protected void traverseLocal(XSParticleDecl particle,
286N/A Element elmDecl,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar,
286N/A int allContextFlags,
286N/A XSObject parent,
286N/A String[] localNSDecls) {
286N/A
286N/A if (localNSDecls != null) {
286N/A schemaDoc.fNamespaceSupport.setEffectiveContext(localNSDecls);
286N/A }
286N/A
286N/A // General Attribute Checking
286N/A Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, false, schemaDoc);
286N/A
286N/A QName refAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];
286N/A XInt minAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_MINOCCURS];
286N/A XInt maxAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS];
286N/A
286N/A XSElementDecl element = null;
286N/A XSAnnotationImpl annotation = null;
286N/A if (elmDecl.getAttributeNode(SchemaSymbols.ATT_REF) != null) {
286N/A if (refAtt != null) {
286N/A element = (XSElementDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ELEMENT_TYPE, refAtt, elmDecl);
286N/A
286N/A Element child = DOMUtil.getFirstChildElement(elmDecl);
286N/A if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
286N/A annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A }
286N/A else {
286N/A String text = DOMUtil.getSyntheticAnnotation(elmDecl);
286N/A if (text != null) {
286N/A annotation = traverseSyntheticAnnotation(elmDecl, text, attrValues, false, schemaDoc);
286N/A }
286N/A }
286N/A // Element Declaration Representation OK
286N/A // 2 If the item's parent is not <schema>, then all of the following must be true:
286N/A // 2.1 One of ref or name must be present, but not both.
286N/A // 2.2 If ref is present, then all of <complexType>, <simpleType>, <key>, <keyref>, <unique>, nillable, default, fixed, form, block and type must be absent, i.e. only minOccurs, maxOccurs, id are allowed in addition to ref, along with <annotation>.
286N/A if (child != null) {
286N/A reportSchemaError("src-element.2.2", new Object[]{refAtt.rawname, DOMUtil.getLocalName(child)}, child);
286N/A }
286N/A } else {
286N/A element = null;
286N/A }
286N/A } else {
286N/A element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, false, parent);
286N/A }
286N/A
286N/A particle.fMinOccurs = minAtt.intValue();
286N/A particle.fMaxOccurs = maxAtt.intValue();
286N/A if (element != null) {
286N/A particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
286N/A particle.fValue = element;
286N/A }
286N/A else {
286N/A particle.fType = XSParticleDecl.PARTICLE_EMPTY;
286N/A }
286N/A if (refAtt != null) {
286N/A XSObjectList annotations;
286N/A if (annotation != null) {
286N/A annotations = new XSObjectListImpl();
286N/A ((XSObjectListImpl) annotations).addXSObject(annotation);
286N/A } else {
286N/A annotations = XSObjectListImpl.EMPTY_LIST;
286N/A }
286N/A particle.fAnnotations = annotations;
286N/A } else {
286N/A particle.fAnnotations = ((element != null) ? element.fAnnotations
286N/A : XSObjectListImpl.EMPTY_LIST);
286N/A }
286N/A Long defaultVals = (Long)attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT];
286N/A checkOccurrences(particle, SchemaSymbols.ELT_ELEMENT,
286N/A (Element)elmDecl.getParentNode(), allContextFlags,
286N/A defaultVals.longValue());
286N/A
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A }
286N/A
286N/A /**
286N/A * Traverse a globally declared element.
286N/A *
286N/A * @param elmDecl
286N/A * @param schemaDoc
286N/A * @param grammar
286N/A * @return the element declaration
286N/A */
286N/A XSElementDecl traverseGlobal(Element elmDecl,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar) {
286N/A
286N/A // General Attribute Checking'
286N/A
286N/A Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, true, schemaDoc);
286N/A XSElementDecl element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, true, null);
286N/A fAttrChecker.returnAttrArray(attrValues, schemaDoc);
286N/A return element;
286N/A
286N/A }
286N/A
286N/A /**
286N/A * Traverse a globally declared element.
286N/A *
286N/A * @param elmDecl
286N/A * @param attrValues
286N/A * @param schemaDoc
286N/A * @param grammar
286N/A * @param isGlobal
286N/A * @return the element declaration
286N/A */
286N/A XSElementDecl traverseNamedElement(Element elmDecl,
286N/A Object[] attrValues,
286N/A XSDocumentInfo schemaDoc,
286N/A SchemaGrammar grammar,
286N/A boolean isGlobal,
286N/A XSObject parent) {
286N/A
286N/A Boolean abstractAtt = (Boolean) attrValues[XSAttributeChecker.ATTIDX_ABSTRACT];
286N/A XInt blockAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_BLOCK];
286N/A String defaultAtt = (String) attrValues[XSAttributeChecker.ATTIDX_DEFAULT];
286N/A XInt finalAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_FINAL];
286N/A String fixedAtt = (String) attrValues[XSAttributeChecker.ATTIDX_FIXED];
286N/A XInt formAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_FORM];
286N/A String nameAtt = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
286N/A Boolean nillableAtt = (Boolean) attrValues[XSAttributeChecker.ATTIDX_NILLABLE];
286N/A QName subGroupAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_SUBSGROUP];
286N/A QName typeAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_TYPE];
286N/A
286N/A // Step 1: get declaration information
286N/A
286N/A XSElementDecl element = null;
286N/A if (fSchemaHandler.fDeclPool !=null) {
286N/A element = fSchemaHandler.fDeclPool.getElementDecl();
286N/A } else {
286N/A element = new XSElementDecl();
286N/A }
286N/A // get 'name'
286N/A if (nameAtt != null)
286N/A element.fName = fSymbolTable.addSymbol(nameAtt);
286N/A
286N/A // get 'target namespace'
286N/A if (isGlobal) {
286N/A element.fTargetNamespace = schemaDoc.fTargetNamespace;
286N/A element.setIsGlobal();
286N/A }
286N/A else {
286N/A if (parent instanceof XSComplexTypeDecl)
286N/A element.setIsLocal((XSComplexTypeDecl)parent);
286N/A
286N/A if (formAtt != null) {
286N/A if (formAtt.intValue() == SchemaSymbols.FORM_QUALIFIED)
286N/A element.fTargetNamespace = schemaDoc.fTargetNamespace;
286N/A else
286N/A element.fTargetNamespace = null;
286N/A } else if (schemaDoc.fAreLocalElementsQualified) {
286N/A element.fTargetNamespace = schemaDoc.fTargetNamespace;
286N/A } else {
286N/A element.fTargetNamespace = null;
286N/A }
286N/A }
286N/A
286N/A // get 'block', 'final', 'nillable', 'abstract'
286N/A if (blockAtt == null) {
286N/A // use defaults
286N/A element.fBlock = schemaDoc.fBlockDefault;
286N/A // discard valid Block 'Default' values that are invalid for Block
286N/A // respect #all
286N/A if (element.fBlock != XSConstants.DERIVATION_ALL) {
286N/A element.fBlock &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION);
286N/A }
286N/A } else {
286N/A // use specified values
286N/A element.fBlock = blockAtt.shortValue();
286N/A // check for valid values
286N/A if ((element.fBlock != XSConstants.DERIVATION_ALL)
286N/A &&
286N/A ((element.fBlock | XSConstants.DERIVATION_EXTENSION_RESTRICTION_SUBSTITION)
286N/A != XSConstants.DERIVATION_EXTENSION_RESTRICTION_SUBSTITION)) {
286N/A reportSchemaError(
286N/A "s4s-att-invalid-value",
286N/A new Object[]{element.fName, "block", "must be (#all | List of (extension | restriction | substitution))"},
286N/A elmDecl);
286N/A }
286N/A }
286N/A
286N/A element.fFinal = finalAtt == null ? schemaDoc.fFinalDefault : finalAtt.shortValue();
286N/A // discard valid Final 'Default' values that are invalid for Final
286N/A element.fFinal &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION);
286N/A
286N/A if (nillableAtt.booleanValue())
286N/A element.setIsNillable();
286N/A if (abstractAtt != null && abstractAtt.booleanValue())
286N/A element.setIsAbstract();
286N/A
286N/A // get 'value constraint'
286N/A if (fixedAtt != null) {
286N/A element.fDefault = new ValidatedInfo();
286N/A element.fDefault.normalizedValue = fixedAtt;
286N/A element.setConstraintType(XSConstants.VC_FIXED);
286N/A } else if (defaultAtt != null) {
286N/A element.fDefault = new ValidatedInfo();
286N/A element.fDefault.normalizedValue = defaultAtt;
286N/A element.setConstraintType(XSConstants.VC_DEFAULT);
286N/A } else {
286N/A element.setConstraintType(XSConstants.VC_NONE);
286N/A }
286N/A
286N/A // get 'substitutionGroup affiliation'
286N/A if (subGroupAtt != null) {
286N/A element.fSubGroup = (XSElementDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ELEMENT_TYPE, subGroupAtt, elmDecl);
286N/A }
286N/A
286N/A // get 'annotation'
286N/A Element child = DOMUtil.getFirstChildElement(elmDecl);
286N/A XSAnnotationImpl annotation = null;
286N/A if(child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
286N/A annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A }
286N/A else {
286N/A String text = DOMUtil.getSyntheticAnnotation(elmDecl);
286N/A if (text != null) {
286N/A annotation = traverseSyntheticAnnotation(elmDecl, text, attrValues, false, schemaDoc);
286N/A }
286N/A }
286N/A
286N/A XSObjectList annotations;
286N/A if (annotation != null) {
286N/A annotations = new XSObjectListImpl();
286N/A ((XSObjectListImpl)annotations).addXSObject (annotation);
286N/A } else {
286N/A annotations = XSObjectListImpl.EMPTY_LIST;
286N/A }
286N/A element.fAnnotations = annotations;
286N/A
286N/A // get 'type definition'
286N/A XSTypeDefinition elementType = null;
286N/A boolean haveAnonType = false;
286N/A
286N/A // Handle Anonymous type if there is one
286N/A if (child != null) {
286N/A String childName = DOMUtil.getLocalName(child);
286N/A
286N/A if (childName.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {
286N/A elementType = fSchemaHandler.fComplexTypeTraverser.traverseLocal(child, schemaDoc, grammar);
286N/A haveAnonType = true;
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A }
286N/A else if (childName.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
286N/A elementType = fSchemaHandler.fSimpleTypeTraverser.traverseLocal(child, schemaDoc, grammar);
286N/A haveAnonType = true;
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A }
286N/A }
286N/A
286N/A // Handler type attribute
286N/A if (elementType == null && typeAtt != null) {
286N/A elementType = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.TYPEDECL_TYPE, typeAtt, elmDecl);
286N/A if (elementType == null) {
286N/A element.fUnresolvedTypeName = typeAtt;
286N/A }
286N/A }
286N/A
286N/A // Get it from the substitutionGroup declaration
286N/A if (elementType == null && element.fSubGroup != null) {
286N/A elementType = element.fSubGroup.fType;
286N/A }
286N/A
286N/A if (elementType == null) {
286N/A elementType = SchemaGrammar.fAnyType;
286N/A }
286N/A
286N/A element.fType = elementType;
286N/A
286N/A // get 'identity constraint'
286N/A
286N/A // see if there's something here; it had better be key, keyref or unique.
286N/A if (child != null) {
286N/A String childName = DOMUtil.getLocalName(child);
286N/A while (child != null &&
286N/A (childName.equals(SchemaSymbols.ELT_KEY) ||
286N/A childName.equals(SchemaSymbols.ELT_KEYREF) ||
286N/A childName.equals(SchemaSymbols.ELT_UNIQUE))) {
286N/A
286N/A if (childName.equals(SchemaSymbols.ELT_KEY) ||
286N/A childName.equals(SchemaSymbols.ELT_UNIQUE)) {
286N/A // need to set <key>/<unique> to hidden before traversing it,
286N/A // because it has global scope
286N/A DOMUtil.setHidden(child, fSchemaHandler.fHiddenNodes);
286N/A fSchemaHandler.fUniqueOrKeyTraverser.traverse(child, element, schemaDoc, grammar);
286N/A if(DOMUtil.getAttrValue(child, SchemaSymbols.ATT_NAME).length() != 0 ) {
286N/A fSchemaHandler.checkForDuplicateNames(
286N/A (schemaDoc.fTargetNamespace == null) ? ","+DOMUtil.getAttrValue(child, SchemaSymbols.ATT_NAME)
286N/A : schemaDoc.fTargetNamespace+","+ DOMUtil.getAttrValue(child, SchemaSymbols.ATT_NAME),
286N/A fSchemaHandler.ATTRIBUTE_TYPE, fSchemaHandler.getIDRegistry(), fSchemaHandler.getIDRegistry_sub(),
286N/A child, schemaDoc);
286N/A }
286N/A } else if (childName.equals(SchemaSymbols.ELT_KEYREF)) {
286N/A fSchemaHandler.storeKeyRef(child, schemaDoc, element);
286N/A }
286N/A child = DOMUtil.getNextSiblingElement(child);
286N/A if (child != null) {
286N/A childName = DOMUtil.getLocalName(child);
286N/A }
286N/A }
286N/A }
286N/A
286N/A // Step 3: check against schema for schemas
286N/A
286N/A // required attributes
286N/A if (nameAtt == null) {
286N/A if (isGlobal)
286N/A reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_ELEMENT, SchemaSymbols.ATT_NAME}, elmDecl);
286N/A else
286N/A reportSchemaError("src-element.2.1", null, elmDecl);
286N/A nameAtt = NO_NAME;
286N/A }
286N/A
286N/A // element
286N/A if (child != null) {
286N/A reportSchemaError("s4s-elt-must-match.1", new Object[]{nameAtt, "(annotation?, (simpleType | complexType)?, (unique | key | keyref)*))", DOMUtil.getLocalName(child)}, child);
286N/A }
286N/A
286N/A // Step 4: check 3.3.3 constraints
286N/A
286N/A // src-element
286N/A
286N/A // 1 default and fixed must not both be present.
286N/A if (defaultAtt != null && fixedAtt != null) {
286N/A reportSchemaError("src-element.1", new Object[]{nameAtt}, elmDecl);
286N/A }
286N/A
286N/A // 2 If the item's parent is not <schema>, then all of the following must be true:
286N/A // 2.1 One of ref or name must be present, but not both.
286N/A // This is checked in XSAttributeChecker
286N/A
286N/A // 2.2 If ref is present, then all of <complexType>, <simpleType>, <key>, <keyref>, <unique>, nillable, default, fixed, form, block and type must be absent, i.e. only minOccurs, maxOccurs, id are allowed in addition to ref, along with <annotation>.
286N/A // Attributes are checked in XSAttributeChecker, elements are checked in "traverse" method
286N/A
286N/A // 3 type and either <simpleType> or <complexType> are mutually exclusive.
286N/A if (haveAnonType && (typeAtt != null)) {
286N/A reportSchemaError("src-element.3", new Object[]{nameAtt}, elmDecl);
286N/A }
286N/A
286N/A // Step 5: check 3.3.6 constraints
286N/A // check for NOTATION type
286N/A checkNotationType(nameAtt, elementType, elmDecl);
286N/A
286N/A // e-props-correct
286N/A
286N/A // 2 If there is a {value constraint}, the canonical lexical representation of its value must be valid with respect to the {type definition} as defined in Element Default Valid (Immediate) (3.3.6).
286N/A if (element.fDefault != null) {
286N/A fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
286N/A if (XSConstraints.ElementDefaultValidImmediate(element.fType, element.fDefault.normalizedValue, fValidationState, element.fDefault) == null) {
286N/A reportSchemaError ("e-props-correct.2", new Object[]{nameAtt, element.fDefault.normalizedValue}, elmDecl);
286N/A element.fDefault = null;
286N/A element.setConstraintType(XSConstants.VC_NONE);
286N/A }
286N/A }
286N/A
286N/A // 4 If there is an {substitution group affiliation}, the {type definition} of the element declaration must be validly derived from the {type definition} of the {substitution group affiliation}, given the value of the {substitution group exclusions} of the {substitution group affiliation}, as defined in Type Derivation OK (Complex) (3.4.6) (if the {type definition} is complex) or as defined in Type Derivation OK (Simple) (3.14.6) (if the {type definition} is simple).
286N/A if (element.fSubGroup != null) {
286N/A if (!XSConstraints.checkTypeDerivationOk(element.fType, element.fSubGroup.fType, element.fSubGroup.fFinal)) {
286N/A reportSchemaError ("e-props-correct.4", new Object[]{nameAtt, subGroupAtt.prefix+":"+subGroupAtt.localpart}, elmDecl);
286N/A element.fSubGroup = null;
286N/A }
286N/A }
286N/A
286N/A // 5 If the {type definition} or {type definition}'s {content type} is or is derived from ID then there must not be a {value constraint}.
286N/A if (element.fDefault != null) {
286N/A if ((elementType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE &&
286N/A ((XSSimpleType)elementType).isIDType()) ||
286N/A (elementType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE &&
286N/A ((XSComplexTypeDecl)elementType).containsTypeID())) {
286N/A reportSchemaError ("e-props-correct.5", new Object[]{element.fName}, elmDecl);
286N/A element.fDefault = null;
286N/A element.setConstraintType(XSConstants.VC_NONE);
286N/A }
286N/A }
286N/A
286N/A // Element without a name. Return null.
286N/A if (element.fName == null)
286N/A return null;
286N/A
286N/A // Step 5: register the element decl to the grammar
286N/A if (isGlobal) {
286N/A grammar.addGlobalElementDeclAll(element);
286N/A
286N/A if (grammar.getGlobalElementDecl(element.fName) == null) {
286N/A grammar.addGlobalElementDecl(element);
286N/A }
286N/A
286N/A // we also add the element to the tolerate duplicates list as well
286N/A final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
286N/A final XSElementDecl element2 = grammar.getGlobalElementDecl(element.fName, loc);
286N/A if (element2 == null) {
286N/A grammar.addGlobalElementDecl(element, loc);
286N/A }
286N/A
286N/A // if we are tolerating duplicates, and we found a duplicate declaration
286N/A // use the duplicate one instead
286N/A if (fSchemaHandler.fTolerateDuplicates) {
286N/A if (element2 != null) {
286N/A element = element2;
286N/A }
286N/A fSchemaHandler.addGlobalElementDecl(element);
286N/A }
286N/A }
286N/A
286N/A return element;
286N/A }
286N/A
286N/A void reset(SymbolTable symbolTable, boolean validateAnnotations, Locale locale) {
286N/A super.reset(symbolTable, validateAnnotations, locale);
286N/A fDeferTraversingLocalElements = true;
286N/A } // reset()
286N/A
286N/A}