FileDocCategorySizeDatePackage
XSDAbstractParticleTraverser.javaAPI DocJava SE 5 API16750Fri Aug 26 14:55:52 BST 2005com.sun.org.apache.xerces.internal.impl.xs.traversers

XSDAbstractParticleTraverser

public abstract class XSDAbstractParticleTraverser extends XSDAbstractTraverser
author
Elena Litani, IBM
author
Sandy Gao, IBM
version
$Id: XSDAbstractParticleTraverser.java,v 1.16 2004/02/04 18:48:15 mrglavas Exp $

Fields Summary
ParticleArray
fPArray
Constructors Summary
XSDAbstractParticleTraverser(XSDHandler handler, XSAttributeChecker gAttrCheck)

        super(handler, gAttrCheck);
    
Methods Summary
protected booleanhasAllContent(com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl particle)

        // If the content is not empty, is the top node ALL?
        if (particle != null && particle.fType == XSParticleDecl.PARTICLE_MODELGROUP) {
            return ((XSModelGroupImpl)particle.fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL;
        }

        return false;
    
com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecltraverseAll(org.w3c.dom.Element allDecl, com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDocumentInfo schemaDoc, com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar grammar, int allContextFlags, com.sun.org.apache.xerces.internal.xs.XSObject parent)
Traverse the "All" declaration Content: (annotation? , element*)


        // General Attribute Checking

        Object[] attrValues = fAttrChecker.checkAttributes(allDecl, false, schemaDoc);

        Element child = DOMUtil.getFirstChildElement(allDecl);

        XSAnnotationImpl annotation = null;
        if (child !=null) {
            // traverse Annotation
            if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
                annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
                child = DOMUtil.getNextSiblingElement(child);
            }
        }
        String childName = null;
        XSParticleDecl particle;
        fPArray.pushContext();

        for (; child != null; child = DOMUtil.getNextSiblingElement(child)) {

            particle = null;
            childName = DOMUtil.getLocalName(child);

            // Only elements are allowed in <all>
            if (childName.equals(SchemaSymbols.ELT_ELEMENT)) {
                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, PROCESSING_ALL_EL, parent);
            }
            else {
                Object[] args = {"all", "(annotation?, element*)", DOMUtil.getLocalName(child)};
                reportSchemaError("s4s-elt-must-match.1", args, child);
            }

            if (particle != null)
                fPArray.addParticle(particle);
        }

        particle = null;
        XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS];
        XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS];
        Long defaultVals = (Long)attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT];
            
        XSModelGroupImpl group = new XSModelGroupImpl();
        group.fCompositor = XSModelGroupImpl.MODELGROUP_ALL;
        group.fParticleCount = fPArray.getParticleCount();
        group.fParticles = fPArray.popContext();
        group.fAnnotation = annotation;
        particle = new XSParticleDecl();
        particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
        particle.fMinOccurs = minAtt.intValue();
        particle.fMaxOccurs = maxAtt.intValue();
        particle.fValue = group;

        particle = checkOccurrences(particle,
                                    SchemaSymbols.ELT_ALL,
                                    (Element)allDecl.getParentNode(),
                                    allContextFlags,
                                    defaultVals.longValue());
        fAttrChecker.returnAttrArray(attrValues, schemaDoc);

        return particle;
    
com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecltraverseChoice(org.w3c.dom.Element choiceDecl, com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDocumentInfo schemaDoc, com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar grammar, int allContextFlags, com.sun.org.apache.xerces.internal.xs.XSObject parent)
Traverse the Choice declaration Content: (annotation? , (element | group | choice | sequence | any)*)

param
choiceDecl
param
schemaDoc
param
grammar
return


        return traverseSeqChoice (choiceDecl, schemaDoc, grammar, allContextFlags, true, parent);
    
private com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecltraverseSeqChoice(org.w3c.dom.Element decl, com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDocumentInfo schemaDoc, com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar grammar, int allContextFlags, boolean choice, com.sun.org.apache.xerces.internal.xs.XSObject parent)
Common traversal for and

param
decl
param
schemaDoc
param
grammar
param
choice If traversing this parameter is true.
return


        // General Attribute Checking
        Object[] attrValues = fAttrChecker.checkAttributes(decl, false, schemaDoc);

        Element child = DOMUtil.getFirstChildElement(decl);
        XSAnnotationImpl annotation = null;
        if (child !=null) {
            // traverse Annotation
            if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
                annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
                child = DOMUtil.getNextSiblingElement(child);
            }
        }
        boolean hadContent = false;
        String childName = null;
        XSParticleDecl particle;
        fPArray.pushContext();

        for (;child != null;child = DOMUtil.getNextSiblingElement(child)) {

            particle = null;

            childName = DOMUtil.getLocalName(child);
            if (childName.equals(SchemaSymbols.ELT_ELEMENT)) {
                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent);
            }
            else if (childName.equals(SchemaSymbols.ELT_GROUP)) {
                particle = fSchemaHandler.fGroupTraverser.traverseLocal(child, schemaDoc, grammar);

                // A content type of all can only appear
                // as the content type of a complex type definition.
                if (hasAllContent(particle)) {
                    // don't insert the "all" particle, otherwise we won't be
                    // able to create DFA from this content model
                    particle = null;
                    reportSchemaError("cos-all-limited.1.2", null, child);
                }

            }
            else if (childName.equals(SchemaSymbols.ELT_CHOICE)) {
                particle = traverseChoice(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent);
            }
            else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) {
                particle = traverseSequence(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent);
            }
            else if (childName.equals(SchemaSymbols.ELT_ANY)) {
                particle = fSchemaHandler.fWildCardTraverser.traverseAny(child, schemaDoc, grammar);
            }
            else {
                Object [] args;
                if (choice) {
                    args = new Object[]{"choice", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)};
                }
                else {
                    args = new Object[]{"sequence", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)};
                }
                reportSchemaError("s4s-elt-must-match.1", args, child);
            }

            if (particle != null)
                fPArray.addParticle(particle);
        }

        particle = null;
        
        XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS];
        XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS];
        Long defaultVals = (Long)attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT];

        XSModelGroupImpl group = new XSModelGroupImpl();
        group.fCompositor = choice ? XSModelGroupImpl.MODELGROUP_CHOICE : XSModelGroupImpl.MODELGROUP_SEQUENCE;
        group.fParticleCount = fPArray.getParticleCount();
        group.fParticles = fPArray.popContext();
        group.fAnnotation = annotation;
        particle = new XSParticleDecl();
        particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
        particle.fMinOccurs = minAtt.intValue();
        particle.fMaxOccurs = maxAtt.intValue();
        particle.fValue = group;

        particle = checkOccurrences(particle,
                                    choice ? SchemaSymbols.ELT_CHOICE : SchemaSymbols.ELT_SEQUENCE,
                                    (Element)decl.getParentNode(),
                                    allContextFlags,
                                    defaultVals.longValue());
        fAttrChecker.returnAttrArray(attrValues, schemaDoc);

        return particle;
    
com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecltraverseSequence(org.w3c.dom.Element seqDecl, com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDocumentInfo schemaDoc, com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar grammar, int allContextFlags, com.sun.org.apache.xerces.internal.xs.XSObject parent)
Traverse the Sequence declaration Content: (annotation? , (element | group | choice | sequence | any)*)

param
seqDecl
param
schemaDoc
param
grammar
return


        return traverseSeqChoice(seqDecl, schemaDoc, grammar, allContextFlags, false, parent);