Class HierarchicalDocumentReader

java.lang.Object
  |
  +--DocumentReader
        |
        +--HierarchicalDocumentReader

public class HierarchicalDocumentReader
extends DocumentReader

Wrapper Class

This class is a wrapper around a hierarchical HUppaal document, such that the grammar might be re-designed with minimal programming effort.

Version:
Vanilla-1 Tue Apr 3 16:11:51 2001
Author:
M. Oliver Möller

Field Summary
(package private) static boolean debug
          Spam out debuggin information, if debug is true
private static long fakeIDCounter
          AUX counter to create unique fake IDs
private static java.lang.String fakeIDName
          Name of Component IDs that are not present in the original document

used in wrapAroundInstHashTable.
static java.lang.String huppaalDTD
          Version of the hierarchical Huppaal grammar
private  org.w3c.dom.Element oldRoot
          original, hierarchical document-root
private static java.lang.String unambigousNameSeparator
          Separate Strings (names) for hashing
(package private) static boolean useLabelConstruct
          Determines whether translations uses the <label> construct for assignments, guards and synchronisations.
(package private) static boolean useLabelForInvariants
          Determines whether translations uses the <label> construct also for invariants.
private  java.util.Hashtable wrapAroundInstHashTable
          Hashing global element names to dummy component Elements
 
Fields inherited from class DocumentReader
hashOriginalIDsToElements, origDoc, sanityChecks
 
Constructor Summary
HierarchicalDocumentReader(org.w3c.dom.Document theDoc)
          Default Constructor
 
Method Summary
 void addGuardsAndAssignmentsOfConnectionInContext(org.w3c.dom.Element connection, java.util.Vector guards, java.util.Vector assignments, java.lang.Object contextOfIt)
          The TexualInstantiaion is handed over for context information (i.e.
private  void addIDAndElementToHashTable(java.lang.String ID, org.w3c.dom.Element el)
          Make hash table entries for Elements that are not accessible in the original document

Used to retrieve components with fake IDs.
 void collectGuardsAndAssignmentsOfTarget(org.w3c.dom.Element target, java.util.Vector guards, java.util.Vector assignments, java.lang.Object context)
          Traverses the entry-fork starting with this target (which is assumed to point at a component and an entry)
The guards and assignments present in the connections are collected textually (Vector of strings), without any assumption on the order.

NOTE:The result of this process possibly has to be adjusted to the current instantiation (i.e., names have to be mapped) The information for this can be extraced from the context, which is a list (stack?) of renamings.
 void createJoinsForGlobalExits(TextualInstantiation tinst, org.w3c.dom.Element globalEntry)
          Create the Joins for stopping global elements (direct children of root);

 java.lang.String docToString()
          Return the original document as string
 org.w3c.dom.NodeList getAllAliveGlobalInits()
          Return the list of global inits, that refer to a root element that is part of the system.
private  org.w3c.dom.NodeList getAllChildrenThatAreAssignments(org.w3c.dom.Element connection)
          Retrieve all child nodes that are assignments.
private  org.w3c.dom.NodeList getAllChildrenThatAreGuards(org.w3c.dom.Element connection)
          Retrieve all child nodes that are guards.
private  org.w3c.dom.NodeList getAllChildrenThatAreSynchronisation(org.w3c.dom.Element connection)
          Retrieve all child nodes that are synchronisations.
 java.util.Vector getAllExitsOfComponent(org.w3c.dom.Element component)
          Returns a Vector of exit Elements, that correspond to the exits of the template this component instantiates.
static java.util.Vector getAllExitsOfTemplate(org.w3c.dom.Element template)
          Returns a Vector of exit Elements, that correspond to the exits of this template.
static java.util.Vector getAllLocationsAndComponents(org.w3c.dom.Element template)
          Return a vector with all locations and components.
 org.w3c.dom.NodeList getAllTemplates()
          Return the (complete) list of defined hierarchical templates
private  org.w3c.dom.Element getConnectionOfEntry(org.w3c.dom.Element entry)
          Returns the (one) connection an entry points to
 java.util.Vector getConnectionsToExitOrExitpoint(org.w3c.dom.Element exitOrExitpoint)
          Returns s Vector of Elements, containing all the pointing-to connections.
 java.lang.String getDeclarationText()
          Retrieve the texutal declaration data from element tag, if present
 org.w3c.dom.NodeList getDirectChildNodes()
          All direct Children of root
 org.w3c.dom.NodeList getDirectChildNodesWithTag(java.lang.String tag)
          Some direct children of root
private  org.w3c.dom.Element getEntryATargetPointsTo(org.w3c.dom.Element target)
          Returns the (one) <entry&rt; element that a target points to
 org.w3c.dom.Element getForkElementOfEntry(org.w3c.dom.Element entry)
          Map <entry> or <entrypoint> to the (single) corresponding fork Element.
Throws exception, if used wrongly or in wrong context.
 java.lang.String getInstantiationText()
          Retrieve the texutal instantiation data from element tag, if present
 java.util.Vector getNamesOfAliveSystemParts()
          Browse the system definition to get the name of instantiations that are declared to be part of the top-level parallel composition.
 java.lang.String getSystemText()
          Retrieve the texutal system data from element tag, if present
 org.w3c.dom.Element getTargetElementOfEntry(org.w3c.dom.Element entry)
          Map <entry> or <entrypoint> to the (single) corresponding target Element.
Throws exception, if used wrongly or in wrong context.
 org.w3c.dom.NodeList getTargetsOfFork(org.w3c.dom.Element fork)
           
 org.w3c.dom.Element getTemplateWithName(java.lang.String name)
          Returns the Element in the original (hierarchical) document, that has the specified name.
Throws Exception, if not found.
 java.lang.String getTextualAssignmentOfTransitionIfPresent(org.w3c.dom.Element transition)
          Returns the text of a assignment, if present and not the empty string, otherwise, returns null.

Throws Exception, if not called on transition or connection.
 java.lang.String getTextualGuardOfTransitionIfPresent(org.w3c.dom.Element transition)
          Returns the text of a guard, if present and not the empty string, otherwise, returns null.

Throws Exception, if not called on transition or connection.
static org.w3c.dom.Element getTheChildAssignmentIfExists(org.w3c.dom.Element connection)
          Retrieve (if existent) the child that is assignment.

Return null, if it does not exist.

Throws exception, if more than two such children exist.
static org.w3c.dom.Element getTheChildGuardIfExists(org.w3c.dom.Element connection)
          Retrieve (if existent) the child that is guard.

Return null, if it does not exist.

Throws exception, if more than two such children exist.
static org.w3c.dom.Element getTheChildInvariantIfExists(org.w3c.dom.Element connection)
          Retrieve (if existent) the child that is invariant.

Return null, if it does not exist.

Throws exception, if more than two such children exist.
static org.w3c.dom.Element getTheChildSynchronisationIfExists(org.w3c.dom.Element connection)
          Retrieve (if existent) the child that is synchronisation.

Return null, if it does not exist.

Throws exception, if more than two such children exist.
static boolean hasDefaultExit(org.w3c.dom.Element template)
          Checks whether this template has a default exit.
 boolean isANDComponent(org.w3c.dom.Element component)
          Returns true, if the component is isantiation of an AND template.

Trows Exception, if called on a non-component
 boolean isANDTemplate(org.w3c.dom.Element template)
          Returns true, if the template is an AND element.

Trows Exception, if called on a non-template
static boolean isAssignmentElement(org.w3c.dom.Node n)
          Test, whether this is an assignment Element.

Depends on useLabelConstruct.
static boolean isComponent(org.w3c.dom.Element el)
          Test whether this element is a component.

Throws Exception, if the element is not a location or component.
static boolean isDefaultExitOrExitpoint(org.w3c.dom.Element exitOrExitpoint)
          Returns true, if the element is a default exit or an exitpoint.
Throws exception on type error.
static boolean isGuardElement(org.w3c.dom.Node n)
          Test, whether this is an guard Element.

Depends on useLabelConstruct.
 boolean isHistoryComponent(org.w3c.dom.Element component)
          Returns true, if the component is a history element.

Trows Exception, if called on a non-component
static boolean isHistoryEntry(org.w3c.dom.Element entry)
          Returns true, if the entry is a history element.

Trows Exception, if called on a non-entry
 boolean isHistoryTemplate(org.w3c.dom.Element template)
          Returns true, if the template is a history element.

Trows Exception, if called on a non-template
static boolean isInvariantElement(org.w3c.dom.Node n)
          Test, whether this is an invariant Element.

Depends on useLabelConstruct.
static boolean isNailElement(org.w3c.dom.Node n)
          Test, whether a node is an Element and a nail
static boolean isSourceElement(org.w3c.dom.Node n)
          Test, whether a node is an Element and a source
static boolean isSynchronisationElement(org.w3c.dom.Node n)
          Test, whether this is an synchronisation Element.

Depends on useLabelConstruct.
static boolean isTargetElement(org.w3c.dom.Node n)
          Test, whether a node is an Element and a target
static java.util.Vector splitCommaSeperatedString(java.lang.String s)
          Given a string containing a comma-speparated list, split it into a vector of Strings (without the commata).
Trims the strings (cuts away whitespaces).
 org.w3c.dom.Element wrapComponentAroundGlobalInstantiation(java.lang.String instName, java.lang.String templateName)
          Returns a (dummy) component Element, that points to a global instantiation.
Once constructed, these Elements are stored in a Hashtable, so the result on the same call will be unique.
 
Methods inherited from class DocumentReader
getAllChildrenWithLabel, getCdataOfElement, getElementByID, getElementID, getElementName, getFirstChildWithLabel, getFirstChildWithLabelIfExists, getTheChildWithLabel, getTheChildWithLabelIfExists, getXCoordinate, getYCoordinate, max, max, max3, max4, max5, memorizeIDsOfOriginalDocument, min
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

useLabelConstruct

static final boolean useLabelConstruct
Determines whether translations uses the <label> construct for assignments, guards and synchronisations. not.

From huppaal-0.4 on, this should be true.

useLabelForInvariants

static final boolean useLabelForInvariants
Determines whether translations uses the <label> construct also for invariants.
From huppaal-0.5 on, this should be true.

huppaalDTD

public static final java.lang.String huppaalDTD
Version of the hierarchical Huppaal grammar

oldRoot

private org.w3c.dom.Element oldRoot
original, hierarchical document-root

wrapAroundInstHashTable

private java.util.Hashtable wrapAroundInstHashTable
Hashing global element names to dummy component Elements

unambigousNameSeparator

private static final java.lang.String unambigousNameSeparator
Separate Strings (names) for hashing

fakeIDName

private static final java.lang.String fakeIDName
Name of Component IDs that are not present in the original document

used in wrapAroundInstHashTable.

fakeIDCounter

private static long fakeIDCounter
AUX counter to create unique fake IDs

debug

static boolean debug
Spam out debuggin information, if debug is true
Constructor Detail

HierarchicalDocumentReader

public HierarchicalDocumentReader(org.w3c.dom.Document theDoc)
Default Constructor
Method Detail

getDirectChildNodes

public org.w3c.dom.NodeList getDirectChildNodes()
All direct Children of root

getDirectChildNodesWithTag

public org.w3c.dom.NodeList getDirectChildNodesWithTag(java.lang.String tag)
Some direct children of root

getTemplateWithName

public org.w3c.dom.Element getTemplateWithName(java.lang.String name)
                                        throws java.lang.Exception
Returns the Element in the original (hierarchical) document, that has the specified name.
Throws Exception, if not found.

getAllTemplates

public org.w3c.dom.NodeList getAllTemplates()
Return the (complete) list of defined hierarchical templates

getAllAliveGlobalInits

public org.w3c.dom.NodeList getAllAliveGlobalInits()
                                            throws java.lang.Exception
Return the list of global inits, that refer to a root element that is part of the system.

getSystemText

public java.lang.String getSystemText()
                               throws java.lang.Exception
Retrieve the texutal system data from element tag, if present

getInstantiationText

public java.lang.String getInstantiationText()
                                      throws java.lang.Exception
Retrieve the texutal instantiation data from element tag, if present

getDeclarationText

public java.lang.String getDeclarationText()
                                    throws java.lang.Exception
Retrieve the texutal declaration data from element tag, if present

getAllExitsOfComponent

public java.util.Vector getAllExitsOfComponent(org.w3c.dom.Element component)
                                        throws java.lang.Exception
Returns a Vector of exit Elements, that correspond to the exits of the template this component instantiates.

getAllExitsOfTemplate

public static java.util.Vector getAllExitsOfTemplate(org.w3c.dom.Element template)
                                              throws java.lang.Exception
Returns a Vector of exit Elements, that correspond to the exits of this template.

getAllLocationsAndComponents

public static java.util.Vector getAllLocationsAndComponents(org.w3c.dom.Element template)
                                                     throws java.lang.Exception
Return a vector with all locations and components.

isComponent

public static boolean isComponent(org.w3c.dom.Element el)
                           throws java.lang.Exception
Test whether this element is a component.

Throws Exception, if the element is not a location or component.

isDefaultExitOrExitpoint

public static boolean isDefaultExitOrExitpoint(org.w3c.dom.Element exitOrExitpoint)
                                        throws java.lang.Exception
Returns true, if the element is a default exit or an exitpoint.
Throws exception on type error.

hasDefaultExit

public static boolean hasDefaultExit(org.w3c.dom.Element template)
                              throws java.lang.Exception
Checks whether this template has a default exit.

isHistoryTemplate

public boolean isHistoryTemplate(org.w3c.dom.Element template)
                          throws java.lang.Exception
Returns true, if the template is a history element.

Trows Exception, if called on a non-template

isANDTemplate

public boolean isANDTemplate(org.w3c.dom.Element template)
                      throws java.lang.Exception
Returns true, if the template is an AND element.

Trows Exception, if called on a non-template

isHistoryComponent

public boolean isHistoryComponent(org.w3c.dom.Element component)
                           throws java.lang.Exception
Returns true, if the component is a history element.

Trows Exception, if called on a non-component

isANDComponent

public boolean isANDComponent(org.w3c.dom.Element component)
                       throws java.lang.Exception
Returns true, if the component is isantiation of an AND template.

Trows Exception, if called on a non-component

isHistoryEntry

public static boolean isHistoryEntry(org.w3c.dom.Element entry)
                              throws java.lang.Exception
Returns true, if the entry is a history element.

Trows Exception, if called on a non-entry

isTargetElement

public static boolean isTargetElement(org.w3c.dom.Node n)
Test, whether a node is an Element and a target

isSourceElement

public static boolean isSourceElement(org.w3c.dom.Node n)
Test, whether a node is an Element and a source

isNailElement

public static boolean isNailElement(org.w3c.dom.Node n)
Test, whether a node is an Element and a nail

isAssignmentElement

public static boolean isAssignmentElement(org.w3c.dom.Node n)
Test, whether this is an assignment Element.

Depends on useLabelConstruct.

isGuardElement

public static boolean isGuardElement(org.w3c.dom.Node n)
Test, whether this is an guard Element.

Depends on useLabelConstruct.

isSynchronisationElement

public static boolean isSynchronisationElement(org.w3c.dom.Node n)
Test, whether this is an synchronisation Element.

Depends on useLabelConstruct.

isInvariantElement

public static boolean isInvariantElement(org.w3c.dom.Node n)
Test, whether this is an invariant Element.

Depends on useLabelConstruct.

getForkElementOfEntry

public org.w3c.dom.Element getForkElementOfEntry(org.w3c.dom.Element entry)
                                          throws java.lang.Exception
Map <entry> or <entrypoint> to the (single) corresponding fork Element.
Throws exception, if used wrongly or in wrong context.

Should only be called in AND templates.

getTargetElementOfEntry

public org.w3c.dom.Element getTargetElementOfEntry(org.w3c.dom.Element entry)
                                            throws java.lang.Exception
Map <entry> or <entrypoint> to the (single) corresponding target Element.
Throws exception, if used wrongly or in wrong context.

getTargetsOfFork

public org.w3c.dom.NodeList getTargetsOfFork(org.w3c.dom.Element fork)
                                      throws java.lang.Exception

collectGuardsAndAssignmentsOfTarget

public void collectGuardsAndAssignmentsOfTarget(org.w3c.dom.Element target,
                                                java.util.Vector guards,
                                                java.util.Vector assignments,
                                                java.lang.Object context)
                                         throws java.lang.Exception
Traverses the entry-fork starting with this target (which is assumed to point at a component and an entry)
The guards and assignments present in the connections are collected textually (Vector of strings), without any assumption on the order.

NOTE:The result of this process possibly has to be adjusted to the current instantiation (i.e., names have to be mapped) The information for this can be extraced from the context, which is a list (stack?) of renamings. !!! NOT IMPLEMENTED YET !!!.

Invariants

Of the traversed components are also added to the guards

Local Clocks

Might be reset (i.e. added to the assignments. !!! Not implemented yet -- there are no local declarations !!!

addGuardsAndAssignmentsOfConnectionInContext

public void addGuardsAndAssignmentsOfConnectionInContext(org.w3c.dom.Element connection,
                                                         java.util.Vector guards,
                                                         java.util.Vector assignments,
                                                         java.lang.Object contextOfIt)
                                                  throws java.lang.Exception
The TexualInstantiaion is handed over for context information (i.e. renaming, that is necessary if parameters are allowed).

Does not add guards or assignments that contain only whitespaces.

can also be applied on transtions

getNamesOfAliveSystemParts

public java.util.Vector getNamesOfAliveSystemParts()
                                            throws java.lang.Exception
Browse the system definition to get the name of instantiations that are declared to be part of the top-level parallel composition.

getAllChildrenThatAreAssignments

private org.w3c.dom.NodeList getAllChildrenThatAreAssignments(org.w3c.dom.Element connection)
Retrieve all child nodes that are assignments.

getAllChildrenThatAreGuards

private org.w3c.dom.NodeList getAllChildrenThatAreGuards(org.w3c.dom.Element connection)
Retrieve all child nodes that are guards.

getAllChildrenThatAreSynchronisation

private org.w3c.dom.NodeList getAllChildrenThatAreSynchronisation(org.w3c.dom.Element connection)
Retrieve all child nodes that are synchronisations.

getEntryATargetPointsTo

private org.w3c.dom.Element getEntryATargetPointsTo(org.w3c.dom.Element target)
                                             throws java.lang.Exception
Returns the (one) <entry&rt; element that a target points to

getConnectionsToExitOrExitpoint

public java.util.Vector getConnectionsToExitOrExitpoint(org.w3c.dom.Element exitOrExitpoint)
                                                 throws java.lang.Exception
Returns s Vector of Elements, containing all the pointing-to connections.

Throws Exception, if the argument is wrong and DocumentReader.sanityChecks is true - or if there are no ingoing connections.

getConnectionOfEntry

private org.w3c.dom.Element getConnectionOfEntry(org.w3c.dom.Element entry)
                                          throws java.lang.Exception
Returns the (one) connection an entry points to

getTextualGuardOfTransitionIfPresent

public java.lang.String getTextualGuardOfTransitionIfPresent(org.w3c.dom.Element transition)
                                                      throws java.lang.Exception
Returns the text of a guard, if present and not the empty string, otherwise, returns null.

Throws Exception, if not called on transition or connection.

getTextualAssignmentOfTransitionIfPresent

public java.lang.String getTextualAssignmentOfTransitionIfPresent(org.w3c.dom.Element transition)
                                                           throws java.lang.Exception
Returns the text of a assignment, if present and not the empty string, otherwise, returns null.

Throws Exception, if not called on transition or connection.

getTheChildAssignmentIfExists

public static org.w3c.dom.Element getTheChildAssignmentIfExists(org.w3c.dom.Element connection)
                                                         throws java.lang.Exception
Retrieve (if existent) the child that is assignment.

Return null, if it does not exist.

Throws exception, if more than two such children exist.

getTheChildGuardIfExists

public static org.w3c.dom.Element getTheChildGuardIfExists(org.w3c.dom.Element connection)
                                                    throws java.lang.Exception
Retrieve (if existent) the child that is guard.

Return null, if it does not exist.

Throws exception, if more than two such children exist.

getTheChildSynchronisationIfExists

public static org.w3c.dom.Element getTheChildSynchronisationIfExists(org.w3c.dom.Element connection)
                                                              throws java.lang.Exception
Retrieve (if existent) the child that is synchronisation.

Return null, if it does not exist.

Throws exception, if more than two such children exist.

getTheChildInvariantIfExists

public static org.w3c.dom.Element getTheChildInvariantIfExists(org.w3c.dom.Element connection)
                                                        throws java.lang.Exception
Retrieve (if existent) the child that is invariant.

Return null, if it does not exist.

Throws exception, if more than two such children exist.

docToString

public java.lang.String docToString()
Return the original document as string

createJoinsForGlobalExits

public void createJoinsForGlobalExits(TextualInstantiation tinst,
                                      org.w3c.dom.Element globalEntry)
                               throws java.lang.Exception
Create the Joins for stopping global elements (direct children of root);


splitCommaSeperatedString

public static java.util.Vector splitCommaSeperatedString(java.lang.String s)
Given a string containing a comma-speparated list, split it into a vector of Strings (without the commata).
Trims the strings (cuts away whitespaces).

wrapComponentAroundGlobalInstantiation

public org.w3c.dom.Element wrapComponentAroundGlobalInstantiation(java.lang.String instName,
                                                                  java.lang.String templateName)
                                                           throws java.lang.Exception
Returns a (dummy) component Element, that points to a global instantiation.
Once constructed, these Elements are stored in a Hashtable, so the result on the same call will be unique.
Used to make the ComponentMapper work on global Elements

addIDAndElementToHashTable

private void addIDAndElementToHashTable(java.lang.String ID,
                                        org.w3c.dom.Element el)
                                 throws java.lang.Exception
Make hash table entries for Elements that are not accessible in the original document

Used to retrieve components with fake IDs.