planet.generic.commonapi.factory
Class NodeFactoryImpl

java.lang.Object
  extended by planet.generic.commonapi.factory.NodeFactoryImpl
All Implemented Interfaces:
java.io.Serializable, NodeFactory

public class NodeFactoryImpl
extends java.lang.Object
implements NodeFactory

This is a specific implementation of NodeFactory that permits build any class of Node with any type of Id. It is possible by identifies theese parameters in properties file:

  1. DEFAULT_IDFACTORY: Class which identifies the IdFactory to use.
  2. DEFAULT_NODECLASS: Class which identifies the Class for new building instances.
  3. DEFAULT_TOPOLOGY: Topology of the network to construct. It is necessary to construct a valid Id for the new Node.
They can be modified too by invoking methods to this class. In any case, the properties file only can be modified by programmer.

Author:
Jordi Pujol
See Also:
Serialized Form

Field Summary
protected  java.lang.String propertiesFile
          Properties file name whose read properties.
 
Constructor Summary
NodeFactoryImpl(java.lang.Class idFactory, java.lang.Class nodeClass, java.lang.Class idClass, java.lang.String topology, int networkSize)
          Initializes a new instance of NodeFactory with the classes idFactory and nodeClass specifieds by parameter.
NodeFactoryImpl(IdFactory idFactory, java.lang.Class nodeClass, java.lang.String topology)
          Initializes a new instance of NodeFactory with the idFactory and nodeClass specifieds by parameter.
NodeFactoryImpl(java.lang.String propertiesFile)
          This constructor reads the properties' file and initializes the IdFactory and Class for new Nodes.
 
Method Summary
 Node buildNode()
          Builds a NodeImpl with the actual IdFactory and class for the nodes.
 Node buildNode(Id id)
          Builds a node with the actual implementation class of NodeImpl and the specified id.
 IdFactory getIdFactory()
          Gets the actual IdFactory in use.
 java.lang.Class getNodeClass()
          Gets the actual class of implementation of NodeImpl returned by this factory.
 java.lang.String getTopology()
          Gets the actual topology for the network.
 void setIdFactory(IdFactory idFactory)
          Sets the IdFactory to use in the future.
 void setNodeClass(java.lang.Class nodeClass)
          Sets the class of an implementation of NodeImpl to return by this factory in the future.
 void setTopology(java.lang.String topology)
          Sets the topology of the network to know how generates new Ids.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertiesFile

protected java.lang.String propertiesFile
Properties file name whose read properties.

Constructor Detail

NodeFactoryImpl

public NodeFactoryImpl(java.lang.String propertiesFile)
                throws InitializationException
This constructor reads the properties' file and initializes the IdFactory and Class for new Nodes. If occur any problem with this initialization, throws a InitializationException exception with short description for the problem.

Throws:
InitializationException - If occur any problem during initialization steps.

NodeFactoryImpl

public NodeFactoryImpl(java.lang.Class idFactory,
                       java.lang.Class nodeClass,
                       java.lang.Class idClass,
                       java.lang.String topology,
                       int networkSize)
                throws InitializationException
Initializes a new instance of NodeFactory with the classes idFactory and nodeClass specifieds by parameter. If exists any problem with this classes an exception is thrown with a short description for the problem.

Parameters:
idFactory - IdFactory class that permits build new Ids for the new Nodes.
nodeClass - Class for new Nodes.
topology - Topology of the target network.
Throws:
InitializationException - If exists any problem with initialization of both classes.
See Also:
Id

NodeFactoryImpl

public NodeFactoryImpl(IdFactory idFactory,
                       java.lang.Class nodeClass,
                       java.lang.String topology)
                throws InitializationException
Initializes a new instance of NodeFactory with the idFactory and nodeClass specifieds by parameter.

Parameters:
idFactory - Instance of IdFactory that permits build new Ids for the new Nodes.
nodeClass - Class for new Nodes.
topology - Topology of the target network.
Throws:
InitializationException - If exists any problem with initialization.
See Also:
Id
Method Detail

buildNode

public Node buildNode()
               throws InitializationException
Builds a NodeImpl with the actual IdFactory and class for the nodes.

Specified by:
buildNode in interface NodeFactory
Returns:
A new instance of the default Node.
Throws:
InitializationException
See Also:
NodeFactory.buildNode(), IdFactory, Id, Node

buildNode

public Node buildNode(Id id)
               throws InitializationException
Builds a node with the actual implementation class of NodeImpl and the specified id.

Specified by:
buildNode in interface NodeFactory
Parameters:
id - Id to assign to the new instance of NodeImpl.
Returns:
An instance of actual implementation class of NodeImpl.
Throws:
InitializationException
See Also:
NodeFactory.buildNode(planet.commonapi.Id), IdFactory, Id, Node

getIdFactory

public IdFactory getIdFactory()
Gets the actual IdFactory in use.

Specified by:
getIdFactory in interface NodeFactory
Returns:
The actual IdFactory in use.
See Also:
NodeFactory.getIdFactory()

setIdFactory

public void setIdFactory(IdFactory idFactory)
Sets the IdFactory to use in the future.

Specified by:
setIdFactory in interface NodeFactory
Parameters:
idFactory - The new IdFactory to use in the future.
See Also:
NodeFactory.setIdFactory(planet.commonapi.factory.IdFactory)

getNodeClass

public java.lang.Class getNodeClass()
Gets the actual class of implementation of NodeImpl returned by this factory.

Specified by:
getNodeClass in interface NodeFactory
Returns:
The actual class of implementation of NodeImpl returned.
See Also:
NodeFactory.getNodeClass()

setNodeClass

public void setNodeClass(java.lang.Class nodeClass)
                  throws InitializationException
Sets the class of an implementation of NodeImpl to return by this factory in the future.

Specified by:
setNodeClass in interface NodeFactory
Parameters:
nodeClass - Class of an implementation of NodeImpl to return by this factory.
Throws:
InitializationException
See Also:
NodeFactory.setNodeClass(java.lang.Class)

getTopology

public java.lang.String getTopology()
Gets the actual topology for the network. It is necessary to known how generate new Ids for the nodes.

Specified by:
getTopology in interface NodeFactory
Returns:
The topology of the network actually in use.
See Also:
NodeFactory.getTopology()

setTopology

public void setTopology(java.lang.String topology)
                 throws InitializationException
Sets the topology of the network to know how generates new Ids.

Specified by:
setTopology in interface NodeFactory
Parameters:
topology - Topology of the network.
Throws:
InitializationException
See Also:
NodeFactory.setTopology(java.lang.String)