org.extex.framework
Class Registrar

java.lang.Object
  extended by org.extex.framework.Registrar

public final class Registrar
extends java.lang.Object

This class provides a means to reconnect an object to a managing factory after it has been disconnected. The disconnection might happen during serialization and deserialization.

Whenever an object is deserialized Java tries to invoke the method readResolve(). This method can be used to get a hand on the object which has just been reconstructed. Here the object can be replaced by another one or some other action can be applied.

Any class which is serializable and wants to participate in the reconnection mechanism should implement the method readResolve. In this method the method reconnect() of the Registrar should be invoked. This is shown in the following example:

  protected Object readResolve() throws ObjectStreamException {

      return Registrar.reconnect(this);
  }
 

Any factory which wants to participate in the reconnection mechanism should implement the interface RegistrarObserver.

Finally, before an object is deserialized, the interested parties should register an observer at the Registrar.

Note that the registrar has to be implemented as a static singleton since readResolve() does not provide any means to pass a reference to some other object to it.

Version:
$Revision: 6802 $
Author:
Gerd Neugebauer

Method Summary
static Registrar activate()
          Create a new registrar and activate it.
static void activate(Registrar registrar)
          Activate an existing registrar.
static void deactivate(Registrar registrar)
          Deactivate a currently active registrar.
static java.lang.Object reconnect(java.lang.Object object)
          Find anyone interested in an object and let the object be integrated into their views of the world.
static java.lang.Object register(RegistrarObserver observer, java.lang.Class<?> type)
          This method registers an observer at the registrar.
static boolean unregister(java.lang.Object obs)
          Unregister a registered observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

activate

public static Registrar activate()
                          throws RegistrarException
Create a new registrar and activate it.

Returns:
the new registrar
Throws:
RegistrarException - in case of an error

activate

public static void activate(Registrar registrar)
                     throws RegistrarException
Activate an existing registrar.

Parameters:
registrar - the registrar to activate
Throws:
RegistrarException - in case of an error

deactivate

public static void deactivate(Registrar registrar)
                       throws RegistrarException
Deactivate a currently active registrar.

Parameters:
registrar - the registrar to deactivate
Throws:
RegistrarException - in case of an error

reconnect

public static java.lang.Object reconnect(java.lang.Object object)
                                  throws RegistrarException
Find anyone interested in an object and let the object be integrated into their views of the world.

Parameters:
object - the object to reconnect
Returns:
the object which should actually be used
Throws:
RegistrarException - in case of a problem with registration

register

public static java.lang.Object register(RegistrarObserver observer,
                                        java.lang.Class<?> type)
This method registers an observer at the registrar. This observer is invoked for each class which is deserialized and matches the class given. The type argument can be an interface as well.

Parameters:
observer - the observer
type - the interface or class to be observed
Returns:
a reference to an object which can be passed to unregister() for removing the registered observer.

unregister

public static boolean unregister(java.lang.Object obs)
Unregister a registered observer.

Parameters:
obs - the reference obtained from register()
Returns:
true iff the removal succeeded