EDU.utwente.CoCompose.lang
Class Model

java.lang.Object
  |
  +--EDU.auburn.VGJ.graph.Graph
        |
        +--EDU.utwente.CoCompose.lang.Model
All Implemented Interfaces:
java.lang.Cloneable, UniqueRealm

public class Model
extends Graph
implements UniqueRealm, java.lang.Cloneable

Represents a design model made in the CoCompose language.

Version:
0.1.17, 19 November 2003
Author:
Dennis Wagelaar

Field Summary
protected  UniqueRealm typeRealm
          The composite type unique realm.
 
Fields inherited from class EDU.auburn.VGJ.graph.Graph
edges_, idHash_, lastTopId_, nodeList_
 
Constructor Summary
Model()
          Constructs an empty Model.
Model(java.lang.String uri, java.lang.String name)
          Constructs a Model from an XML document.
 
Method Summary
 void accept(ModelVisitor visitor)
          Accepts a ModelVisitor.
 void addTransPriority(java.lang.String language, java.lang.String form)
          Adds a concept form translation priority to the user defined heuristic.
protected  void applyCorrectnessConstraint(Link link)
          Enforces correctness constraints for the AbstractConcepts in the link.
 void checkCompleteness()
          Checks the completeness of the entire model.
 void checkCorrectness()
          Checks the correctness of the entire model.
 void clearTransPriorities()
          Clears the translation priority user defined heuristics.
 java.lang.Object clone()
          Creates a deep copy of the model using only persistent attributes (XML).
 void copyTransPriorities(Model from)
          Copies the translation priorities from another model.
 Composite firstComposite()
          Gets first composite from the model.
 CompositePartConcept firstCompositePartConcept()
          Gets first composite part concept from the model.
 Concept firstConcept()
          Gets first concept from the model.
 Node firstFreeNode()
          Gets first free, non-contained node from the model.
 AbstractConcept getAbstractConcept(java.lang.String name, java.lang.String namespace)
          Gets the AbstractConcept with the given name in the given unique realm.
 java.util.Collection getAbstractConcepts()
          Gets the contained AbstractConcepts.
 java.util.Collection getAbstractConcepts(AbstractConcept copiedFrom)
          Gets the AbstractConcepts that were copied from the given AbstractConcept.
 java.util.Collection getAbstractConcepts(AbstractConcept copiedFrom, UniqueRealm inRealm)
          Gets the AbstractConcepts that were copied from the given AbstractConcept.
 boolean getAlignToGrid()
          Gets align to grid attribute.
 AppliedPatterns getAppliedPatterns()
          Gets the applied solution patterns for this model.
 int getCompositeCount()
          Gets composite count.
 int getFreeNodeCount()
          Gets free nodes count, which is the number of nodes excluding all contained nodes, such as composite roles.
 java.util.Collection getLinkedNodes(java.lang.Object node)
          Gets a collection of nodes linked to the given node.
 java.util.Enumeration getLinks()
          Gets all links in the model.
 java.util.Enumeration getLinks(java.lang.Object node)
          Gets all links connected to the given node.
 java.lang.String getName()
          Gets the name of the model/unique realm.
 Node getNodeAt(DPoint3 pos)
          Gets the node at the given position.
 java.lang.String getTargetLanguage()
          Gets target language to translate the model to.
 java.util.Enumeration getTransLanguages()
          Gets the list of target languages for which translation priorities have been defined.
 java.util.Enumeration getTransPriorities(java.lang.String language)
          Gets the concept form translation priorities for the target language.
 void insertLink(Link link)
          Inserts a link, if it is legal.
 int insertNode()
          Insert a new Node object in the model.
 int insertNode(Node node)
          Insert a node in the model.
 void insertTransPriority(java.lang.String language, java.lang.String form, int index)
          Inserts a concept form translation priority to the user defined heuristic.
 boolean isUnique(java.lang.String value)
          Checks whether the given value is unique within the realm.
 void linkNodes(Node node, java.util.Collection nodes)
          Links nodes to the given node.
protected  void linkToXML(org.xml.sax.helpers.DefaultHandler handler, Link link)
          Create XML from link using a SAX DefaultHandler.
protected  boolean newLinkOk(Link link)
          Checks whether a new link can be made between these nodes.
 Composite nextComposite(Node prev_node)
          Gets next composite from the model.
 CompositePartConcept nextCompositePartConcept(Node prev_node)
          Gets next composite part concept from the model.
 Concept nextConcept(Node prev_node)
          Gets next concept from the model.
 Node nextFreeNode(Node prev_node)
          Gets next free, non-contained node from the model.
 int numberOfEdges()
          Gets the number of edges in the model.
 void refreshFromComposite(Composite fromComp)
          Updates all the composites in the model using the given composite type data.
 void register(java.lang.String value)
          Registers a new value in the realm.
 void removeEdge(int n1, int n2)
          Remove the connection from n1 to n2 but leave the nodes in place.
 void removeNode(int n)
          Remove the node from the graph (also removes the links connected to it).
 void removeNodeFromId(int id)
          Remove the node from the graph (also removes the links connected to it).
 void removeTransPriority(java.lang.String language, java.lang.String form)
          Removes a concept form translation priority from the user defined heuristic.
 void replaceNode(int n, Node node)
          Replaces the node at position n by the given node, keeping the links.
 java.lang.Object safeClone()
          Creates a deep copy of the model using only persistent attributes (XML).
 void saveStates()
          Calls saveState for each Node and Link in the model.
 void setAlignToGrid(boolean align)
          Sets align to grid attribute.
 void setInsertNode(Node node_in)
          Sets a Node object for insertion in the model.
 void setName(java.lang.String name)
          Sets the name of the model/unique realm.
 void setTargetLanguage(java.lang.String language)
          Sets target language to translate the model to.
protected static java.lang.String SystemPath(java.lang.String systemId, java.lang.String modelPath)
          Calculates the path to the system DTD.
 void toXML(org.xml.sax.helpers.DefaultHandler handler, boolean selectedOnly, java.lang.String path)
          Create an XML document from the model using a SAX DefaultHandler.
 void unRegister(java.lang.String value)
          Unregisters a value from the realm.
 
Methods inherited from class EDU.auburn.VGJ.graph.Graph
children, copy, dummysToEdgePaths, firstAvailable, firstNode, firstNodeIndex, getEdge, getEdgePathPoints, getEdges, getIndexFromNode, getNodeFromId, getNodeFromIndex, group, highestIndex, insertEdge, insertEdge, insertEdge, insertEdge, insertNode, insertNodeAt, isDirected, killGroup, nextNode, nextNodeIndex, nodeFromIndex, numberOfNodes, pack, parents, removeEdge, removeEdgePaths, removeGroups, removeNode, setDirected, setGMLvalues, setNodeGroup
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeRealm

protected UniqueRealm typeRealm
The composite type unique realm.
Constructor Detail

Model

public Model()
Constructs an empty Model.

Model

public Model(java.lang.String uri,
             java.lang.String name)
      throws CoComposeException
Constructs a Model from an XML document.
Parameters:
uri - Location of the XML document.
name - The model name
Throws:
CoComposeException - if the Model could not be created.
Method Detail

SystemPath

protected static java.lang.String SystemPath(java.lang.String systemId,
                                             java.lang.String modelPath)
Calculates the path to the system DTD.
Parameters:
systemId - - the system DTD relative to application executable path.
Returns:
the system DTD relative to the model path.

linkToXML

protected void linkToXML(org.xml.sax.helpers.DefaultHandler handler,
                         Link link)
                  throws org.xml.sax.SAXException
Create XML from link using a SAX DefaultHandler.
Parameters:
handler - The SAX DefaultHandler.
link - The link to get the GML data from.
Throws:
org.xml.sax.SAXException - if an XML handler error occurs.

newLinkOk

protected boolean newLinkOk(Link link)
Checks whether a new link can be made between these nodes.
Parameters:
link - The link to check.
Returns:
True if and only if the new link is legal.

applyCorrectnessConstraint

protected void applyCorrectnessConstraint(Link link)
                                   throws CoComposeException
Enforces correctness constraints for the AbstractConcepts in the link. Removes link if correctness constraints did not apply.
Parameters:
link - The link of which to check the involved AbstractConcepts.
Throws:
CoComposeException - if correctness constraints did not apply.

linkNodes

public void linkNodes(Node node,
                      java.util.Collection nodes)
               throws CoComposeException
Links nodes to the given node.
Parameters:
node - The node to link the other nodes to.
nodes - A collection of other nodes to link.
Throws:
CoComposeException - if not all links could be made.

insertLink

public void insertLink(Link link)
                throws CoComposeException
Inserts a link, if it is legal.
Parameters:
link - The link to insert.
Throws:
CoComposeException - if the link is illegal.

removeEdge

public void removeEdge(int n1,
                       int n2)
Remove the connection from n1 to n2 but leave the nodes in place.
Overrides:
removeEdge in class Graph
Parameters:
n1 - index of the first node on the edge
n2 - index of the second node on the edge

saveStates

public void saveStates()
Calls saveState for each Node and Link in the model.

getAlignToGrid

public boolean getAlignToGrid()
Gets align to grid attribute.
Returns:
The align to grid attribute.

setAlignToGrid

public void setAlignToGrid(boolean align)
Sets align to grid attribute.
Parameters:
align - The align to grid attribute.

setInsertNode

public void setInsertNode(Node node_in)
Sets a Node object for insertion in the model. Insertion is performed later using insertNode().
Parameters:
node_in - The Node to insert.

insertNode

public int insertNode()
Insert a new Node object in the model.
Overrides:
insertNode in class Graph
Returns:
the node index in the internal list.

insertNode

public int insertNode(Node node)
Insert a node in the model.
Parameters:
node - The Node object to insert.
Returns:
the node index in the internal list.

removeNode

public void removeNode(int n)
Remove the node from the graph (also removes the links connected to it).
Overrides:
removeNode in class Graph
Parameters:
n - The node index.

removeNodeFromId

public void removeNodeFromId(int id)
Remove the node from the graph (also removes the links connected to it).
Parameters:
id - The id of the node to remove.

replaceNode

public void replaceNode(int n,
                        Node node)
                 throws CoComposeException
Replaces the node at position n by the given node, keeping the links.
Parameters:
n - The index of the node to be replaced.
node - The node to be inserted in place.
Throws:
CoComposeException - if one of the new links is illegal.

getLinks

public java.util.Enumeration getLinks()
Gets all links in the model.
Returns:
All links in the model.

getLinks

public java.util.Enumeration getLinks(java.lang.Object node)
Gets all links connected to the given node.
Parameters:
node - The node to which the links should connect.
Returns:
an enumeration of links connected to the given node.

getAbstractConcept

public AbstractConcept getAbstractConcept(java.lang.String name,
                                          java.lang.String namespace)
Gets the AbstractConcept with the given name in the given unique realm.
Parameters:
name - The name of the AbstractConcept.
namespace - The namespace of the AbstractConcept name.
Returns:
The AbstractConcept if found, null otherwise.

getAbstractConcepts

public java.util.Collection getAbstractConcepts(AbstractConcept copiedFrom)
Gets the AbstractConcepts that were copied from the given AbstractConcept.
Parameters:
copiedFrom - The AbstractConcept that was copied.
Returns:
The Collection of AbstractConcepts found.

getAbstractConcepts

public java.util.Collection getAbstractConcepts(AbstractConcept copiedFrom,
                                                UniqueRealm inRealm)
Gets the AbstractConcepts that were copied from the given AbstractConcept.
Parameters:
copiedFrom - The AbstractConcept that was copied.
inRealm - Target AbstractConcept should reside within this realm.
Returns:
The Collection of AbstractConcepts found.

getAbstractConcepts

public java.util.Collection getAbstractConcepts()
Gets the contained AbstractConcepts.
Returns:
The collection of AbstractConcepts.

addTransPriority

public void addTransPriority(java.lang.String language,
                             java.lang.String form)
Adds a concept form translation priority to the user defined heuristic.
Parameters:
language - The target language in which the concept form is defined.
form - The concept form to add to the priority list.

insertTransPriority

public void insertTransPriority(java.lang.String language,
                                java.lang.String form,
                                int index)
Inserts a concept form translation priority to the user defined heuristic.
Parameters:
language - The target language in which the concept form is defined.
form - The concept form to add to the priority list.
index - The list index to insert the concept form at.

removeTransPriority

public void removeTransPriority(java.lang.String language,
                                java.lang.String form)
Removes a concept form translation priority from the user defined heuristic.
Parameters:
language - The target language in which the concept form is defined.
form - The concept form to remove from the priority list.

clearTransPriorities

public void clearTransPriorities()
Clears the translation priority user defined heuristics.

getTransPriorities

public java.util.Enumeration getTransPriorities(java.lang.String language)
Gets the concept form translation priorities for the target language.
Parameters:
language - The target language for which to get the priority list.
Returns:
The priority list of concept forms.

getTransLanguages

public java.util.Enumeration getTransLanguages()
Gets the list of target languages for which translation priorities have been defined.
Returns:
An enumeration of target languages.

copyTransPriorities

public void copyTransPriorities(Model from)
Copies the translation priorities from another model.
Parameters:
from - - the model to copy from

toXML

public void toXML(org.xml.sax.helpers.DefaultHandler handler,
                  boolean selectedOnly,
                  java.lang.String path)
           throws org.xml.sax.SAXException
Create an XML document from the model using a SAX DefaultHandler.
Parameters:
handler - - the SAX DefaultHandler.
selectedOnly - - if true, only creates XML for selected nodes.
path - - the path to the XML file to be written or null.
Throws:
org.xml.sax.SAXException - if an XML handler error occurs.

clone

public java.lang.Object clone()
Creates a deep copy of the model using only persistent attributes (XML). Also copies name and appliedPatterns properties.
Overrides:
clone in class Graph
Returns:
A deep copy of the model.

safeClone

public java.lang.Object safeClone()
                           throws java.lang.Exception
Creates a deep copy of the model using only persistent attributes (XML). Also copies name and appliedPatterns properties. Safe clone operation that throws an exception when cloning fails.
Returns:
A deep copy of the model.
Throws:
java.lang.Exception - - if cloning failed.

isUnique

public boolean isUnique(java.lang.String value)
Checks whether the given value is unique within the realm.
Specified by:
isUnique in interface UniqueRealm
Parameters:
value - The value to check.
Returns:
True if and only if the value is unique within the realm.

register

public void register(java.lang.String value)
Registers a new value in the realm.
Specified by:
register in interface UniqueRealm
Parameters:
value - The value to register.

unRegister

public void unRegister(java.lang.String value)
Unregisters a value from the realm.
Specified by:
unRegister in interface UniqueRealm
Parameters:
value - The value to unregister.

getName

public java.lang.String getName()
Gets the name of the model/unique realm.
Specified by:
getName in interface UniqueRealm
Returns:
The name of the model/unique realm.

setName

public void setName(java.lang.String name)
Sets the name of the model/unique realm.
Parameters:
name - The name of the model/unique realm.

getLinkedNodes

public java.util.Collection getLinkedNodes(java.lang.Object node)
Gets a collection of nodes linked to the given node.
Parameters:
node - The node to find links of.
Returns:
A collection of linked nodes.

getFreeNodeCount

public int getFreeNodeCount()
Gets free nodes count, which is the number of nodes excluding all contained nodes, such as composite roles.
Returns:
The number of free nodes.

getCompositeCount

public int getCompositeCount()
Gets composite count.
Returns:
The number of composites in the model.

firstFreeNode

public Node firstFreeNode()
Gets first free, non-contained node from the model.
Returns:
The first free node.

nextFreeNode

public Node nextFreeNode(Node prev_node)
Gets next free, non-contained node from the model.
Parameters:
prev_node - The previous node.
Returns:
The next free node.

firstComposite

public Composite firstComposite()
Gets first composite from the model.
Returns:
The first composite.

nextComposite

public Composite nextComposite(Node prev_node)
Gets next composite from the model.
Parameters:
prev_node - The previous node.
Returns:
The next composite.

firstConcept

public Concept firstConcept()
Gets first concept from the model.
Returns:
The first concept.

nextConcept

public Concept nextConcept(Node prev_node)
Gets next concept from the model.
Parameters:
prev_node - The previous node.
Returns:
The next concept.

firstCompositePartConcept

public CompositePartConcept firstCompositePartConcept()
Gets first composite part concept from the model.
Returns:
The first composite part concept.

nextCompositePartConcept

public CompositePartConcept nextCompositePartConcept(Node prev_node)
Gets next composite part concept from the model.
Parameters:
prev_node - The previous node.
Returns:
The next composite part concept.

getTargetLanguage

public java.lang.String getTargetLanguage()
Gets target language to translate the model to.
Returns:
The target language.

setTargetLanguage

public void setTargetLanguage(java.lang.String language)
Sets target language to translate the model to.
Parameters:
language - The target language.

getNodeAt

public Node getNodeAt(DPoint3 pos)
Gets the node at the given position.
Parameters:
pos - The position to look at.
Returns:
The node at that position or null.

numberOfEdges

public int numberOfEdges()
Gets the number of edges in the model.
Returns:
The number of edges.

checkCompleteness

public void checkCompleteness()
                       throws CoComposeException
Checks the completeness of the entire model.
Throws:
CoComposeException - if a ConstrainedConcept is not completely specified.

checkCorrectness

public void checkCorrectness()
                      throws CoComposeException
Checks the correctness of the entire model.
Throws:
CoComposeException - if a ConstrainedConcept is not correctly specified.

refreshFromComposite

public void refreshFromComposite(Composite fromComp)
                          throws CoComposeException
Updates all the composites in the model using the given composite type data.
Parameters:
ctype - The composite type from which to copy the data.
Throws:
CoComposeException - if one or more composites could not be successfully refreshed.

getAppliedPatterns

public AppliedPatterns getAppliedPatterns()
Gets the applied solution patterns for this model.
Returns:
The AppliedPatterns.

accept

public void accept(ModelVisitor visitor)
            throws CoComposeException
Accepts a ModelVisitor.
Parameters:
visitor - The visitor object to accept.
Throws:
CoComposeException - if visiting operation failed.