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

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

public class VisualModelCachingFactory
extends java.lang.Object
implements java.io.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:
awos
See Also:
Serialized Form

Field Summary
protected  ConnectionGroupAttributeManager _connectionGroupPropertyManager
           
protected  java.util.Map<Connection,ConnectionGroup> _connectionToConnectionGroup
           
protected  java.util.Map<Connection,pl.edu.agh.cast.model.base.IRelation> _connectionToRelation
           
protected  java.util.Map<java.lang.String,Node> _entityToNode
          Maps IEntity.getId() to Node
protected  NodeAttributeManager _nodeAttributeManager
           
protected  java.util.Map<pl.edu.agh.cast.model.base.IRelation,Connection> _relationToConnection
           
 
Constructor Summary
VisualModelCachingFactory()
          No argument constructor (for deserialization purpose)
VisualModelCachingFactory(NodeAttributeManager nodePropMgr, ConnectionGroupAttributeManager connectionGroupPropMgr)
           
 
Method Summary
 boolean containsNode(java.lang.String nodeId)
          Returns true if factory has created a node with specific id.
protected  void copyAttributes(pl.edu.agh.cast.model.mapper.Mappable mappable, ModelElement element)
          Copies entity's attributes to a node
 Connection copyConnection(Connection conn)
           
 ConnectionGroup copyConnectionGroup(ConnectionGroup cg, Connection conn)
           
 Node copyNode(Node node)
           
 Connection createConnection(pl.edu.agh.cast.model.base.IRelation relation)
          Returns a connection corresponding to the given relation, creating it if necessary.
 Connection createConnection(pl.edu.agh.cast.model.base.IRelation relation, java.util.Set<java.lang.String> currentDS)
          Returns a connection corresponding to the given relation, creating it if necessary.
 ConnectionGroup createConnectionGroup(Connection connection)
           
 Node createNode(pl.edu.agh.cast.model.base.IEntity entity)
          Returns a node corresponding to the given entity, creating if it necessary.
 Node createNode(pl.edu.agh.cast.model.base.IEntity entity, java.util.Set<java.lang.String> currentDS)
          Returns a node corresponding to the given entity, creating if it necessary.
 Connection findConnection(java.lang.String sourceNodeId, java.lang.String targetNodeId, java.util.Date date)
           
 Node findNode(java.lang.String nodeId)
           
 pl.edu.agh.cast.model.base.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.
 java.util.Collection<Connection> getConnections()
           
 int getNodeCount()
           
 java.util.Collection<Node> getNodes()
           
protected  java.util.Collection<pl.edu.agh.cast.model.base.IRelation> getRelations()
          Returns all relations kept in the local (diagram) model
 void initAfterDeserialization(java.util.Set<Connection> connections)
          Initializes all fields after custom de-serialization
 void removeConnection(Connection c)
           
 void removeNode(Node node)
           
protected  void setupConnectionGroups()
          TODO This is temporary fix to get back connections after deserialization.
 boolean wasCreatedHere(Connection connection)
           
 boolean wasCreatedHere(ConnectionGroup cg)
           
 boolean wasCreatedHere(Node node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_entityToNode

protected java.util.Map<java.lang.String,Node> _entityToNode
Maps IEntity.getId() to Node


_relationToConnection

protected java.util.Map<pl.edu.agh.cast.model.base.IRelation,Connection> _relationToConnection

_connectionToRelation

protected java.util.Map<Connection,pl.edu.agh.cast.model.base.IRelation> _connectionToRelation

_connectionToConnectionGroup

protected java.util.Map<Connection,ConnectionGroup> _connectionToConnectionGroup

_nodeAttributeManager

protected NodeAttributeManager _nodeAttributeManager

_connectionGroupPropertyManager

protected ConnectionGroupAttributeManager _connectionGroupPropertyManager
Constructor Detail

VisualModelCachingFactory

public VisualModelCachingFactory(NodeAttributeManager nodePropMgr,
                                 ConnectionGroupAttributeManager connectionGroupPropMgr)

VisualModelCachingFactory

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

Method Detail

createNode

public Node createNode(pl.edu.agh.cast.model.base.IEntity entity)
Returns a node corresponding to the given entity, creating if it necessary.

Parameters:
entity -
Returns:

createNode

public Node createNode(pl.edu.agh.cast.model.base.IEntity entity,
                       java.util.Set<java.lang.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 -
currentDS -
Returns:

createConnection

public Connection createConnection(pl.edu.agh.cast.model.base.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(pl.edu.agh.cast.model.base.IRelation relation,
                                   java.util.Set<java.lang.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)

getConnectionGroup

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

Parameters:
source -
target -
Returns:

copyAttributes

protected void copyAttributes(pl.edu.agh.cast.model.mapper.Mappable mappable,
                              ModelElement element)
Copies entity's attributes to a node

Parameters:
mappable - attributes source
element - attributes destination

getNodeCount

public int getNodeCount()

getNodes

public java.util.Collection<Node> getNodes()

getConnections

public java.util.Collection<Connection> getConnections()

wasCreatedHere

public boolean wasCreatedHere(Node node)

wasCreatedHere

public boolean wasCreatedHere(Connection connection)

wasCreatedHere

public boolean wasCreatedHere(ConnectionGroup cg)

removeNode

public void removeNode(Node node)

removeConnection

public void removeConnection(Connection c)

containsNode

public boolean containsNode(java.lang.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)

copyConnection

public Connection copyConnection(Connection conn)

copyConnectionGroup

public ConnectionGroup copyConnectionGroup(ConnectionGroup cg,
                                           Connection conn)

findNode

public Node findNode(java.lang.String nodeId)

findConnection

public Connection findConnection(java.lang.String sourceNodeId,
                                 java.lang.String targetNodeId,
                                 java.util.Date date)

findRelation

public pl.edu.agh.cast.model.base.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(java.util.Set<Connection> connections)
Initializes all fields after custom de-serialization

Parameters:
connections -

getRelations

protected java.util.Collection<pl.edu.agh.cast.model.base.IRelation> getRelations()
Returns all relations kept in the local (diagram) model

Returns:
All relations

setupConnectionGroups

protected void setupConnectionGroups()
TODO This is temporary fix to get back connections after deserialization. Proper implementation should be completely different - IMHO (apohllo) this class should not be serialized!



Copyright © 2007-2008 AGH University of Science and Technology. All Rights Reserved.