NextApp Echo
App Container 1.0.5

nextapp.echoservlet.util
Class PeerFactory

java.lang.Object
  extended bynextapp.echoservlet.util.PeerFactory
All Implemented Interfaces:
java.io.Serializable

public class PeerFactory
extends java.lang.Object
implements java.io.Serializable

Generates "peer" objects for objects based on associations. Associations are stored in a properties files, where the keys are the fully qualified class names of objects and the values are the fully qualified class names of their peers. When an object is passed to the createPeer() method its peer will be returned based on the bindings in the properties file. An objects superclass(es) will also be tested for available peers if none is available for the derived class. If no peer is found, a PeerFactoryException is thrown.

See Also:
Serialized Form

Nested Class Summary
 class PeerFactory.PeerFactoryException
          An exception used to describe a problem that was encountered loading a peer object.
 
Field Summary
private  java.util.Map associations
          A map of associations
 
Constructor Summary
PeerFactory()
          Creates a new PeerFactory.
PeerFactory(java.lang.String propertiesFile)
          Creates a new PeerFactory with initial associations.
 
Method Summary
 void addAssociations(java.lang.String propertiesFile)
          Loads peer bindings.
 java.lang.Object createPeer(java.lang.Object object)
          Instantiates a new peer for the specified object by invoking its default constructor.
 java.lang.Class getPeerClass(java.lang.Class objectClass)
          Returns the peer class associated for the given object class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

associations

private java.util.Map associations
A map of associations

Constructor Detail

PeerFactory

public PeerFactory()
Creates a new PeerFactory.


PeerFactory

public PeerFactory(java.lang.String propertiesFile)
            throws PeerFactory.PeerFactoryException
Creates a new PeerFactory with initial associations.

Parameters:
propertiesFile - The name for the properties file containing the initial peer bindings.
Method Detail

addAssociations

public void addAssociations(java.lang.String propertiesFile)
                     throws PeerFactory.PeerFactoryException
Loads peer bindings. Invoking this method will result in the new associations supplementing existing associations. Existing associations will not be removed. If two associations have the same key, the most recently added one will be used.

Parameters:
propertiesFile - The name of a properties file containing the peer bindings to be loaded.
Throws:
PeerFactory.PeerFactoryException

createPeer

public java.lang.Object createPeer(java.lang.Object object)
                            throws PeerFactory.PeerFactoryException
Instantiates a new peer for the specified object by invoking its default constructor.

Parameters:
object - The object for which to create an peer instance.
Returns:
A new instance of the peer object for object.
Throws:
PeerFactory.PeerFactoryException - if the peer cannot be instantiated.

getPeerClass

public java.lang.Class getPeerClass(java.lang.Class objectClass)
                             throws PeerFactory.PeerFactoryException
Returns the peer class associated for the given object class.

Parameters:
objectClass - The Class of the object whose peer Class is to be determined.
Returns:
The Class of the corresponding peer.
Throws:
PeerFactory.PeerFactoryException - if the peer class cannot be determined.

NextApp Echo
App Container 1.0.5