FileDocCategorySizeDatePackage
DTDGrammar.javaAPI DocJava SE 6 API110440Tue Jun 10 00:22:40 BST 2008com.sun.org.apache.xerces.internal.impl.dtd

DTDGrammar

public class DTDGrammar extends Object implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar
A DTD grammar. This class implements the XNI handler interfaces for DTD information so that it can build the approprate validation structures automatically from the callbacks.
xerces.internal
author
Eric Ye, IBM
author
Jeffrey Rodriguez, IBM
author
Andy Clark, IBM
author
Neil Graham, IBM
version
$Id: DTDGrammar.java,v 1.1.2.1 2005/08/01 03:36:39 jeffsuttor Exp $

Fields Summary
public static final int
TOP_LEVEL_SCOPE
Top level scope (-1).
private static final int
CHUNK_SHIFT
Chunk shift (8).
private static final int
CHUNK_SIZE
Chunk size (1 << CHUNK_SHIFT).
private static final int
CHUNK_MASK
Chunk mask (CHUNK_SIZE - 1).
private static final int
INITIAL_CHUNK_COUNT
Initial chunk count (1 << (10 - CHUNK_SHIFT)).
private static final short
LIST_FLAG
List flag (0x80).
private static final short
LIST_MASK
List mask (~LIST_FLAG).
private static final boolean
DEBUG
Debug DTDGrammar.
protected XMLDTDSource
fDTDSource
protected XMLDTDContentModelSource
fDTDContentModelSource
protected int
fCurrentElementIndex
Current element index.
protected int
fCurrentAttributeIndex
Current attribute index.
protected boolean
fReadingExternalDTD
fReadingExternalDTD
private SymbolTable
fSymbolTable
Symbol table.
protected XMLDTDDescription
fGrammarDescription
private int
fElementDeclCount
Number of element declarations.
private QName[]
fElementDeclName
Element declaration name.
private short[]
fElementDeclType
Element declaration type.
private int[]
fElementDeclContentSpecIndex
Element declaration content spec index. This index value is used to refer to the content spec information tables.
private ContentModelValidator[]
fElementDeclContentModelValidator
Element declaration content model validator. This validator is constructed from the content spec nodes.
private int[]
fElementDeclFirstAttributeDeclIndex
First attribute declaration of an element declaration.
private int[]
fElementDeclLastAttributeDeclIndex
Last attribute declaration of an element declaration.
private int
fAttributeDeclCount
Number of attribute declarations.
private QName[]
fAttributeDeclName
Attribute declaration name.
private boolean
fIsImmutable
private short[]
fAttributeDeclType
Attribute declaration type.
private String[]
fAttributeDeclEnumeration
Attribute declaration enumeration values.
private short[]
fAttributeDeclDefaultType
private DatatypeValidator[]
fAttributeDeclDatatypeValidator
private String[]
fAttributeDeclDefaultValue
private String[]
fAttributeDeclNonNormalizedDefaultValue
private int[]
fAttributeDeclNextAttributeDeclIndex
private int
fContentSpecCount
private short[]
fContentSpecType
private Object[]
fContentSpecValue
private Object[]
fContentSpecOtherValue
private int
fEntityCount
private String[]
fEntityName
private String[]
fEntityValue
private String[]
fEntityPublicId
private String[]
fEntitySystemId
private String[]
fEntityBaseSystemId
private String[]
fEntityNotation
private byte[]
fEntityIsPE
private byte[]
fEntityInExternal
private int
fNotationCount
private String[]
fNotationName
private String[]
fNotationPublicId
private String[]
fNotationSystemId
private String[]
fNotationBaseSystemId
private QNameHashtable
fElementIndexMap
Element index mapping table.
private QNameHashtable
fEntityIndexMap
Entity index mapping table.
private QNameHashtable
fNotationIndexMap
Notation index mapping table.
private boolean
fMixed
Mixed.
private QName
fQName
Temporary qualified name.
private QName
fQName2
Temporary qualified name.
protected XMLAttributeDecl
fAttributeDecl
Temporary Attribute decl.
private int
fLeafCount
private int
fEpsilonIndex
private XMLElementDecl
fElementDecl
Element declaration.
private XMLEntityDecl
fEntityDecl
Entity declaration.
private XMLSimpleType
fSimpleType
Simple type.
private XMLContentSpec
fContentSpec
Content spec node.
Hashtable
fElementDeclTab
table of XMLElementDecl
private short[]
fOpStack
Children content model operation stack.
private int[]
fNodeIndexStack
Children content model index stack.
private int[]
fPrevNodeIndexStack
Children content model previous node index stack.
private int
fDepth
Stack depth
private boolean[]
fPEntityStack
Entity stack.
private int
fPEDepth
private int[]
fElementDeclIsExternal
flag if the elementDecl is External.
private int[]
fAttributeDeclIsExternal
flag if the AttributeDecl is External.
int
valueIndex
int
prevNodeIndex
int
nodeIndex
Constructors Summary
public DTDGrammar(SymbolTable symbolTable, XMLDTDDescription desc)
Default constructor.


    //
    // Constructors
    //

       
         
        fSymbolTable = symbolTable;
        fGrammarDescription = desc;
    
Methods Summary
protected intaddContentSpecNode(short nodeType, java.lang.String nodeValue)
Create an XMLContentSpec for a single non-leaf

param
nodeType the type of XMLContentSpec to create - from XMLContentSpec.CONTENTSPECNODE_*
param
nodeValue handle to an XMLContentSpec
return
handle to the newly create XMLContentSpec


        // create content spec node
        int contentSpecIndex = createContentSpec();

        // set content spec node values
        fContentSpec.setValues(nodeType, nodeValue, null);
        setContentSpec(contentSpecIndex, fContentSpec);

        // return index
        return contentSpecIndex;

    
protected intaddContentSpecNode(short nodeType, int leftNodeIndex, int rightNodeIndex)
Create an XMLContentSpec for a two child leaf

param
nodeType the type of XMLContentSpec to create - from XMLContentSpec.CONTENTSPECNODE_*
param
leftNodeIndex handle to an XMLContentSpec
param
rightNodeIndex handle to an XMLContentSpec
return
handle to the newly create XMLContentSpec


        // create content spec node
        int contentSpecIndex = createContentSpec();

        // set content spec node values
        int[] leftIntArray  = new int[1];
        int[] rightIntArray = new int[1];

        leftIntArray[0]      = leftNodeIndex;
        rightIntArray[0]    = rightNodeIndex;
        fContentSpec.setValues(nodeType, leftIntArray, rightIntArray);
        setContentSpec(contentSpecIndex, fContentSpec);

        // return index
        return contentSpecIndex;

    
protected intaddUniqueLeafNode(java.lang.String elementName)
create an XMLContentSpec for a leaf

param
elementName the name (Element) for the node
return
handle to the newly create XMLContentSpec


        // create content spec node
        int contentSpecIndex = createContentSpec();

        // set content spec node values
        fContentSpec.setValues( XMLContentSpec.CONTENTSPECNODE_LEAF,
                                elementName, null);
        setContentSpec(contentSpecIndex, fContentSpec);

        // return index
        return contentSpecIndex;

    
public voidany(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A content model of ANY.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
#empty
see
#startGroup

private voidappendContentSpec(com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec contentSpec, java.lang.StringBuffer str, boolean parens, int parentContentSpecType)


        int thisContentSpec = contentSpec.type & 0x0f;
        switch (thisContentSpec) {
            case XMLContentSpec.CONTENTSPECNODE_LEAF: {
                if (contentSpec.value == null && contentSpec.otherValue == null) {
                    str.append("#PCDATA");
                }
                else if (contentSpec.value == null && contentSpec.otherValue != null) {
                    str.append("##any:uri="+contentSpec.otherValue);
                }
                else if (contentSpec.value == null) {
                    str.append("##any");
                }
                else {
                    str.append(contentSpec.value);
                }
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: {
                if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE  ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    str.append('(");
                    appendContentSpec(contentSpec, str, true, thisContentSpec );
                    str.append(')");
                } 
                else {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    appendContentSpec( contentSpec, str, true, thisContentSpec );
                }
                str.append('?");
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: {
                if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    str.append('(");
                    appendContentSpec(contentSpec, str, true, thisContentSpec);
                    str.append(')" );
                } 
                else {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    appendContentSpec(contentSpec, str, true, thisContentSpec);
                }
                str.append('*");
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: {
                if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE   ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE  ||
                    parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {

                    str.append('(");
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    appendContentSpec(contentSpec, str, true, thisContentSpec);
                    str.append(')" );
                }
                else {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    appendContentSpec(contentSpec, str, true, thisContentSpec);
                }
                str.append('+");
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_CHOICE:
            case XMLContentSpec.CONTENTSPECNODE_SEQ: {
                if (parens) {
                    str.append('(");
                }
                int type = contentSpec.type;
                int otherValue = ((int[])contentSpec.otherValue)[0];
                getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                appendContentSpec(contentSpec, str, contentSpec.type != type, thisContentSpec);
                if (type == XMLContentSpec.CONTENTSPECNODE_CHOICE) {
                    str.append('|");
                }
                else {
                    str.append(',");
                }
                getContentSpec(otherValue, contentSpec);
                appendContentSpec(contentSpec, str, true, thisContentSpec);
                if (parens) {
                    str.append(')");
                }
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ANY: {
                str.append("##any");
                if (contentSpec.otherValue != null) {
                    str.append(":uri=");
                    str.append(contentSpec.otherValue);
                }
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: {
                str.append("##other:uri=");
                str.append(contentSpec.otherValue);
                break;
            }
            case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: {
                str.append("##local");
                break;
            }
            default: {
                str.append("???");
                break;
            }

        } // switch type

    
public voidattributeDecl(java.lang.String elementName, java.lang.String attributeName, java.lang.String type, java.lang.String[] enumeration, java.lang.String defaultType, com.sun.org.apache.xerces.internal.xni.XMLString defaultValue, com.sun.org.apache.xerces.internal.xni.XMLString nonNormalizedDefaultValue, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
An attribute declaration.

param
elementName The name of the element that this attribute is associated with.
param
attributeName The name of the attribute.
param
type The attribute type. This value will be one of the following: "CDATA", "ENTITY", "ENTITIES", "ENUMERATION", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", or "NOTATION".
param
enumeration If the type has the value "ENUMERATION", this array holds the allowed attribute values; otherwise, this array is null.
param
defaultType The attribute default type. This value will be one of the following: "#FIXED", "#IMPLIED", "#REQUIRED", or null.
param
defaultValue The attribute default value, or null if no default value is specified.
param
nonNormalizedDefaultValue The attribute default value with no normalization performed, or null if no default value is specified.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        if ( this.fElementDeclTab.containsKey( (String) elementName) ) {
            //if ElementDecl has already being created in the Grammar then remove from table,
            //this.fElementDeclTab.remove( (String) elementName );
        }
        // then it is forward reference to a element decl, create the elementDecl first.
        else {
            fCurrentElementIndex = createElementDecl();//create element decl

            XMLElementDecl elementDecl       = new XMLElementDecl();
            elementDecl.name.setValues(null, elementName, elementName, null);

            elementDecl.scope= -1;

            //add(or set) this elementDecl to the local cache
            this.fElementDeclTab.put(elementName, elementDecl );

            //set internal structure
            setElementDecl(fCurrentElementIndex, elementDecl );
        }

        //Get Grammar index to grammar array
        int elementIndex       = getElementDeclIndex(elementName);
        
        //return, when more than one definition is provided for the same attribute of given element type
        //only the first declaration is binding and later declarations are ignored
        if (getAttributeDeclIndex(elementIndex, attributeName) != -1) {
            return;
        }

        fCurrentAttributeIndex = createAttributeDecl();// Create current Attribute Decl

        fSimpleType.clear();
        if ( defaultType != null ) {
            if ( defaultType.equals( "#FIXED") ) {
                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED;
            } else if ( defaultType.equals( "#IMPLIED") ) {
                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED;
            } else if ( defaultType.equals( "#REQUIRED") ) {
                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED;
            }
        }
        if ( DEBUG ) {
            System.out.println("defaultvalue = " + defaultValue.toString() );
        }
        fSimpleType.defaultValue      = defaultValue!=null ?  defaultValue.toString() : null;
        fSimpleType.nonNormalizedDefaultValue      = nonNormalizedDefaultValue!=null ?  nonNormalizedDefaultValue.toString() : null;
        fSimpleType.enumeration       = enumeration;

        if (type.equals("CDATA")) {
            fSimpleType.type = XMLSimpleType.TYPE_CDATA;
        }
        else if ( type.equals("ID") ) {
            fSimpleType.type = XMLSimpleType.TYPE_ID;
        }
        else if ( type.startsWith("IDREF") ) {
            fSimpleType.type = XMLSimpleType.TYPE_IDREF;
            if (type.indexOf("S") > 0) {
                fSimpleType.list = true;
            }
        }
        else if (type.equals("ENTITIES")) {
            fSimpleType.type = XMLSimpleType.TYPE_ENTITY;
            fSimpleType.list = true;
        }
        else if (type.equals("ENTITY")) {
            fSimpleType.type = XMLSimpleType.TYPE_ENTITY;
        }
        else if (type.equals("NMTOKENS")) {
            fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN;
            fSimpleType.list = true;
        }
        else if (type.equals("NMTOKEN")) {
            fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN;
        }
        else if (type.startsWith("NOTATION") ) {
            fSimpleType.type = XMLSimpleType.TYPE_NOTATION;
        }
        else if (type.startsWith("ENUMERATION") ) {
            fSimpleType.type = XMLSimpleType.TYPE_ENUMERATION;
        }
        else {
            // REVISIT: Report error message. -Ac
            System.err.println("!!! unknown attribute type "+type);
        }
        // REVISIT: The datatype should be stored with the attribute value
        //          and not special-cased in the XMLValidator. -Ac
        //fSimpleType.datatypeValidator = fDatatypeValidatorFactory.createDatatypeValidator(type, null, facets, fSimpleType.list);

        fQName.setValues(null, attributeName, attributeName, null);
        fAttributeDecl.setValues( fQName, fSimpleType, false );

        setAttributeDecl(elementIndex, fCurrentAttributeIndex, fAttributeDecl);

        int chunk = fCurrentAttributeIndex >> CHUNK_SHIFT;
        int index = fCurrentAttributeIndex & CHUNK_MASK;
        ensureAttributeDeclCapacity(chunk);
        fAttributeDeclIsExternal[chunk][index] = fReadingExternalDTD ?  1 : 0;

    
private final com.sun.org.apache.xerces.internal.impl.dtd.models.CMNodebuildSyntaxTree(int startNode, com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec contentSpec)


        // We will build a node at this level for the new tree
        CMNode nodeRet = null;
        getContentSpec(startNode, contentSpec);
        if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY) {
            //nodeRet = new CMAny(contentSpec.type, -1, fLeafCount++);
            nodeRet = new CMAny(contentSpec.type, (String)contentSpec.otherValue, fLeafCount++);
        }
        else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
            nodeRet = new CMAny(contentSpec.type, (String)contentSpec.otherValue, fLeafCount++);
        }
        else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
            nodeRet = new CMAny(contentSpec.type, null, fLeafCount++);
        }
        //
        //  If this node is a leaf, then its an easy one. We just add it
        //  to the tree.
        //
        else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
            //
            //  Create a new leaf node, and pass it the current leaf count,
            //  which is its DFA state position. Bump the leaf count after
            //  storing it. This makes the positions zero based since we
            //  store first and then increment.
            //
            fQName.setValues(null, (String)contentSpec.value, 
                              (String)contentSpec.value, (String)contentSpec.otherValue);
            nodeRet = new CMLeaf(fQName, fLeafCount++);
        } 
        else {
            //
            //  Its not a leaf, so we have to recurse its left and maybe right
            //  nodes. Save both values before we recurse and trash the node.
            final int leftNode = ((int[])contentSpec.value)[0];
            final int rightNode = ((int[])contentSpec.otherValue)[0];

            if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE)
                ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) {
                //
                //  Recurse on both children, and return a binary op node
                //  with the two created sub nodes as its children. The node
                //  type is the same type as the source.
                //

                nodeRet = new CMBinOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec)
                                       , buildSyntaxTree(rightNode, contentSpec));
            } 
            else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE) {
                nodeRet = new CMUniOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec));
            } 
            else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE
                  || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE
                  || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) {
                nodeRet = new CMUniOp(contentSpec.type, buildSyntaxTree(leftNode, contentSpec));
            } 
            else {
                throw new RuntimeException("ImplementationMessages.VAL_CST");
            }
        }
        // And return our new node for this level
        return nodeRet;
    
public voidcomment(com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A comment.

param
text The text in the comment.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by application to signal an error.

private voidcontentSpecTree(int contentSpecIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec contentSpec, com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar$ChildrenList children)
Build a vector of valid QNames from Content Spec table.

param
contentSpecIndex Content Spec index
param
vectorQName Array of QName
exception
RuntimeException


        // Handle any and leaf nodes
        getContentSpec( contentSpecIndex, contentSpec);
        if ( contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF ||
            (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY ||
            (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL ||
            (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {

            // resize arrays, if needed
            if (children.length == children.qname.length) {
                QName[] newQName = new QName[children.length * 2];
                System.arraycopy(children.qname, 0, newQName, 0, children.length);
                children.qname = newQName;
                int[] newType = new int[children.length * 2];
                System.arraycopy(children.type, 0, newType, 0, children.length);
                children.type = newType;
            }

            // save values and return length
            children.qname[children.length] = new QName(null, (String)contentSpec.value, 
                                                     (String) contentSpec.value, 
                                                     (String) contentSpec.otherValue);
            children.type[children.length] = contentSpec.type;
            children.length++;
            return;
        }

        //
        //  Its not a leaf, so we have to recurse its left and maybe right
        //  nodes. Save both values before we recurse and trash the node.
        //
        final int leftNode = contentSpec.value != null 
                           ? ((int[])(contentSpec.value))[0] : -1;
        int rightNode = -1 ;
        if (contentSpec.otherValue != null ) 
            rightNode = ((int[])(contentSpec.otherValue))[0];
        else 
            return;

        if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE ||
            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ) {
            contentSpecTree(leftNode, contentSpec, children);
            contentSpecTree(rightNode, contentSpec, children);
            return;
        }

        if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ||
            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) {
            contentSpecTree(leftNode, contentSpec, children);
            return;
        }

        // error
        throw new RuntimeException("Invalid content spec type seen in contentSpecTree() method of AbstractDTDGrammar class : "+contentSpec.type);

    
protected intcreateAttributeDecl()

      int chunk = fAttributeDeclCount >> CHUNK_SHIFT;
      int index = fAttributeDeclCount & CHUNK_MASK;

      ensureAttributeDeclCapacity(chunk);
      fAttributeDeclName[chunk][index]                    = new QName();
      fAttributeDeclType[chunk][index]                    = -1;
      fAttributeDeclDatatypeValidator[chunk][index]       = null;
      fAttributeDeclEnumeration[chunk][index]             = null;
      fAttributeDeclDefaultType[chunk][index]             = XMLSimpleType.DEFAULT_TYPE_IMPLIED;
      fAttributeDeclDefaultValue[chunk][index]            = null;
      fAttributeDeclNonNormalizedDefaultValue[chunk][index]            = null;
      fAttributeDeclNextAttributeDeclIndex[chunk][index]  = -1;
      return fAttributeDeclCount++;
   
private com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidatorcreateChildModel(int contentSpecIndex)
When the element has a 'CHILDREN' model, this method is called to create the content model object. It looks for some special case simple models and creates SimpleContentModel objects for those. For the rest it creates the standard DFA style model.

        
        //
        //  Get the content spec node for the element we are working on.
        //  This will tell us what kind of node it is, which tells us what
        //  kind of model we will try to create.
        //
        XMLContentSpec contentSpec = new XMLContentSpec();
        getContentSpec(contentSpecIndex, contentSpec);

        if ((contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY ||
            (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER ||
            (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
            // let fall through to build a DFAContentModel
        }

        else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
            //
            //  Check that the left value is not -1, since any content model
            //  with PCDATA should be MIXED, so we should not have gotten here.
            //
            if (contentSpec.value == null && contentSpec.otherValue == null)
                throw new RuntimeException("ImplementationMessages.VAL_NPCD");

            //
            //  Its a single leaf, so its an 'a' type of content model, i.e.
            //  just one instance of one element. That one is definitely a
            //  simple content model.
            //

            fQName.setValues(null, (String)contentSpec.value, 
                              (String)contentSpec.value, (String)contentSpec.otherValue);
            return new SimpleContentModel(contentSpec.type, fQName, null);
        } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE)
                    ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) {
            //
            //  Lets see if both of the children are leafs. If so, then it
            //  it has to be a simple content model
            //
            XMLContentSpec contentSpecLeft  = new XMLContentSpec();
            XMLContentSpec contentSpecRight = new XMLContentSpec();

            getContentSpec( ((int[])contentSpec.value)[0], contentSpecLeft);
            getContentSpec( ((int[])contentSpec.otherValue)[0], contentSpecRight);

            if ((contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF)
                 &&  (contentSpecRight.type == XMLContentSpec.CONTENTSPECNODE_LEAF)) {
                //
                //  Its a simple choice or sequence, so we can do a simple
                //  content model for it.
                //
                fQName.setValues(null, (String)contentSpecLeft.value, 
                                  (String)contentSpecLeft.value, (String)contentSpecLeft.otherValue);
                fQName2.setValues(null, (String)contentSpecRight.value, 
                                  (String)contentSpecRight.value, (String)contentSpecRight.otherValue);
                return new SimpleContentModel(contentSpec.type, fQName, fQName2);
            }
        } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE)
                    ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE)
                    ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE)) {
            //
            //  Its a repetition, so see if its one child is a leaf. If so
            //  its a repetition of a single element, so we can do a simple
            //  content model for that.
            //
            XMLContentSpec contentSpecLeft = new XMLContentSpec();
            getContentSpec(((int[])contentSpec.value)[0], contentSpecLeft);
    
            if (contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
                //
                //  It is, so we can create a simple content model here that
                //  will check for this repetition. We pass -1 for the unused
                //  right node.
                //
                fQName.setValues(null, (String)contentSpecLeft.value, 
                                  (String)contentSpecLeft.value, (String)contentSpecLeft.otherValue);
                return new SimpleContentModel(contentSpec.type, fQName, null);
            }
        } else {
            throw new RuntimeException("ImplementationMessages.VAL_CST");
        }

        //
        //  Its not a simple content model, so here we have to create a DFA
        //  for this element. So we create a DFAContentModel object. He
        //  encapsulates all of the work to create the DFA.
        //

        fLeafCount = 0;
        //int leafCount = countLeaves(contentSpecIndex);
        fLeafCount = 0;
        CMNode cmn    = buildSyntaxTree(contentSpecIndex, contentSpec);

        // REVISIT: has to be fLeafCount because we convert x+ to x,x*, one more leaf
        return new DFAContentModel(  cmn, fLeafCount, false);

    
protected intcreateContentSpec()

      int chunk = fContentSpecCount >> CHUNK_SHIFT;
      int index = fContentSpecCount & CHUNK_MASK;

      ensureContentSpecCapacity(chunk);
      fContentSpecType[chunk][index]       = -1;
      fContentSpecValue[chunk][index]      = null;
      fContentSpecOtherValue[chunk][index] = null;

      return fContentSpecCount++;
   
protected intcreateElementDecl()

      int chunk = fElementDeclCount >> CHUNK_SHIFT;
      int index = fElementDeclCount & CHUNK_MASK;
      ensureElementDeclCapacity(chunk);
      fElementDeclName[chunk][index]                    = new QName(); 
      fElementDeclType[chunk][index]                    = -1;  
      fElementDeclContentModelValidator[chunk][index]   = null;
      fElementDeclFirstAttributeDeclIndex[chunk][index] = -1;
      fElementDeclLastAttributeDeclIndex[chunk][index]  = -1;
      return fElementDeclCount++;
   
protected intcreateEntityDecl()

       int chunk = fEntityCount >> CHUNK_SHIFT;
       int index = fEntityCount & CHUNK_MASK;

      ensureEntityDeclCapacity(chunk);
      fEntityIsPE[chunk][index] = 0;
      fEntityInExternal[chunk][index] = 0;

      return fEntityCount++;
   
protected intcreateNotationDecl()

       int chunk = fNotationCount >> CHUNK_SHIFT;
       int index = fNotationCount & CHUNK_MASK;

       ensureNotationDeclCapacity(chunk);

       return fNotationCount++;
   
public voidelement(java.lang.String elementName, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A referenced element in a mixed or children content model.

param
elementName The name of the referenced element.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

        if (fMixed) {
            if (fNodeIndexStack[fDepth] == -1 ) {
                fNodeIndexStack[fDepth] = addUniqueLeafNode(elementName);
            }
            else {
                fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,
                                                             fNodeIndexStack[fDepth],
                                                             addUniqueLeafNode(elementName));
            }
        }
        else {
            fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, elementName);
        }
    
public voidelementDecl(java.lang.String name, java.lang.String contentModel, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
An element declaration.

param
name The name of the element.
param
contentModel The element content model.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ;

        // check if it is already defined
        if ( tmpElementDecl != null ) {
            if (tmpElementDecl.type == -1) {
                fCurrentElementIndex = getElementDeclIndex(name);
            }
            else {
                // duplicate element, ignored.
                return;
            }
        }
        else {
            fCurrentElementIndex = createElementDecl();//create element decl
        }

        XMLElementDecl elementDecl       = new XMLElementDecl();
        
        fQName.setValues(null, name, name, null);
       
        elementDecl.name.setValues(fQName);

        elementDecl.contentModelValidator = null;
        elementDecl.scope= -1;
        if (contentModel.equals("EMPTY")) {
            elementDecl.type = XMLElementDecl.TYPE_EMPTY;
        }
        else if (contentModel.equals("ANY")) {
            elementDecl.type = XMLElementDecl.TYPE_ANY;
        }
        else if (contentModel.startsWith("(") ) {
            if (contentModel.indexOf("#PCDATA") > 0 ) {
                elementDecl.type = XMLElementDecl.TYPE_MIXED;
            }
            else {
                elementDecl.type = XMLElementDecl.TYPE_CHILDREN;
            }
        }


        //add(or set) this elementDecl to the local cache
        this.fElementDeclTab.put(name, elementDecl );

        fElementDecl         = elementDecl;

        if ((fDepth == 0 ||
            (fDepth == 1 && elementDecl.type == XMLElementDecl.TYPE_MIXED)) &&
            fNodeIndexStack != null) {
            if (elementDecl.type == XMLElementDecl.TYPE_MIXED) {
                int pcdata = addUniqueLeafNode(null);
                if (fNodeIndexStack[0] == -1) {
                    fNodeIndexStack[0] = pcdata;
                }
                else {
                    fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,
                                                            pcdata, fNodeIndexStack[0]);
                }
            }
            setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]);
        }

        if ( DEBUG ) {
            System.out.println(  "name = " + fElementDecl.name.localpart );
            System.out.println(  "Type = " + fElementDecl.type );
        }

        setElementDecl(fCurrentElementIndex, fElementDecl );//set internal structure

        int chunk = fCurrentElementIndex >> CHUNK_SHIFT;
        int index = fCurrentElementIndex & CHUNK_MASK;
        ensureElementDeclCapacity(chunk);
        fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0;

    
public voidempty(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A content model of EMPTY.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
#any
see
#startGroup

public voidendAttlist(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of an attribute list.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

public voidendConditional(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of a conditional section.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

public voidendContentModel(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of a content model.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

public voidendDTD(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of the DTD.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

        fIsImmutable = true;
        // make sure our description contains useful stuff...
        if(fGrammarDescription.getRootName() == null) {
            // we don't know what the root is; so use possibleRoots...
            int chunk, index = 0;
            String currName = null;
            Vector elements = new Vector();
            for (int i=0; i < fElementDeclCount; i++) {
                chunk = i >> CHUNK_SHIFT;
                index = i & CHUNK_MASK;
                currName = fElementDeclName[chunk][index].rawname;
                elements.addElement(currName);
            }
            fGrammarDescription.setPossibleRoots(elements);
        }
    
public voidendExternalSubset(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of the DTD external subset.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

        fReadingExternalDTD = false;
    
public voidendGroup(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The end of a group for mixed or children content models.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        if (!fMixed) {
            if (fPrevNodeIndexStack[fDepth] != -1) {
                fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
            }
            int nodeIndex = fNodeIndexStack[fDepth--];
            fNodeIndexStack[fDepth] = nodeIndex;
        }

    
public voidendParameterEntity(java.lang.String name, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
This method notifies the end of an entity. The DTD has the pseudo-name of "[dtd]" and parameter entity names start with '%'.

Note: Since the DTD is an entity, the handler will be notified of the end of the DTD entity by calling the endEntity method with the entity name "[dtd]" after calling the endDTD method.

param
name The name of the entity.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        fPEDepth--;
        fReadingExternalDTD = fPEntityStack[fPEDepth];

    
private voidensureAttributeDeclCapacity(int chunk)


        if (chunk >= fAttributeDeclName.length) {
            fAttributeDeclIsExternal = resize(fAttributeDeclIsExternal,
                                       fAttributeDeclIsExternal.length * 2);
            fAttributeDeclName = resize(fAttributeDeclName, fAttributeDeclName.length * 2);
            fAttributeDeclType = resize(fAttributeDeclType, fAttributeDeclType.length * 2);
            fAttributeDeclEnumeration = resize(fAttributeDeclEnumeration, fAttributeDeclEnumeration.length * 2);
            fAttributeDeclDefaultType = resize(fAttributeDeclDefaultType, fAttributeDeclDefaultType.length * 2);
            fAttributeDeclDatatypeValidator = resize(fAttributeDeclDatatypeValidator, fAttributeDeclDatatypeValidator.length * 2);
            fAttributeDeclDefaultValue = resize(fAttributeDeclDefaultValue, fAttributeDeclDefaultValue.length * 2);
            fAttributeDeclNonNormalizedDefaultValue = resize(fAttributeDeclNonNormalizedDefaultValue, fAttributeDeclNonNormalizedDefaultValue.length * 2);
            fAttributeDeclNextAttributeDeclIndex = resize(fAttributeDeclNextAttributeDeclIndex, fAttributeDeclNextAttributeDeclIndex.length * 2);
        }
        else if (fAttributeDeclName[chunk] != null) {
            return;
        }

        fAttributeDeclIsExternal[chunk] = new int[CHUNK_SIZE];
        fAttributeDeclName[chunk] = new QName[CHUNK_SIZE];
        fAttributeDeclType[chunk] = new short[CHUNK_SIZE];
        fAttributeDeclEnumeration[chunk] = new String[CHUNK_SIZE][];
        fAttributeDeclDefaultType[chunk] = new short[CHUNK_SIZE];
        fAttributeDeclDatatypeValidator[chunk] = new DatatypeValidator[CHUNK_SIZE];
        fAttributeDeclDefaultValue[chunk] = new String[CHUNK_SIZE];
        fAttributeDeclNonNormalizedDefaultValue[chunk] = new String[CHUNK_SIZE];
        fAttributeDeclNextAttributeDeclIndex[chunk] = new int[CHUNK_SIZE];
        return;
    
private voidensureContentSpecCapacity(int chunk)

        if (chunk >= fContentSpecType.length) {
            fContentSpecType = resize(fContentSpecType, fContentSpecType.length * 2);
            fContentSpecValue = resize(fContentSpecValue, fContentSpecValue.length * 2);
            fContentSpecOtherValue = resize(fContentSpecOtherValue, fContentSpecOtherValue.length * 2);
        }
        else if (fContentSpecType[chunk] != null) {
            return;
        }

        fContentSpecType[chunk] = new short[CHUNK_SIZE];
        fContentSpecValue[chunk] = new Object[CHUNK_SIZE];
        fContentSpecOtherValue[chunk] = new Object[CHUNK_SIZE];
        return;
    
private voidensureElementDeclCapacity(int chunk)

        if (chunk >= fElementDeclName.length) {
            fElementDeclIsExternal = resize(fElementDeclIsExternal,
                                     fElementDeclIsExternal.length * 2);

            fElementDeclName = resize(fElementDeclName, fElementDeclName.length * 2);
            fElementDeclType = resize(fElementDeclType, fElementDeclType.length * 2);
            fElementDeclContentModelValidator = resize(fElementDeclContentModelValidator, fElementDeclContentModelValidator.length * 2);
            fElementDeclContentSpecIndex = resize(fElementDeclContentSpecIndex,fElementDeclContentSpecIndex.length * 2);
            fElementDeclFirstAttributeDeclIndex = resize(fElementDeclFirstAttributeDeclIndex, fElementDeclFirstAttributeDeclIndex.length * 2);
            fElementDeclLastAttributeDeclIndex = resize(fElementDeclLastAttributeDeclIndex, fElementDeclLastAttributeDeclIndex.length * 2);
        }
        else if (fElementDeclName[chunk] != null) {
            return;
        }

        fElementDeclIsExternal[chunk] = new int[CHUNK_SIZE];
        fElementDeclName[chunk] = new QName[CHUNK_SIZE];
        fElementDeclType[chunk] = new short[CHUNK_SIZE];
        fElementDeclContentModelValidator[chunk] = new ContentModelValidator[CHUNK_SIZE];
        fElementDeclContentSpecIndex[chunk] = new int[CHUNK_SIZE];
        fElementDeclFirstAttributeDeclIndex[chunk] = new int[CHUNK_SIZE];
        fElementDeclLastAttributeDeclIndex[chunk] = new int[CHUNK_SIZE];
        return;
    
private voidensureEntityDeclCapacity(int chunk)

        if (chunk >= fEntityName.length) {
            fEntityName = resize(fEntityName, fEntityName.length * 2);
            fEntityValue = resize(fEntityValue, fEntityValue.length * 2);
            fEntityPublicId = resize(fEntityPublicId, fEntityPublicId.length * 2);
            fEntitySystemId = resize(fEntitySystemId, fEntitySystemId.length * 2);
            fEntityBaseSystemId = resize(fEntityBaseSystemId, fEntityBaseSystemId.length * 2);
            fEntityNotation = resize(fEntityNotation, fEntityNotation.length * 2);
            fEntityIsPE = resize(fEntityIsPE, fEntityIsPE.length * 2);
            fEntityInExternal = resize(fEntityInExternal, fEntityInExternal.length * 2);
        }
        else if (fEntityName[chunk] != null) {
            return;
        }

        fEntityName[chunk] = new String[CHUNK_SIZE];
        fEntityValue[chunk] = new String[CHUNK_SIZE];
        fEntityPublicId[chunk] = new String[CHUNK_SIZE];
        fEntitySystemId[chunk] = new String[CHUNK_SIZE];
        fEntityBaseSystemId[chunk] = new String[CHUNK_SIZE];
        fEntityNotation[chunk] = new String[CHUNK_SIZE];
        fEntityIsPE[chunk] = new byte[CHUNK_SIZE];
        fEntityInExternal[chunk] = new byte[CHUNK_SIZE];
        return;
    
private voidensureNotationDeclCapacity(int chunk)

        if (chunk >= fNotationName.length) {
            fNotationName = resize(fNotationName, fNotationName.length * 2);
            fNotationPublicId = resize(fNotationPublicId, fNotationPublicId.length * 2);
            fNotationSystemId = resize(fNotationSystemId, fNotationSystemId.length * 2);
            fNotationBaseSystemId = resize(fNotationBaseSystemId, fNotationBaseSystemId.length * 2);
        }
        else if (fNotationName[chunk] != null) {
            return;
        }

        fNotationName[chunk] = new String[CHUNK_SIZE];
        fNotationPublicId[chunk] = new String[CHUNK_SIZE];
        fNotationSystemId[chunk] = new String[CHUNK_SIZE];
        fNotationBaseSystemId[chunk] = new String[CHUNK_SIZE];
        return;
    
public voidexternalEntityDecl(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
An external entity declaration.

param
name The name of the entity. Parameter entity names start with '%', whereas the name of a general entity is just the entity name.
param
identifier An object containing all location information pertinent to this external entity declaration.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        int entityIndex = getEntityDeclIndex(name);
        if( entityIndex == -1){
            entityIndex = createEntityDecl();
            boolean isPE = name.startsWith("%");
            boolean inExternal = fReadingExternalDTD;

            XMLEntityDecl  entityDecl = new XMLEntityDecl();
            entityDecl.setValues(name, identifier.getPublicId(), identifier.getLiteralSystemId(),
                                identifier.getBaseSystemId(),
                                null, null, isPE, inExternal);

            setEntityDecl(entityIndex, entityDecl);
        }
    
public booleangetAttributeDecl(int attributeDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLAttributeDecl attributeDecl)
getAttributeDecl

param
attributeDeclIndex
param
attributeDecl The values of this structure are set by this call.
return
true if getAttributeDecl was able to fill in the value of attributeDecl

        if (attributeDeclIndex < 0 || attributeDeclIndex >= fAttributeDeclCount) {
            return false;
        }
        int chunk = attributeDeclIndex >> CHUNK_SHIFT;
        int index = attributeDeclIndex & CHUNK_MASK;

        attributeDecl.name.setValues(fAttributeDeclName[chunk][index]);

        short attributeType;
        boolean isList;

        if (fAttributeDeclType[chunk][index] == -1) {

            attributeType = -1;
            isList = false;
        } else {
            attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK);
            isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0;
        }
        attributeDecl.simpleType.setValues(attributeType,fAttributeDeclName[chunk][index].localpart,
                                           fAttributeDeclEnumeration[chunk][index],
                                           isList, fAttributeDeclDefaultType[chunk][index],
                                           fAttributeDeclDefaultValue[chunk][index], 
                                           fAttributeDeclNonNormalizedDefaultValue[chunk][index], 
                                           fAttributeDeclDatatypeValidator[chunk][index]);
        return true;

    
public intgetAttributeDeclIndex(int elementDeclIndex, java.lang.String attributeDeclName)

        if (elementDeclIndex == -1) {
            return -1;
        }
        int attDefIndex = getFirstAttributeDeclIndex(elementDeclIndex);
        while (attDefIndex != -1) {
            getAttributeDecl(attDefIndex, fAttributeDecl);

            if (fAttributeDecl.name.rawname == attributeDeclName
                || attributeDeclName.equals(fAttributeDecl.name.rawname) ) {
                return attDefIndex;
            }
            attDefIndex = getNextAttributeDeclIndex(attDefIndex);
        }
        return -1;
    
public booleangetAttributeDeclIsExternal(int attributeDeclIndex)
Returns true if the specified attribute declaration is external.

param
attributeDeclIndex Attribute declaration index.


        if (attributeDeclIndex < 0) {
            return false;
        }

        int chunk = attributeDeclIndex >> CHUNK_SHIFT;
        int index = attributeDeclIndex & CHUNK_MASK;
        return (fAttributeDeclIsExternal[chunk][index] != 0);
    
public booleangetContentSpec(int contentSpecIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec contentSpec)
getContentSpec

param
contentSpecIndex
param
contentSpec
return
true if find the requested contentSpec node, false otherwise

        if (contentSpecIndex < 0 || contentSpecIndex >= fContentSpecCount )
            return false;

        int chunk = contentSpecIndex >> CHUNK_SHIFT;
        int index = contentSpecIndex & CHUNK_MASK;

        contentSpec.type       = fContentSpecType[chunk][index];
        contentSpec.value      = fContentSpecValue[chunk][index];
        contentSpec.otherValue = fContentSpecOtherValue[chunk][index];
        return true;
    
public java.lang.StringgetContentSpecAsString(int elementDeclIndex)
getContentSpecAsString

param
elementDeclIndex
return
String


        if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
            return null;
        }

        int chunk = elementDeclIndex >> CHUNK_SHIFT;
        int index = elementDeclIndex &  CHUNK_MASK;

        int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index];

        // lookup content spec node
        XMLContentSpec contentSpec = new XMLContentSpec();

        if (getContentSpec(contentSpecIndex, contentSpec)) {

            // build string
            StringBuffer str = new StringBuffer();
            int    parentContentSpecType = contentSpec.type & 0x0f;
            int    nextContentSpec;
            switch (parentContentSpecType) {
                case XMLContentSpec.CONTENTSPECNODE_LEAF: {
                    str.append('(");
                    if (contentSpec.value == null && contentSpec.otherValue == null) {
                        str.append("#PCDATA");
                    }
                    else {
                        str.append(contentSpec.value);
                    }
                    str.append(')");
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    nextContentSpec = contentSpec.type;

                    if (nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
                        str.append('(");
                        str.append(contentSpec.value);
                        str.append(')");
                    } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
                        str.append('(" );
                        appendContentSpec(contentSpec, str, 
                                          true, parentContentSpecType );
                        str.append(')");
                    } else {
                        appendContentSpec(contentSpec, str, 
                                          true, parentContentSpecType );
                    }
                    str.append('?");
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    nextContentSpec = contentSpec.type;

                    if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
                        str.append('(");
                        if (contentSpec.value == null && contentSpec.otherValue == null) {
                            str.append("#PCDATA");
                        }
                        else if (contentSpec.otherValue != null) {
                            str.append("##any:uri="+contentSpec.otherValue);
                        }
                        else if (contentSpec.value == null) {
                            str.append("##any");
                        }
                        else {
                            appendContentSpec(contentSpec, str, 
                                              true, parentContentSpecType );
                        }
                        str.append(')");
                    } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
                        str.append('(" );
                        appendContentSpec(contentSpec, str, 
                                          true, parentContentSpecType );
                        str.append(')");
                    } else {
                        appendContentSpec(contentSpec, str, 
                                          true, parentContentSpecType );
                    }
                    str.append('*");
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: {
                    getContentSpec(((int[])contentSpec.value)[0], contentSpec);
                    nextContentSpec = contentSpec.type;

                    if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
                        str.append('(");
                        if (contentSpec.value == null && contentSpec.otherValue == null) {
                            str.append("#PCDATA");
                        }
                        else if (contentSpec.otherValue != null) {
                            str.append("##any:uri="+contentSpec.otherValue);
                        }
                        else if (contentSpec.value == null) {
                            str.append("##any");
                        }
                        else {
                            str.append(contentSpec.value);
                        }
                        str.append(')");
                    } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE  ||
                        nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
                        str.append('(" );
                        appendContentSpec(contentSpec, str, 
                                          true, parentContentSpecType );
                        str.append(')");
                    } else {
                        appendContentSpec(contentSpec, str,
                                          true, parentContentSpecType);
                    }
                    str.append('+");
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_CHOICE:
                case XMLContentSpec.CONTENTSPECNODE_SEQ: {
                    appendContentSpec(contentSpec, str, 
                                      true, parentContentSpecType );
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ANY: {
                    str.append("##any");
                    if (contentSpec.otherValue != null) {
                        str.append(":uri=");
                        str.append(contentSpec.otherValue);
                    }
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: {
                    str.append("##other:uri=");
                    str.append(contentSpec.otherValue);
                    break;
                }
                case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: {
                    str.append("##local");
                    break;
                }
                default: {
                    str.append("???");
                }

            } // switch type

            // return string
            return str.toString();
        }

        // not found
        return null;

    
public shortgetContentSpecType(int elementIndex)
make separate function for getting contentSpecType of element. we can avoid setting of the element values.

        if (elementIndex < 0 || elementIndex >= fElementDeclCount) {
            return -1 ;
        }

        int chunk = elementIndex >> CHUNK_SHIFT;
        int index = elementIndex &  CHUNK_MASK;
			
        if(fElementDeclType[chunk][index] == -1){
            return -1 ;
			    }
        else{
				       return (short) (fElementDeclType[chunk][index] & LIST_MASK);
			    }

		
public com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSourcegetDTDContentModelSource()

        return fDTDContentModelSource;
    
public com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSourcegetDTDSource()

        return fDTDSource;
    
protected com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidatorgetElementContentModelValidator(int elementDeclIndex)
getElementContentModelValidator

param
elementDeclIndex
return
its ContentModelValidator if any.


        int chunk = elementDeclIndex >> CHUNK_SHIFT;
        int index = elementDeclIndex & CHUNK_MASK;

        ContentModelValidator contentModel    =  fElementDeclContentModelValidator[chunk][index];

        // If we have one, just return that. Otherwise, gotta create one
        if (contentModel != null) {
            return contentModel;
        }

        int contentType = fElementDeclType[chunk][index];
        if (contentType == XMLElementDecl.TYPE_SIMPLE) {
            return null;
        }

        // Get the type of content this element has
        int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; 

        /***
        if ( contentSpecIndex == -1 )
            return null;
        /***/

        XMLContentSpec  contentSpec = new XMLContentSpec();
        getContentSpec( contentSpecIndex, contentSpec );

        // And create the content model according to the spec type
        if ( contentType == XMLElementDecl.TYPE_MIXED ) {
            //
            //  Just create a mixel content model object. This type of
            //  content model is optimized for mixed content validation.
            //
            ChildrenList children = new ChildrenList();
            contentSpecTree(contentSpecIndex, contentSpec, children);
            contentModel = new MixedContentModel(children.qname,
                                                 children.type,
                                                 0, children.length, 
                                                 false);
        } else if (contentType == XMLElementDecl.TYPE_CHILDREN) {
            //  This method will create an optimal model for the complexity
            //  of the element's defined model. If its simple, it will create
            //  a SimpleContentModel object. If its a simple list, it will
            //  create a SimpleListContentModel object. If its complex, it
            //  will create a DFAContentModel object.
            //
            contentModel = createChildModel(contentSpecIndex);
        } else {
            throw new RuntimeException("Unknown content type for a element decl "
                                     + "in getElementContentModelValidator() in AbstractDTDGrammar class");
        }

        // Add the new model to the content model for this element
        fElementDeclContentModelValidator[chunk][index] = contentModel;

        return contentModel;

    
public booleangetElementDecl(int elementDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl elementDecl)
getElementDecl

param
elementDeclIndex
param
elementDecl The values of this structure are set by this call.
return
True if find the element, False otherwise.


        if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
            return false;
        }

        int chunk = elementDeclIndex >> CHUNK_SHIFT;
        int index = elementDeclIndex &  CHUNK_MASK;

        elementDecl.name.setValues(fElementDeclName[chunk][index]);

        if (fElementDeclType[chunk][index] == -1) {
            elementDecl.type                    = -1;
            elementDecl.simpleType.list = false;
        } else {
            elementDecl.type            = (short) (fElementDeclType[chunk][index] & LIST_MASK);
            elementDecl.simpleType.list = (fElementDeclType[chunk][index] & LIST_FLAG) != 0;
        }

        /* Validators are null until we add that code */
        if (elementDecl.type == XMLElementDecl.TYPE_CHILDREN || elementDecl.type == XMLElementDecl.TYPE_MIXED) {
            elementDecl.contentModelValidator = getElementContentModelValidator(elementDeclIndex);
        }
              
        elementDecl.simpleType.datatypeValidator = null;
        elementDecl.simpleType.defaultType       = -1;
        elementDecl.simpleType.defaultValue      = null;

        return true;

    
public intgetElementDeclIndex(java.lang.String elementDeclName)
getElementDeclIndex

param
elementDeclName
return
index of the elementDeclName in scope

        int mapping = fElementIndexMap.get(elementDeclName);
        //System.out.println("getElementDeclIndex("+elementDeclName+") -> "+mapping);
        return mapping;
    
public intgetElementDeclIndex(com.sun.org.apache.xerces.internal.xni.QName elementDeclQName)
Returns the element decl index.

param
elementDeclQName qualilfied name of the element

        return getElementDeclIndex(elementDeclQName.rawname);
    
public booleangetElementDeclIsExternal(int elementDeclIndex)
Returns true if the specified element declaration is external.

param
elementDeclIndex The element declaration index.


        if (elementDeclIndex < 0) {
            return false;
        }

        int chunk = elementDeclIndex >> CHUNK_SHIFT;
        int index = elementDeclIndex & CHUNK_MASK;
        return (fElementDeclIsExternal[chunk][index] != 0);

    
public booleangetEntityDecl(int entityDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLEntityDecl entityDecl)
getEntityDecl

param
entityDeclIndex
param
entityDecl
return
true if getEntityDecl was able to fill entityDecl with the contents of the entity with index entityDeclIndex

        if (entityDeclIndex < 0 || entityDeclIndex >= fEntityCount) {
            return false;
        }
        int chunk = entityDeclIndex >> CHUNK_SHIFT;
        int index = entityDeclIndex & CHUNK_MASK;

        entityDecl.setValues(fEntityName[chunk][index],
                             fEntityPublicId[chunk][index],
                             fEntitySystemId[chunk][index],
                             fEntityBaseSystemId[chunk][index],
                             fEntityNotation[chunk][index],
                             fEntityValue[chunk][index],
                             fEntityIsPE[chunk][index] == 0 ? false : true ,
                             fEntityInExternal[chunk][index] == 0 ? false : true );

        return true;
    
public intgetEntityDeclIndex(java.lang.String entityDeclName)
getEntityDeclIndex

param
entityDeclName
return
the index of the EntityDecl

        if (entityDeclName == null) {
            return -1;
        }

        return fEntityIndexMap.get(entityDeclName);
    
public intgetFirstAttributeDeclIndex(int elementDeclIndex)
getFirstAttributeDeclIndex

param
elementDeclIndex
return
index of the first attribute for element declaration elementDeclIndex

        int chunk = elementDeclIndex >> CHUNK_SHIFT;
        int index = elementDeclIndex &  CHUNK_MASK;

        return  fElementDeclFirstAttributeDeclIndex[chunk][index];
    
public intgetFirstElementDeclIndex()
Returns the index of the first element declaration. This index is then used to query more information about the element declaration.

see
#getNextElementDeclIndex
see
#getElementDecl

        return fElementDeclCount >= 0 ? 0 : -1;
    
public com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescriptiongetGrammarDescription()

        return fGrammarDescription;
    
public intgetNextAttributeDeclIndex(int attributeDeclIndex)
getNextAttributeDeclIndex

param
attributeDeclIndex
return
index of the next attribute of the attribute at attributeDeclIndex

        int chunk = attributeDeclIndex >> CHUNK_SHIFT;
        int index = attributeDeclIndex &  CHUNK_MASK;

        return fAttributeDeclNextAttributeDeclIndex[chunk][index];
    
public intgetNextElementDeclIndex(int elementDeclIndex)
Returns the next index of the element declaration following the specified element declaration.

param
elementDeclIndex The element declaration index.

        return elementDeclIndex < fElementDeclCount - 1 
             ? elementDeclIndex + 1 : -1;
    
public booleangetNotationDecl(int notationDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLNotationDecl notationDecl)
getNotationDecl

param
notationDeclIndex
param
notationDecl
return
return true of getNotationDecl can fill notationDecl with information about the notation at notationDeclIndex.

        if (notationDeclIndex < 0 || notationDeclIndex >= fNotationCount) {
            return false;
        }
        int chunk = notationDeclIndex >> CHUNK_SHIFT;
        int index = notationDeclIndex & CHUNK_MASK;

        notationDecl.setValues(fNotationName[chunk][index], 
                               fNotationPublicId[chunk][index],
                               fNotationSystemId[chunk][index],
                               fNotationBaseSystemId[chunk][index]);

        return true;

    
public intgetNotationDeclIndex(java.lang.String notationDeclName)
getNotationDeclIndex

param
notationDeclName
return
the index if found a notation with the name, otherwise -1.

        if (notationDeclName == null) {
            return -1;
        }

        return fNotationIndexMap.get(notationDeclName);
    
public com.sun.org.apache.xerces.internal.util.SymbolTablegetSymbolTable()
Returns the symbol table.

        return fSymbolTable;
    
public voidignoredCharacters(com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
Characters within an IGNORE conditional section.

param
text The ignored text.
param
augs Additional information that may include infoset augmentations.

protected voidinitializeContentModelStack()
Initialize content model stack.


        if (fOpStack == null) {
            fOpStack = new short[8];
            fNodeIndexStack = new int[8];
            fPrevNodeIndexStack = new int[8];
        } else if (fDepth == fOpStack.length) {
            short[] newStack = new short[fDepth * 2];
            System.arraycopy(fOpStack, 0, newStack, 0, fDepth);
            fOpStack = newStack;
            int[]   newIntStack = new int[fDepth * 2];
            System.arraycopy(fNodeIndexStack, 0, newIntStack, 0, fDepth);
            fNodeIndexStack = newIntStack;
            newIntStack = new int[fDepth * 2];
            System.arraycopy(fPrevNodeIndexStack, 0, newIntStack, 0, fDepth);
            fPrevNodeIndexStack = newIntStack;
        }
        fOpStack[fDepth] = -1;
        fNodeIndexStack[fDepth] = -1;
        fPrevNodeIndexStack[fDepth] = -1;

    
public voidinternalEntityDecl(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.XMLString nonNormalizedText, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
An internal entity declaration.

param
name The name of the entity. Parameter entity names start with '%', whereas the name of a general entity is just the entity name.
param
text The value of the entity.
param
nonNormalizedText The non-normalized value of the entity. This value contains the same sequence of characters that was in the internal entity declaration, without any entity references expanded.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        int entityIndex = getEntityDeclIndex(name);
        if( entityIndex == -1){
            entityIndex = createEntityDecl();
            boolean isPE = name.startsWith("%");
            boolean inExternal = fReadingExternalDTD;
            XMLEntityDecl  entityDecl = new XMLEntityDecl();
            entityDecl.setValues(name,null,null, null, null,
                                 text.toString(), isPE, inExternal);

            setEntityDecl(entityIndex, entityDecl);
        }

    
public booleanisCDATAAttribute(com.sun.org.apache.xerces.internal.xni.QName elName, com.sun.org.apache.xerces.internal.xni.QName atName)
Returns whether the given attribute is of type CDATA or not

param
elName The element name.
param
atName The attribute name.
return
true if the attribute is of type CDATA

        int elDeclIdx = getElementDeclIndex(elName);
        int atDeclIdx = getAttributeDeclIndex(elDeclIdx, atName.rawname);
        if (getAttributeDecl(elDeclIdx, fAttributeDecl)
            && fAttributeDecl.simpleType.type != XMLSimpleType.TYPE_CDATA){
            return false;
        }
        return true;
    
public booleanisEntityDeclared(java.lang.String name)

        return (getEntityDeclIndex(name)!=-1)?true:false;
    
public booleanisEntityUnparsed(java.lang.String name)

        int entityIndex = getEntityDeclIndex(name);
        if (entityIndex >-1) {
            int chunk = entityIndex >> CHUNK_SHIFT;
            int index = entityIndex & CHUNK_MASK;
            //for unparsed entity notation!=null
            return (fEntityNotation[chunk][index]!=null)?true:false;
        }
        return false; 
    
booleanisImmutable()

        return fIsImmutable;
    
public booleanisNamespaceAware()
Returns true if this grammar is namespace aware.

        return false;
    
public voidnotationDecl(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A notation declaration

param
name The name of the notation.
param
identifier An object containing all location information pertinent to this notation.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        XMLNotationDecl  notationDecl = new XMLNotationDecl();
        notationDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(),
                identifier.getBaseSystemId());
        int notationIndex = getNotationDeclIndex(name);
        if (notationIndex == -1) {
            notationIndex = createNotationDecl();
            setNotationDecl(notationIndex, notationDecl);
        }

    
public voidoccurrence(short occurrence, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The occurrence count for a child in a children content model or for the mixed content model group.

param
occurrence The occurrence count for the last element or group.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler#OCCURS_ZERO_OR_ONE
see
com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler#OCCURS_ZERO_OR_MORE
see
com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler#OCCURS_ONE_OR_MORE


        if (!fMixed) {
            if (occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE ) {
                fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[fDepth], -1);
            } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE ) {
                fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[fDepth], -1 );
            } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE) {
                fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[fDepth], -1 );
            }
        }

    
public voidpcdata(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The appearance of "#PCDATA" within a group signifying a mixed content model. This method will be the first called following the content model's startGroup().

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
#startGroup

        fMixed = true;
    
private voidprintAttribute(int attributeDeclIndex)


        XMLAttributeDecl attributeDecl = new XMLAttributeDecl();
        if (getAttributeDecl(attributeDeclIndex, attributeDecl)) {
            System.out.print(" { ");
            System.out.print(attributeDecl.name.localpart);
            System.out.print(" }");
        }

    
public voidprintAttributes(int elementDeclIndex)

        int attributeDeclIndex = getFirstAttributeDeclIndex(elementDeclIndex);
        System.out.print(elementDeclIndex);
        System.out.print(" [");
        while (attributeDeclIndex != -1) {
            System.out.print(' ");
            System.out.print(attributeDeclIndex);
            printAttribute(attributeDeclIndex);
            attributeDeclIndex = getNextAttributeDeclIndex(attributeDeclIndex);
            if (attributeDeclIndex != -1) {
                System.out.print(",");
            }
        }
        System.out.println(" ]");
    
public voidprintElements()

        int elementDeclIndex = 0;
        XMLElementDecl elementDecl = new XMLElementDecl();
        while (getElementDecl(elementDeclIndex++, elementDecl)) {

            System.out.println("element decl: "+elementDecl.name+
                               ", "+ elementDecl.name.rawname  );

            //                   ", "+ elementDecl.contentModelValidator.toString());
        }
    
public voidprocessingInstruction(java.lang.String target, com.sun.org.apache.xerces.internal.xni.XMLString data, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A processing instruction. Processing instructions consist of a target name and, optionally, text data. The data is only meaningful to the application.

Typically, a processing instruction's data will contain a series of pseudo-attributes. These pseudo-attributes follow the form of element attributes but are not parsed or presented to the application as anything other than text. The application is responsible for parsing the data.

param
target The target.
param
data The data or null if none specified.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

protected voidputElementNameMapping(com.sun.org.apache.xerces.internal.xni.QName name, int scope, int elementDeclIndex)

   
private static byte[][]resize(byte[][] array, int newsize)

        byte newarray[][] = new byte[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static short[][]resize(short[][] array, int newsize)

        short newarray[][] = new short[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static int[][]resize(int[][] array, int newsize)

        int newarray[][] = new int[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator[][]resize(com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator[][] array, int newsize)

        DatatypeValidator newarray[][] = new DatatypeValidator[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator[][]resize(com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator[][] array, int newsize)

        ContentModelValidator newarray[][] = new ContentModelValidator[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static java.lang.Object[][]resize(java.lang.Object[][] array, int newsize)

        Object newarray[][] = new Object[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static com.sun.org.apache.xerces.internal.xni.QName[][]resize(com.sun.org.apache.xerces.internal.xni.QName[][] array, int newsize)

        QName newarray[][] = new QName[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static java.lang.String[][]resize(java.lang.String[][] array, int newsize)

        String newarray[][] = new String[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static java.lang.String[][][]resize(java.lang.String[][][] array, int newsize)

        String newarray[][][] = new String[newsize] [][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
public voidseparator(short separator, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The separator between choices or sequences of a mixed or children content model.

param
separator The type of children separator.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler#SEPARATOR_CHOICE
see
com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler#SEPARATOR_SEQUENCE


        if (!fMixed) {
            if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_SEQ && separator == XMLDTDContentModelHandler.SEPARATOR_CHOICE ) {
                if (fPrevNodeIndexStack[fDepth] != -1) {
                    fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
                }
                fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth];
                fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_CHOICE;
            } else if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_CHOICE && separator == XMLDTDContentModelHandler.SEPARATOR_SEQUENCE) {
                if (fPrevNodeIndexStack[fDepth] != -1) {
                    fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
                }
                fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth];
                fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_SEQ;
            }
        }

    
protected voidsetAttributeDecl(int elementDeclIndex, int attributeDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLAttributeDecl attributeDecl)

      int attrChunk = attributeDeclIndex >> CHUNK_SHIFT;
      int attrIndex = attributeDeclIndex &  CHUNK_MASK; 
      fAttributeDeclName[attrChunk][attrIndex].setValues(attributeDecl.name);
      fAttributeDeclType[attrChunk][attrIndex]  =  attributeDecl.simpleType.type;

      if (attributeDecl.simpleType.list) {
         fAttributeDeclType[attrChunk][attrIndex] |= LIST_FLAG;
      }
      fAttributeDeclEnumeration[attrChunk][attrIndex]  =  attributeDecl.simpleType.enumeration;
      fAttributeDeclDefaultType[attrChunk][attrIndex]  =  attributeDecl.simpleType.defaultType;
      fAttributeDeclDatatypeValidator[attrChunk][attrIndex] =  attributeDecl.simpleType.datatypeValidator;

      fAttributeDeclDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.defaultValue;
      fAttributeDeclNonNormalizedDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.nonNormalizedDefaultValue;

      int elemChunk     = elementDeclIndex >> CHUNK_SHIFT;
      int elemIndex     = elementDeclIndex &  CHUNK_MASK;
      int index         = fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex];
      while (index != -1) {
         if (index == attributeDeclIndex) {
            break;
         }
         attrChunk = index >> CHUNK_SHIFT;
         attrIndex = index & CHUNK_MASK;
         index = fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex];
      }
      if (index == -1) {
         if (fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] == -1) {
            fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex;
         } else {
            index = fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex];
            attrChunk = index >> CHUNK_SHIFT;
            attrIndex = index & CHUNK_MASK;
            fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex] = attributeDeclIndex;
         }
         fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex;
      }
   
protected voidsetContentSpec(int contentSpecIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec contentSpec)

      int   chunk = contentSpecIndex >> CHUNK_SHIFT;
      int   index = contentSpecIndex & CHUNK_MASK;

      fContentSpecType[chunk][index]       = contentSpec.type;
      fContentSpecValue[chunk][index]      = contentSpec.value;
      fContentSpecOtherValue[chunk][index] = contentSpec.otherValue;
   
protected voidsetContentSpecIndex(int elementDeclIndex, int contentSpecIndex)


      if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
         return;
      }

      int chunk = elementDeclIndex >> CHUNK_SHIFT;
      int index = elementDeclIndex &  CHUNK_MASK;

      fElementDeclContentSpecIndex[chunk][index] = contentSpecIndex;
   
public voidsetDTDContentModelSource(com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSource source)

        fDTDContentModelSource = source;
    
public voidsetDTDSource(com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource source)

        fDTDSource = source;
    
protected voidsetElementDecl(int elementDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl elementDecl)

      if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
         return;
      }
      int     chunk       = elementDeclIndex >> CHUNK_SHIFT;
      int     index       = elementDeclIndex &  CHUNK_MASK;

      int     scope       = elementDecl.scope;


      fElementDeclName[chunk][index].setValues(elementDecl.name);
      fElementDeclType[chunk][index]                  = elementDecl.type; 

      fElementDeclContentModelValidator[chunk][index] = elementDecl.contentModelValidator;
         

      if (elementDecl.simpleType.list  == true ) {
         fElementDeclType[chunk][index] |= LIST_FLAG;
      }

      fElementIndexMap.put(elementDecl.name.rawname, elementDeclIndex);
   
protected voidsetEntityDecl(int entityDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLEntityDecl entityDecl)

       int chunk = entityDeclIndex >> CHUNK_SHIFT;
       int index = entityDeclIndex & CHUNK_MASK;

       fEntityName[chunk][index] = entityDecl.name;
       fEntityValue[chunk][index] = entityDecl.value;
       fEntityPublicId[chunk][index] = entityDecl.publicId;
       fEntitySystemId[chunk][index] = entityDecl.systemId;
       fEntityBaseSystemId[chunk][index] = entityDecl.baseSystemId;
       fEntityNotation[chunk][index] = entityDecl.notation;
       fEntityIsPE[chunk][index] = entityDecl.isPE ? (byte)1 : (byte)0;
       fEntityInExternal[chunk][index] = entityDecl.inExternal ? (byte)1 : (byte)0;

       fEntityIndexMap.put(entityDecl.name, entityDeclIndex);
   
protected voidsetFirstAttributeDeclIndex(int elementDeclIndex, int newFirstAttrIndex)


      if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
         return;
      }

      int chunk = elementDeclIndex >> CHUNK_SHIFT;
      int index = elementDeclIndex &  CHUNK_MASK;

      fElementDeclFirstAttributeDeclIndex[chunk][index] = newFirstAttrIndex;
   
protected voidsetNotationDecl(int notationDeclIndex, com.sun.org.apache.xerces.internal.impl.dtd.XMLNotationDecl notationDecl)

       int chunk = notationDeclIndex >> CHUNK_SHIFT;
       int index = notationDeclIndex & CHUNK_MASK;

       fNotationName[chunk][index] = notationDecl.name;
       fNotationPublicId[chunk][index] = notationDecl.publicId;
       fNotationSystemId[chunk][index] = notationDecl.systemId;
       fNotationBaseSystemId[chunk][index] = notationDecl.baseSystemId;

       fNotationIndexMap.put(notationDecl.name, notationDeclIndex);
   
public voidstartAttlist(java.lang.String elementName, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of an attribute list.

param
elementName The name of the element that this attribute list is associated with.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

public voidstartConditional(short type, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of a conditional section.

param
type The type of the conditional section. This value will either be CONDITIONAL_INCLUDE or CONDITIONAL_IGNORE.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
XMLDTDHandler#CONDITIONAL_INCLUDE
see
XMLDTDHandler#CONDITIONAL_IGNORE

public voidstartContentModel(java.lang.String elementName, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of a content model. Depending on the type of the content model, specific methods may be called between the call to the startContentModel method and the call to the endContentModel method.

param
elementName The name of the element.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        XMLElementDecl elementDecl = (XMLElementDecl) this.fElementDeclTab.get( elementName);
        if ( elementDecl != null ) {
            fElementDecl = elementDecl;
        }
        fDepth = 0;
        initializeContentModelStack();

    
public voidstartDTD(com.sun.org.apache.xerces.internal.xni.XMLLocator locator, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of the DTD.

param
locator The document locator, or null if the document location cannot be reported during the parsing of the document DTD. However, it is strongly recommended that a locator be supplied that can at least report the base system identifier of the DTD.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

        //Initialize stack
        fOpStack = null;
        fNodeIndexStack = null;
        fPrevNodeIndexStack = null;
    
public voidstartExternalSubset(com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of the DTD external subset.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

        fReadingExternalDTD = true;
    
public voidstartGroup(com.sun.org.apache.xerces.internal.xni.Augmentations augs)
A start of either a mixed or children content model. A mixed content model will immediately be followed by a call to the pcdata() method. A children content model will contain additional groups and/or elements.

param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.
see
#any
see
#empty

        fDepth++;
        initializeContentModelStack();
        fMixed = false;
    
public voidstartParameterEntity(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, java.lang.String encoding, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
This method notifies of the start of an entity. The DTD has the pseudo-name of "[dtd]" and parameter entity names start with '%'.

Note: Since the DTD is an entity, the handler will be notified of the start of the DTD entity by calling the startParameterEntity method with the entity name "[dtd]" before calling the startDTD method.

param
name The name of the parameter entity.
param
identifier The resource identifier.
param
encoding The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal parameter entities).
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        // keep track of this entity before fEntityDepth is increased
        if (fPEDepth == fPEntityStack.length) {
            boolean[] entityarray = new boolean[fPEntityStack.length * 2];
            System.arraycopy(fPEntityStack, 0, entityarray, 0, fPEntityStack.length);
            fPEntityStack = entityarray;
        }
        fPEntityStack[fPEDepth] = fReadingExternalDTD;
        fPEDepth++;

    
public voidtextDecl(java.lang.String version, java.lang.String encoding, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
Notifies of the presence of a TextDecl line in an entity. If present, this method will be called immediately following the startEntity call.

Note: This method is only called for external parameter entities referenced in the DTD.

param
version The XML version, or null if not specified.
param
encoding The IANA encoding name of the entity.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.

public voidunparsedEntityDecl(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, java.lang.String notation, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
An unparsed entity declaration.

param
name The name of the entity.
param
identifier An object containing all location information pertinent to this entity.
param
notation The name of the notation.
param
augs Additional information that may include infoset augmentations.
throws
XNIException Thrown by handler to signal an error.


        XMLEntityDecl  entityDecl = new XMLEntityDecl();
        boolean isPE = name.startsWith("%");
        boolean inExternal = fReadingExternalDTD;

        entityDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(),
                            identifier.getBaseSystemId(), notation,
                            null, isPE, inExternal);
        int entityIndex = getEntityDeclIndex(name);
        if (entityIndex == -1) {
            entityIndex = createEntityDecl();
            setEntityDecl(entityIndex, entityDecl);
        }