net.dpml.station.server
Class DefaultModel

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by net.dpml.station.server.DefaultModel
All Implemented Interfaces:
Serializable, Remote
Direct Known Subclasses:
RemoteApplicationRegistry

public abstract class DefaultModel
extends UnicastRemoteObject

A abstract base class that established an event queue and handles event dispatch operations for listeners declared in classes extending this base class.

Version:
1.2.0
Author:
Digital Product Meta Library
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
DefaultModel(Logger logger)
          Creation of a new model.
DefaultModel(String name)
          Creation of a new model.
 
Method Summary
protected  void addListener(EventListener listener)
          Add a listener to the set of listeners handled by the model.
protected  void enqueueEvent(EventObject event)
          Enqueue an event for delivery to registered listeners unless there are no registered listeners.
protected  void enqueueEvent(EventObject event, boolean asynchronouse)
          Enqueue an event for delivery to registered listeners unless there are no registered listeners.
protected  Object getLock()
          Return the internal synchronization lock object.
protected  Logger getLogger()
          Return the assigned logging channel.
protected  EventListener[] listeners()
          Return the set of registered listeners.
protected abstract  void processEvent(EventObject event)
          Abstract method that must be implemented by classes extending this class.
protected  void removeListener(EventListener listener)
          Remove a listener to the set of listeners handled by this producer.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultModel

public DefaultModel(String name)
             throws RemoteException
Creation of a new model.

Parameters:
name - the name used to construct a logging channel
Throws:
RemoteException - if a remote exception occurs

DefaultModel

public DefaultModel(Logger logger)
             throws NullPointerException,
                    RemoteException
Creation of a new model.

Parameters:
logger - the assigned logging channel
Throws:
NullPointerException - if the supplied logging channel is null
RemoteException - if a remote exception occurs
Method Detail

processEvent

protected abstract void processEvent(EventObject event)
Abstract method that must be implemented by classes extending this class. An implementation is responsible for handling the processing of events it is aware of or throwing an llegalArgumentException in the case of unrecognized event types. A typical implementation is shown in the following code fragment:
 protected void processEvent( EventObject eventObject )
 {
    if( eventObject instanceof ProxyEvent )
    {
        ProxyEvent event = (ProxyEvent) eventObject;
        processProxyEvent( event );
    }
    else
    {
        final String error = 
          "Event class not recognized: " + eventObject.getClass().getName();
        throw new IllegalArgumentException( error );
    }
 }

 private void processProxyEvent( ProxyEvent event )
 {
    EventListener[] listeners = super.listeners();
    for( int i=0; i<listeners.length; i++ )
    {
        EventListener listener = listeners[i];
        if( listener instanceof ProxyListener )
        {
            ProxyListener pl = (ProxyListener) listener;
            try
            {
                pl.proxyChanged( event );
            }
            catch( Throwable e )
            {
                final String error =
                  "Proxy listener notification error.";
                getLogger().error( error, e );
            }
        }
    }
 }
 

Parameters:
event - the event to process

getLogger

protected Logger getLogger()
Return the assigned logging channel.

Returns:
the logging channel

addListener

protected void addListener(EventListener listener)
                    throws NullPointerException
Add a listener to the set of listeners handled by the model.

Parameters:
listener - the event listener
Throws:
NullPointerException - if the supplied listener is null

removeListener

protected void removeListener(EventListener listener)
                       throws NullPointerException
Remove a listener to the set of listeners handled by this producer.

Parameters:
listener - the event listener
Throws:
NullPointerException - if the supplied listener is null

getLock

protected Object getLock()
Return the internal synchronization lock object.

Returns:
the lock object

listeners

protected EventListener[] listeners()
Return the set of registered listeners.

Returns:
an array of registered listeners

enqueueEvent

protected void enqueueEvent(EventObject event)
Enqueue an event for delivery to registered listeners unless there are no registered listeners.

Parameters:
event - the event object to add to the queue

enqueueEvent

protected void enqueueEvent(EventObject event,
                            boolean asynchronouse)
Enqueue an event for delivery to registered listeners unless there are no registered listeners.

Parameters:
event - the event object to add to the queue
asynchronouse - TRUE if asynchronouse delivery