FileDocCategorySizeDatePackage
BalancedDTDGrammar.javaAPI DocApache Xerces 3.0.111221Fri Sep 14 20:33:54 BST 2007org.apache.xerces.impl.dtd

BalancedDTDGrammar

public final class BalancedDTDGrammar extends DTDGrammar

A DTD grammar that produces balanced syntax trees.

xerces.internal
author
Michael Glavassevich, IBM
version
$Id: BalancedDTDGrammar.java 446755 2006-09-15 21:56:27Z mrglavas $

Fields Summary
private boolean
fMixed
Mixed.
private int
fDepth
Stack depth
private short[]
fOpStack
Children content model operation stack.
private int[]
fGroupIndexStack
Holder for choice/sequence/leaf groups at each depth.
private int[]
fGroupIndexStackSizes
Sizes of the allocated portions of each int[] in fGroupIndexStack.
Constructors Summary
public BalancedDTDGrammar(org.apache.xerces.util.SymbolTable symbolTable, XMLDTDDescription desc)
Default constructor.

    
    //
    // Constructors
    //

       
         
        super(symbolTable, desc);
    
Methods Summary
private intaddContentSpecNodes(int begin, int end)
Creates a subtree from the leaf nodes at the current depth.

        if (begin == end) {
            return fGroupIndexStack[fDepth][begin];
        }
        int middle = (begin + end) / 2;
        return addContentSpecNode(fOpStack[fDepth], 
                addContentSpecNodes(begin, middle), 
                addContentSpecNodes(middle + 1, end));
    
protected final voidaddContentSpecToElement(XMLElementDecl elementDecl)
Adds the content spec to the given element declaration.

        int contentSpec = fGroupIndexStackSizes[0] > 0 ? fGroupIndexStack[0][0] : -1;
        setContentSpecIndex(fCurrentElementIndex, contentSpec);
    
private voidaddToCurrentGroup(int contentSpec)
Add XMLContentSpec to the current group.

param
contentSpec handle to the XMLContentSpec to add to the current group

        int [] currentGroup = fGroupIndexStack[fDepth];
        int length = fGroupIndexStackSizes[fDepth]++;
        if (currentGroup == null) {
            currentGroup = new int[8];
            fGroupIndexStack[fDepth] = currentGroup;
        }
        else if (length == currentGroup.length) {
            int [] newGroup = new int[currentGroup.length * 2];
            System.arraycopy(currentGroup, 0, newGroup, 0, currentGroup.length);
            currentGroup = newGroup;
            fGroupIndexStack[fDepth] = currentGroup;
        }
        currentGroup[length] = contentSpec;
    
public final voidelement(java.lang.String elementName, org.apache.xerces.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.

        addToCurrentGroup(addUniqueLeafNode(elementName));
    
public final voidendDTD(org.apache.xerces.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.

        super.endDTD(augs);
        fOpStack = null;
        fGroupIndexStack = null;
        fGroupIndexStackSizes = null;
    
public final voidendGroup(org.apache.xerces.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.

        final int length = fGroupIndexStackSizes[fDepth];
        final int group = length > 0 ? addContentSpecNodes(0, length - 1) : addUniqueLeafNode(null);
        --fDepth;
        addToCurrentGroup(group);
    
private voidinitializeContentModelStacks()
Initialize the stacks which temporarily hold content models.

        if (fOpStack == null) {
            fOpStack = new short[8];
            fGroupIndexStack = new int [8][];
            fGroupIndexStackSizes = new int [8];
        }
        else if (fDepth == fOpStack.length) {
            short [] newOpStack = new short[fDepth * 2];
            System.arraycopy(fOpStack, 0, newOpStack, 0, fDepth);
            fOpStack = newOpStack;
            int [][] newGroupIndexStack = new int[fDepth * 2][];
            System.arraycopy(fGroupIndexStack, 0, newGroupIndexStack, 0, fDepth);
            fGroupIndexStack = newGroupIndexStack;
            int [] newGroupIndexStackLengths = new int[fDepth * 2];
            System.arraycopy(fGroupIndexStackSizes, 0, newGroupIndexStackLengths, 0, fDepth);
            fGroupIndexStackSizes = newGroupIndexStackLengths;
        }
        fOpStack[fDepth] = -1;
        fGroupIndexStackSizes[fDepth] = 0;
    
public final voidoccurrence(short occurrence, org.apache.xerces.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
org.apache.xerces.xni.XMLDTDContentModelHandler#OCCURS_ZERO_OR_ONE
see
org.apache.xerces.xni.XMLDTDContentModelHandler#OCCURS_ZERO_OR_MORE
see
org.apache.xerces.xni.XMLDTDContentModelHandler#OCCURS_ONE_OR_MORE

        if (!fMixed) {
            int currentIndex = fGroupIndexStackSizes[fDepth] - 1;
            if (occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE) {
                fGroupIndexStack[fDepth][currentIndex] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fGroupIndexStack[fDepth][currentIndex], -1);
            } 
            else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE) {
                fGroupIndexStack[fDepth][currentIndex] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fGroupIndexStack[fDepth][currentIndex], -1);
            } 
            else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE) {
                fGroupIndexStack[fDepth][currentIndex] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fGroupIndexStack[fDepth][currentIndex], -1);
            }
        }
    
public final voidpcdata(org.apache.xerces.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;
    
public final voidseparator(short separator, org.apache.xerces.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
org.apache.xerces.xni.XMLDTDContentModelHandler#SEPARATOR_CHOICE
see
org.apache.xerces.xni.XMLDTDContentModelHandler#SEPARATOR_SEQUENCE

        if (separator == XMLDTDContentModelHandler.SEPARATOR_CHOICE) {
            fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_CHOICE;
        }
        else if (separator == XMLDTDContentModelHandler.SEPARATOR_SEQUENCE) {
            fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_SEQ;
        }
    
public final voidstartContentModel(java.lang.String elementName, org.apache.xerces.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.

        fDepth = 0;
        initializeContentModelStacks();
        super.startContentModel(elementName, augs);
    
public final voidstartGroup(org.apache.xerces.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;
        initializeContentModelStacks();
        fMixed = false;