org.merlotxml.util.xml
Class GrammarComplexType

java.lang.Object
  extended byorg.merlotxml.util.xml.GrammarComplexType
Direct Known Subclasses:
DTDGrammarComplexTypeImpl, SchemaGrammarComplexTypeImpl

public abstract class GrammarComplexType
extends java.lang.Object

Provides access to the grammar for an element. This class is extended by xerces.DTDGrammarComplexTypeImpl and xerces.SchemaGrammarComplexTypeImpl.

Author:
Evert Hoff

Nested Class Summary
protected  class GrammarComplexType.ListComparator
          Sorts objects according to their positions in another list.
 
Field Summary
protected  java.util.Vector _attributes
          The possible attributes that are defined for this element.
protected  java.util.Hashtable _namedAttributes
          GrammarSimpleType objects hashed by name
protected  GrammarSimpleType _simpleContent
          The definition for the node value, or #PCDATA, of this element.
protected  int debugLevel
          Utility to minimise the output during debugging.
static long totalDurationIsEachAttributeValid
           
static long totalDurationIsLocationValid
           
static long totalDurationIsSimpleContentValid
           
 
Constructor Summary
GrammarComplexType()
           
 
Method Summary
protected  void debug(int level, java.lang.String msg)
          Utility for debugging.
 GrammarSimpleType getAttribute(java.lang.String name)
          Gets a named attribute.
 GrammarSimpleType[] getAttributes()
          Gets all the defined attributes.
abstract  GrammarComplexType getChild(java.lang.String name)
          Gets a locally defined element by name.
protected  java.lang.String[] getChildNodeNames(org.w3c.dom.Node el)
          Returns the node names of all the current children of the element.
protected  java.lang.String[] getChildNodeNamesWithoutText(org.w3c.dom.Node el)
          Returns the node names of all children of this node, except for the children that are #text, #comment, or pi_node nodes.
abstract  GrammarComplexType[] getChildren()
          Gets all the children defined within the scope of this parent.
abstract  java.lang.String getDocumentation()
          Gets the value of the value defined in the Schema.
 java.lang.String getFirstMissingChildName(org.w3c.dom.Element el)
           
protected  int getIndexWithoutTextNodes(org.w3c.dom.Node el, int index)
          Recalculates what a child position would have been if there weren't any text nodes.
 GrammarComplexType[] getInsertableElements(org.w3c.dom.Node node)
          Gets all the possible insertable elements that are valid somewhere between the current children of the node.
 GrammarComplexType[] getInsertableElements(org.w3c.dom.Node node, int index)
          Gets all the child complex types that may be inserted as children of the node at the given position.
 int getInsertPosition(org.w3c.dom.Node parent, java.lang.String childElementName)
          Gets the position where a child named childElementName may be inserted.
 boolean getIsComplete(org.w3c.dom.Element el)
           
 boolean getIsEachAttributeValid(org.w3c.dom.Element el)
          Checks the validity of the values of each of the attributes.
 boolean getIsLocationValid(org.w3c.dom.Element el)
          Checks whether this element is in an allowed place in the structure of the document.
abstract  boolean getIsNillable()
          Means whether an attribute xsi:nil='true' may be inserted into the XML file.
abstract  boolean getIsSimpleContentAllowed()
          Determines if the element may contain simple content (#PCDATA).
 boolean getIsSimpleContentValid(org.w3c.dom.Element el)
          Validates the value of the simple content of this element.
abstract  int getMaxOccurs()
          Gets the maximum number of instances of this type of element that are allowed.
abstract  int getMinOccurs()
          Gets the valid minimum number of instances of this type of element.
abstract  java.lang.String getName()
          Gets the name of this complex type.
protected  java.lang.String[] getNames(GrammarComplexType[] complexTypes)
          Convenience method to get an array of names from an array of complex types.
abstract  GrammarComplexType getParentComplexType(org.w3c.dom.Element el)
           
protected  int getPositionAmongPeers(org.w3c.dom.Node parent, org.w3c.dom.Node child)
          Gets the position of the child among its peers under the parent.
 GrammarSimpleType getSimpleContent()
          Gets the GrammarSimpleType that defines the simple content (#PCDATA) of this element.
abstract  boolean isEmptyType()
           
abstract  boolean isMixedType()
           
abstract  void resetValidation(org.w3c.dom.Element el)
           
 java.lang.String toString()
           
protected  java.lang.String toString(java.lang.String[] strings)
          Convenience method for debugging.
protected  java.lang.String toString(java.util.Vector strings)
          Convenience method for debugging.
abstract  int validate(org.w3c.dom.Element el)
          Validates the element in terms of its position in the structure of the document.
protected abstract  int validate(java.lang.String[] candidateNodeNames)
          Validates the candidate node names for their position in the structure.
protected  java.lang.String[] whatCanGoHere(java.lang.String[] currentChildElements, int insertPosition)
          The possible elements that could be inserted at this position, given the current children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_attributes

protected java.util.Vector _attributes
The possible attributes that are defined for this element. Contains GrammarSimpleType objects.


_namedAttributes

protected java.util.Hashtable _namedAttributes
GrammarSimpleType objects hashed by name


_simpleContent

protected GrammarSimpleType _simpleContent
The definition for the node value, or #PCDATA, of this element.


debugLevel

protected int debugLevel
Utility to minimise the output during debugging.


totalDurationIsEachAttributeValid

public static long totalDurationIsEachAttributeValid

totalDurationIsSimpleContentValid

public static long totalDurationIsSimpleContentValid

totalDurationIsLocationValid

public static long totalDurationIsLocationValid
Constructor Detail

GrammarComplexType

public GrammarComplexType()
Method Detail

getAttribute

public GrammarSimpleType getAttribute(java.lang.String name)
Gets a named attribute.

Parameters:
name - The name of the attribute.
Returns:
The attribute definition.

getAttributes

public GrammarSimpleType[] getAttributes()
Gets all the defined attributes.

Returns:
All attributes.

getChild

public abstract GrammarComplexType getChild(java.lang.String name)
Gets a locally defined element by name.

Parameters:
name - The name of the child element.
Returns:
The child.

getChildren

public abstract GrammarComplexType[] getChildren()
Gets all the children defined within the scope of this parent.

Returns:
The children.

getParentComplexType

public abstract GrammarComplexType getParentComplexType(org.w3c.dom.Element el)

getDocumentation

public abstract java.lang.String getDocumentation()
Gets the value of the value defined in the Schema. This is a useful place to store help documentation about each element.

Returns:
The documentation value

getInsertPosition

public int getInsertPosition(org.w3c.dom.Node parent,
                             java.lang.String childElementName)
Gets the position where a child named childElementName may be inserted.

Parameters:
parent - The parent to hold this child.
childElementName - The node name of the child.
Returns:
The first zero-based position where this child may be inserted.

getInsertableElements

public GrammarComplexType[] getInsertableElements(org.w3c.dom.Node node,
                                                  int index)
Gets all the child complex types that may be inserted as children of the node at the given position.

Parameters:
node - The parent node.
index - The zero-based position where a child node is to be inserted.
Returns:
The possible complex types from which one may be chosen.

getInsertableElements

public GrammarComplexType[] getInsertableElements(org.w3c.dom.Node node)
Gets all the possible insertable elements that are valid somewhere between the current children of the node.

Parameters:
node - The parent node.
Returns:
The possible elements, from which one may be chosen.

getIsEachAttributeValid

public boolean getIsEachAttributeValid(org.w3c.dom.Element el)
Checks the validity of the values of each of the attributes.

Parameters:
el - The element for which all attributes must be checked.
Returns:
False if any attribute is invalid.

getIsSimpleContentAllowed

public abstract boolean getIsSimpleContentAllowed()
Determines if the element may contain simple content (#PCDATA).

Returns:
The isSimpleContentAllowed value

getIsSimpleContentValid

public boolean getIsSimpleContentValid(org.w3c.dom.Element el)
Validates the value of the simple content of this element. In other words, the value of the #text node below this element is validated.

Parameters:
el - The element to be validated.
Returns:
The isSimpleContentValid value

getIsLocationValid

public boolean getIsLocationValid(org.w3c.dom.Element el)
Checks whether this element is in an allowed place in the structure of the document.

Parameters:
el - The element to be validated.
Returns:
The valid value

getIsComplete

public boolean getIsComplete(org.w3c.dom.Element el)

getFirstMissingChildName

public java.lang.String getFirstMissingChildName(org.w3c.dom.Element el)

resetValidation

public abstract void resetValidation(org.w3c.dom.Element el)

getIsNillable

public abstract boolean getIsNillable()
Means whether an attribute xsi:nil='true' may be inserted into the XML file.

For DTDs always returns false.

For Schemas, returns whether nillable has been set to true for this element.


getMaxOccurs

public abstract int getMaxOccurs()
Gets the maximum number of instances of this type of element that are allowed.

Returns:
The maxOccurs value, or -1 for infinite.

getMinOccurs

public abstract int getMinOccurs()
Gets the valid minimum number of instances of this type of element.

Returns:
The minOccurs value

getName

public abstract java.lang.String getName()
Gets the name of this complex type. Might be null if it is an anonymous complex type.

Returns:
The name value

getSimpleContent

public GrammarSimpleType getSimpleContent()
Gets the GrammarSimpleType that defines the simple content (#PCDATA) of this element.

Returns:
The simpleContent value

validate

public abstract int validate(org.w3c.dom.Element el)
Validates the element in terms of its position in the structure of the document.

Parameters:
el - The element to be validated for structure.
Returns:
The position of the first child that is not valid.

debug

protected void debug(int level,
                     java.lang.String msg)
Utility for debugging.

Parameters:
level - 0=no debugging, 1 little bit, 2 more, etc.
msg - The message to print.

getChildNodeNames

protected java.lang.String[] getChildNodeNames(org.w3c.dom.Node el)
Returns the node names of all the current children of the element.

Parameters:
el - Description of Parameter
Returns:
The childNodeNames value

getChildNodeNamesWithoutText

protected java.lang.String[] getChildNodeNamesWithoutText(org.w3c.dom.Node el)
Returns the node names of all children of this node, except for the children that are #text, #comment, or pi_node nodes.

Parameters:
el - The parent element.
Returns:
The childNodeNamesWithoutText value

getIndexWithoutTextNodes

protected int getIndexWithoutTextNodes(org.w3c.dom.Node el,
                                       int index)
Recalculates what a child position would have been if there weren't any text nodes.

Parameters:
el - The parent element.
index - The index of the child element.
Returns:
The indexWithoutTextNodes value

getNames

protected java.lang.String[] getNames(GrammarComplexType[] complexTypes)
Convenience method to get an array of names from an array of complex types.

Parameters:
complexTypes - Description of Parameter
Returns:
The names value

getPositionAmongPeers

protected int getPositionAmongPeers(org.w3c.dom.Node parent,
                                    org.w3c.dom.Node child)
Gets the position of the child among its peers under the parent.

Parameters:
parent - The parent node.
child - The child node.
Returns:
The position of this child.

toString

protected java.lang.String toString(java.lang.String[] strings)
Convenience method for debugging.

Parameters:
strings - Description of Parameter
Returns:
Description of the Returned Value

toString

protected java.lang.String toString(java.util.Vector strings)
Convenience method for debugging.

Parameters:
strings - Description of Parameter
Returns:
Description of the Returned Value

toString

public java.lang.String toString()

validate

protected abstract int validate(java.lang.String[] candidateNodeNames)
Validates the candidate node names for their position in the structure.

Parameters:
candidateNodeNames - Description of Parameter
Returns:
The position of the first child that is not valid.

whatCanGoHere

protected java.lang.String[] whatCanGoHere(java.lang.String[] currentChildElements,
                                           int insertPosition)
The possible elements that could be inserted at this position, given the current children.

Parameters:
currentChildElements - The current children node names.
insertPosition - The zero-based position where a new child is to be inserted.
Returns:
The possible element node names, of which one may be chosen.

isEmptyType

public abstract boolean isEmptyType()

isMixedType

public abstract boolean isMixedType()