org.apache.xerces.impl.dtd
Class AbstractDTDGrammar

java.lang.Object
  |
  +--org.apache.xerces.impl.dtd.AbstractDTDGrammar
All Implemented Interfaces:
EntityState, org.apache.xerces.xni.grammars.Grammar
Direct Known Subclasses:
DTDGrammar

public abstract class AbstractDTDGrammar
extends java.lang.Object
implements EntityState, org.apache.xerces.xni.grammars.Grammar

A generic grammar for use in validating XML documents. The Grammar object stores the validation information in a compiled form. Specific subclasses extend this class and "populate" the grammar by compiling the specific syntax (DTD, Schema, etc) into the data structures used by this object.

Note: The AbstractDTDGrammar object is not useful as a generic grammar access or query object. In other words, you cannot round-trip specific grammar syntaxes with the compiled grammar information in the AbstractDTDGrammar object. You can create equivalent validation rules in your choice of grammar syntax but there is no guarantee that the input and output will be the same. Renamed from Grammar to AbstractDTDGrammar by neilg, 01/17/02, to reflect the fact that this is anything but a general-purpose grammar. REVISIT : shouldn't this class and DTDGrammar be combined?

Version:
$Id: AbstractDTDGrammar.java,v 1.6 2002/01/29 01:15:10 lehors Exp $
Author:
Jeffrey Rodriguez, IBM, Eric Ye, IBM, Andy Clark, IBM

Inner Class Summary
protected static class AbstractDTDGrammar.TupleHashtable
          A simple Hashtable implementation that takes a tuple (int, String, String) as the key and a int as value.
 
Field Summary
protected  XMLAttributeDecl fAttributeDecl
          Temporary Attribute decl.
static int TOP_LEVEL_SCOPE
          Top level scope (-1).
 
Fields inherited from interface org.apache.xerces.xni.grammars.Grammar
XML_DTD, XML_SCHEMA
 
Constructor Summary
protected AbstractDTDGrammar(SymbolTable symbolTable)
          Default constructor.
 
Method Summary
protected  int createAttributeDecl()
           
protected  int createContentSpec()
           
protected  int createElementDecl()
           
protected  int createEntityDecl()
           
protected  int createNotationDecl()
           
 boolean getAttributeDecl(int attributeDeclIndex, XMLAttributeDecl attributeDecl)
          getAttributeDecl
 int getAttributeDeclIndex(int elementDeclIndex, java.lang.String attributeDeclName)
          getAttributeDeclIndex
 boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec)
          getContentSpec
 java.lang.String getContentSpecAsString(int elementDeclIndex)
          getContentSpecAsString
protected  ContentModelValidator getElementContentModelValidator(int elementDeclIndex)
          getElementContentModelValidator
 boolean getElementDecl(int elementDeclIndex, XMLElementDecl elementDecl)
          getElementDecl
 int getElementDeclIndex(org.apache.xerces.xni.QName elementDeclQName, int scope)
          getElementDeclIndex
 int getElementDeclIndex(java.lang.String elementDeclName, int scope)
          getElementDeclIndex
 boolean getEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl)
          getEntityDecl
 int getEntityDeclIndex(java.lang.String entityDeclName)
          getEntityDeclIndex
 int getFirstAttributeDeclIndex(int elementDeclIndex)
          getFirstAttributeDeclIndex
 int getFirstElementDeclIndex()
          Returns the index of the first element declaration.
 int getFirstEntityDeclIndex()
          getFirstEntityDeclIndex
 int getFirstNotationDeclIndex()
          getFirstNotationDeclIndex
 java.lang.String getGrammarType()
           
 int getNextAttributeDeclIndex(int attributeDeclIndex)
          getNextAttributeDeclIndex
 int getNextElementDeclIndex(int elementDeclIndex)
          Returns the next index of the element declaration following the specified element declaration.
 int getNextEntityDeclIndex(int elementDeclIndex)
          getNextEntityDeclIndex
 int getNextNotationDeclIndex(int elementDeclIndex)
          getNextNotationDeclIndex
 boolean getNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl)
          getNotationDecl
 int getNotationDeclIndex(java.lang.String notationDeclName)
          getNotationDeclIndex
 SymbolTable getSymbolTable()
          Returns the symbol table.
 java.lang.String getTargetNamespace()
          Returns this grammar's target namespace.
 boolean isCDATAAttribute(org.apache.xerces.xni.QName elName, org.apache.xerces.xni.QName atName)
          Returns whether the given attribute is of type CDATA or not
protected  boolean isDTD()
           
 boolean isEntityDeclared(java.lang.String name)
          Query method to check if entity with this name was declared.
 boolean isEntityUnparsed(java.lang.String name)
          Query method to check if entity is unparsed.
abstract  boolean isNamespaceAware()
          Returns true if this grammar is namespace aware.
 void printAttributes(int elementDeclIndex)
           
 void printElements()
           
protected  void putElementNameMapping(org.apache.xerces.xni.QName name, int scope, int elementDeclIndex)
           
protected  void setAttributeDecl(int elementDeclIndex, int attributeDeclIndex, XMLAttributeDecl attributeDecl)
           
protected  void setContentSpec(int contentSpecIndex, XMLContentSpec contentSpec)
           
protected  void setContentSpecIndex(int elementDeclIndex, int contentSpecIndex)
           
protected  void setElementDecl(int elementDeclIndex, XMLElementDecl elementDecl)
           
protected  void setEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl)
           
protected  void setFirstAttributeDeclIndex(int elementDeclIndex, int newFirstAttrIndex)
           
protected  void setNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl)
           
protected  void setTargetNamespace(java.lang.String targetNamespace)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEVEL_SCOPE

public static final int TOP_LEVEL_SCOPE
Top level scope (-1).

fAttributeDecl

protected XMLAttributeDecl fAttributeDecl
Temporary Attribute decl.
Constructor Detail

AbstractDTDGrammar

protected AbstractDTDGrammar(SymbolTable symbolTable)
Default constructor.
Method Detail

getGrammarType

public java.lang.String getGrammarType()
Specified by:
getGrammarType in interface org.apache.xerces.xni.grammars.Grammar

isNamespaceAware

public abstract boolean isNamespaceAware()
Returns true if this grammar is namespace aware.

getSymbolTable

public SymbolTable getSymbolTable()
Returns the symbol table.

getTargetNamespace

public java.lang.String getTargetNamespace()
Returns this grammar's target namespace.

getFirstElementDeclIndex

public int getFirstElementDeclIndex()
Returns the index of the first element declaration. This index is then used to query more information about the element declaration.
See Also:
getNextElementDeclIndex(int), getElementDecl(int, org.apache.xerces.impl.dtd.XMLElementDecl)

getNextElementDeclIndex

public int getNextElementDeclIndex(int elementDeclIndex)
Returns the next index of the element declaration following the specified element declaration.
Parameters:
elementDeclIndex - The element declaration index.

getElementDeclIndex

public int getElementDeclIndex(java.lang.String elementDeclName,
                               int scope)
getElementDeclIndex
Parameters:
elementDeclName -  
scope -  
Returns:
index of the elementDeclName in scope

getElementDeclIndex

public int getElementDeclIndex(org.apache.xerces.xni.QName elementDeclQName,
                               int scope)
getElementDeclIndex
Parameters:
elementDeclQName -  
scope -  
Returns:
index of elementDeclQName in scope

getElementDecl

public boolean getElementDecl(int elementDeclIndex,
                              XMLElementDecl elementDecl)
getElementDecl
Parameters:
elementDeclIndex -  
elementDecl - The values of this structure are set by this call.
Returns:
True if find the element, False otherwise.

getFirstAttributeDeclIndex

public int getFirstAttributeDeclIndex(int elementDeclIndex)
getFirstAttributeDeclIndex
Parameters:
elementDeclIndex -  
Returns:
index of the first attribute for element declaration elementDeclIndex

getNextAttributeDeclIndex

public int getNextAttributeDeclIndex(int attributeDeclIndex)
getNextAttributeDeclIndex
Parameters:
attributeDeclIndex -  
Returns:
index of the next attribute of the attribute at attributeDeclIndex

getAttributeDeclIndex

public int getAttributeDeclIndex(int elementDeclIndex,
                                 java.lang.String attributeDeclName)
getAttributeDeclIndex
Parameters:
elementDeclIndex -  
attributeDeclName -  
Returns:
index of the attribue named attributeDeclName for the element with index elementDeclIndex

getAttributeDecl

public boolean getAttributeDecl(int attributeDeclIndex,
                                XMLAttributeDecl attributeDecl)
getAttributeDecl
Parameters:
attributeDeclIndex -  
attributeDecl - The values of this structure are set by this call.
Returns:
true if getAttributeDecl was able to fill in the value of attributeDecl

isCDATAAttribute

public boolean isCDATAAttribute(org.apache.xerces.xni.QName elName,
                                org.apache.xerces.xni.QName atName)
Returns whether the given attribute is of type CDATA or not
Parameters:
elName - The element name.
atName - The attribute name.
Returns:
true if the attribute is of type CDATA

getFirstEntityDeclIndex

public int getFirstEntityDeclIndex()
getFirstEntityDeclIndex
Returns:
index of the first EntityDecl

getNextEntityDeclIndex

public int getNextEntityDeclIndex(int elementDeclIndex)
getNextEntityDeclIndex
Parameters:
elementDeclIndex -  
Returns:
index of the next EntityDecl

getEntityDeclIndex

public int getEntityDeclIndex(java.lang.String entityDeclName)
getEntityDeclIndex
Parameters:
entityDeclName -  
Returns:
the index of the EntityDecl

getEntityDecl

public boolean getEntityDecl(int entityDeclIndex,
                             XMLEntityDecl entityDecl)
getEntityDecl
Parameters:
entityDeclIndex -  
entityDecl -  
Returns:
true if getEntityDecl was able to fill entityDecl with the contents of the entity with index entityDeclIndex

getFirstNotationDeclIndex

public int getFirstNotationDeclIndex()
getFirstNotationDeclIndex
Returns:
the index of the first notation declaration in the grammar

getNextNotationDeclIndex

public int getNextNotationDeclIndex(int elementDeclIndex)
getNextNotationDeclIndex
Parameters:
elementDeclIndex -  
Returns:
index of the next notation declaration in the grammar

getNotationDeclIndex

public int getNotationDeclIndex(java.lang.String notationDeclName)
getNotationDeclIndex
Parameters:
notationDeclName -  
Returns:
the index if found a notation with the name, otherwise -1.

getNotationDecl

public boolean getNotationDecl(int notationDeclIndex,
                               XMLNotationDecl notationDecl)
getNotationDecl
Parameters:
notationDeclIndex -  
notationDecl -  
Returns:
return true of getNotationDecl can fill notationDecl with information about the notation at notationDeclIndex.

getContentSpec

public boolean getContentSpec(int contentSpecIndex,
                              XMLContentSpec contentSpec)
getContentSpec
Parameters:
contentSpecIndex -  
contentSpec -  
Returns:
true if find the requested contentSpec node, false otherwise

getContentSpecAsString

public java.lang.String getContentSpecAsString(int elementDeclIndex)
getContentSpecAsString
Parameters:
elementDeclIndex -  

printElements

public void printElements()

printAttributes

public void printAttributes(int elementDeclIndex)

getElementContentModelValidator

protected ContentModelValidator getElementContentModelValidator(int elementDeclIndex)
getElementContentModelValidator
Parameters:
elementDeclIndex -  
Returns:
its ContentModelValidator if any.

createElementDecl

protected int createElementDecl()

setElementDecl

protected void setElementDecl(int elementDeclIndex,
                              XMLElementDecl elementDecl)

putElementNameMapping

protected void putElementNameMapping(org.apache.xerces.xni.QName name,
                                     int scope,
                                     int elementDeclIndex)

setFirstAttributeDeclIndex

protected void setFirstAttributeDeclIndex(int elementDeclIndex,
                                          int newFirstAttrIndex)

setContentSpecIndex

protected void setContentSpecIndex(int elementDeclIndex,
                                   int contentSpecIndex)

createAttributeDecl

protected int createAttributeDecl()

setAttributeDecl

protected void setAttributeDecl(int elementDeclIndex,
                                int attributeDeclIndex,
                                XMLAttributeDecl attributeDecl)

createContentSpec

protected int createContentSpec()

setContentSpec

protected void setContentSpec(int contentSpecIndex,
                              XMLContentSpec contentSpec)

createEntityDecl

protected int createEntityDecl()

setEntityDecl

protected void setEntityDecl(int entityDeclIndex,
                             XMLEntityDecl entityDecl)

createNotationDecl

protected int createNotationDecl()

setNotationDecl

protected void setNotationDecl(int notationDeclIndex,
                               XMLNotationDecl notationDecl)

setTargetNamespace

protected void setTargetNamespace(java.lang.String targetNamespace)

isDTD

protected boolean isDTD()

isEntityDeclared

public boolean isEntityDeclared(java.lang.String name)
Description copied from interface: EntityState
Query method to check if entity with this name was declared.
Specified by:
isEntityDeclared in interface EntityState
Following copied from interface: org.apache.xerces.impl.validation.EntityState
Parameters:
name -  
Returns:
true if name is a declared entity

isEntityUnparsed

public boolean isEntityUnparsed(java.lang.String name)
Description copied from interface: EntityState
Query method to check if entity is unparsed.
Specified by:
isEntityUnparsed in interface EntityState
Following copied from interface: org.apache.xerces.impl.validation.EntityState
Parameters:
name -  
Returns:
true if name is an unparsed entity


Copyright © 1999-2002 Apache XML Project. All Rights Reserved.