pl.edu.agh.cast.model.visual.backward
Class VisualModelCachingFactory

java.lang.Object
  extended by pl.edu.agh.cast.model.visual.backward.VisualModelCachingFactory
All Implemented Interfaces:
Serializable

public class VisualModelCachingFactory
extends Object
implements Serializable

Class responsible for creating visual model elements from base model elements. This class implements a caching mechanism that creates new nodes, connections and connection groups only if they don't exist yet.

Author:
AGH CAST Team
See Also:
Serialized Form

Field Summary
protected  ConnectionGroupAttributeManager connectionGroupPropertyManager
          Connection group attribute manager to use for all nodes.
protected  Map<Connection,ConnectionGroup> connectionToConnectionGroup
          Maps Connection to ConnectionGroup.
protected  Map<Connection,IRelation> connectionToRelation
          Maps Connection to IRelation.
protected  Map<String,Node> entityToNode
          Maps IEntity.getId() to Node.
protected  NodeAttributeManager nodeAttributeManager
          Node attribute manager to use for all nodes.
protected  Map<IRelation,Connection> relationToConnection
          Maps IRelation to Connection.
 
Constructor Summary
VisualModelCachingFactory()
          No argument constructor (for deserialization purpose).
VisualModelCachingFactory(NodeAttributeManager nodePropMgr, ConnectionGroupAttributeManager connectionGroupPropMgr)
          Creates new factory with given node and connection group attribute managers.
 
Method Summary
 boolean containsNode(String nodeId)
          Returns true if factory has created a node with specific id.
protected  void copyAttributes(Mappable mappable, ModelElement element)
          Copies entity's attributes to a node.
 Connection copyConnection(Connection conn)
          Creates a copy of given Connection.
 ConnectionGroup copyConnectionGroup(ConnectionGroup cg, Connection conn)
          Creates a copy of given ConnectionGroup containing specified Connection.
 Node copyNode(Node node)
          Creates a copy of given Node.
 Connection createConnection(IRelation relation)
          Returns a connection corresponding to the given relation, creating it if necessary.
 Connection createConnection(IRelation relation, Set<String> currentDS)
          Returns a connection corresponding to the given relation, creating it if necessary.
 ConnectionGroup createConnectionGroup(Connection connection)
          Returns a connection group corresponding to the given connection, creating it if necessary.
 Node createNode(IEntity entity)
          Returns a node corresponding to the given entity, creating if it necessary.
 Node createNode(IEntity entity, Set<String> currentDS)
          Returns a node corresponding to the given entity, creating if it necessary.
 Connection findConnection(String sourceNodeId, String targetNodeId, Date date)
          Returns Connection based on given node id's and date.
 Node findNode(String nodeId)
          Returns Node based on given id.
 IRelation findRelation(Connection conn)
          Find relation which was used to create given connection.
protected  ConnectionGroup getConnectionGroup(Node source, Node target)
          Find ConnectionGroup for given nodes.
 Collection<Connection> getConnections()
           
 int getNodeCount()
           
 Collection<Node> getNodes()
           
protected  Collection<IRelation> getRelations()
          Returns all relations kept in the local (diagram) model
 void initAfterDeserialization(Set<Connection> connections)
          Initializes all fields after custom de-serialization.
 void removeConnection(Connection c)
          Removes given Connection from cache.
 void removeNode(Node node)
          Removes given Node from cache.
protected  void setupConnectionGroups()
           
 boolean wasCreatedHere(Connection connection)
          Checks whether given Connection was created by this factory.
 boolean wasCreatedHere(ConnectionGroup cg)
          Checks whether given ConnectionGroup was created by this factory.
 boolean wasCreatedHere(Node node)
          Checks whether given Node was created by this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityToNode

protected Map<String,Node> entityToNode
Maps IEntity.getId() to Node.


relationToConnection

protected Map<IRelation,Connection> relationToConnection
Maps IRelation to Connection.


connectionToRelation

protected Map<Connection,IRelation> connectionToRelation
Maps Connection to IRelation.


connectionToConnectionGroup

protected Map<Connection,ConnectionGroup> connectionToConnectionGroup
Maps Connection to ConnectionGroup.


nodeAttributeManager

protected NodeAttributeManager nodeAttributeManager
Node attribute manager to use for all nodes.


connectionGroupPropertyManager

protected ConnectionGroupAttributeManager connectionGroupPropertyManager
Connection group attribute manager to use for all nodes.

Constructor Detail

VisualModelCachingFactory

public VisualModelCachingFactory(NodeAttributeManager nodePropMgr,
                                 ConnectionGroupAttributeManager connectionGroupPropMgr)
Creates new factory with given node and connection group attribute managers.

Parameters:
nodePropMgr - NodeAttributeManager to use
connectionGroupPropMgr - ConnectionGroupAttributeManager to use

VisualModelCachingFactory

public VisualModelCachingFactory()
No argument constructor (for deserialization purpose).

Method Detail

createNode

public Node createNode(IEntity entity)
Returns a node corresponding to the given entity, creating if it necessary.

Parameters:
entity - IEntity to return node for
Returns:
Node that wraps given entity

createNode

public Node createNode(IEntity entity,
                       Set<String> currentDS)
Returns a node corresponding to the given entity, creating if it necessary. The currentDS collection holds the IDs of already processed nodes from current IDataSet. This is to prevent multiple processing of same node's attributes. If the parameter is null then such processing is performed each time.

Parameters:
entity - IEntity to return node for
currentDS - collection of the IDs of already processed nodes from current IDataSet
Returns:
Node that wraps given entity

createConnection

public Connection createConnection(IRelation relation)
Returns a connection corresponding to the given relation, creating it if necessary. Also creates source and target nodes if they don't exist yet.

Parameters:
relation - input relation
Returns:
connection

createConnection

public Connection createConnection(IRelation relation,
                                   Set<String> currentDS)
Returns a connection corresponding to the given relation, creating it if necessary. Also creates source and target nodes if they don't exist yet.

Parameters:
relation - input relation
currentDS - see createNode(IEntity, Set) for parameter details
Returns:
connection

createConnectionGroup

public ConnectionGroup createConnectionGroup(Connection connection)
Returns a connection group corresponding to the given connection, creating it if necessary. Also creates source and target nodes if they don't exist yet.

Parameters:
connection - connection to find connection group for
Returns:
ConnectionGroup containing given connection

getConnectionGroup

protected ConnectionGroup getConnectionGroup(Node source,
                                             Node target)
Find ConnectionGroup for given nodes. Create it if it does not exist.

Parameters:
source - connection group source Node
target - connection group target Node
Returns:
connection group corresponding to given nodes

copyAttributes

protected void copyAttributes(Mappable mappable,
                              ModelElement element)
Copies entity's attributes to a node.

Parameters:
mappable - attributes source
element - attributes destination

getNodeCount

public int getNodeCount()

getNodes

public Collection<Node> getNodes()

getConnections

public Collection<Connection> getConnections()

wasCreatedHere

public boolean wasCreatedHere(Node node)
Checks whether given Node was created by this factory.

Parameters:
node - node to check
Returns:
true if node was created by this instance of the factory

wasCreatedHere

public boolean wasCreatedHere(Connection connection)
Checks whether given Connection was created by this factory.

Parameters:
connection - connection to check
Returns:
true if connection was created by this instance of the factory

wasCreatedHere

public boolean wasCreatedHere(ConnectionGroup cg)
Checks whether given ConnectionGroup was created by this factory.

Parameters:
cg - connection group to check
Returns:
true if cg was created by this instance of the factory

removeNode

public void removeNode(Node node)
Removes given Node from cache.

Parameters:
node - node to remove

removeConnection

public void removeConnection(Connection c)
Removes given Connection from cache.

Parameters:
c - connection to remove

containsNode

public boolean containsNode(String nodeId)
Returns true if factory has created a node with specific id.

Parameters:
nodeId - node id
Returns:
true if factory has created a node with specific id.

copyNode

public Node copyNode(Node node)
Creates a copy of given Node.

Parameters:
node - node to copy
Returns:
copy of the node

copyConnection

public Connection copyConnection(Connection conn)
Creates a copy of given Connection.

Parameters:
conn - connection to copy
Returns:
copy of the conn

copyConnectionGroup

public ConnectionGroup copyConnectionGroup(ConnectionGroup cg,
                                           Connection conn)
Creates a copy of given ConnectionGroup containing specified Connection.

Parameters:
cg - connection group to copy
conn - connection contained by copied group
Returns:
copy of the cg

findNode

public Node findNode(String nodeId)
Returns Node based on given id.

Parameters:
nodeId - id of the node to find
Returns:
the node

findConnection

public Connection findConnection(String sourceNodeId,
                                 String targetNodeId,
                                 Date date)
Returns Connection based on given node id's and date.

Parameters:
sourceNodeId - id of the connection source node
targetNodeId - id of the connection target node
date - date of the connection
Returns:
the connection

findRelation

public IRelation findRelation(Connection conn)
Find relation which was used to create given connection.

Parameters:
conn - The connection for which the relation is searched
Returns:
The relation which corresponds to the connection or null if not found.

initAfterDeserialization

public void initAfterDeserialization(Set<Connection> connections)
Initializes all fields after custom de-serialization.

Parameters:
connections - collection of Connections to be used to initialize this instance of factory

getRelations

protected Collection<IRelation> getRelations()
Returns all relations kept in the local (diagram) model

Returns:
All relations

setupConnectionGroups

protected void setupConnectionGroups()


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.