org.enhydra.barracuda.core.event
Class DefaultBaseEvent

java.lang.Object
  |
  +--org.enhydra.barracuda.core.event.DefaultBaseEvent
All Implemented Interfaces:
BaseEvent, java.lang.Cloneable, StateMap
Direct Known Subclasses:
ControlEvent, ViewEvent

public abstract class DefaultBaseEvent
extends java.lang.Object
implements BaseEvent

This is the default implementation for the BaseEvent interface. It acts as the base class in the event heirarchy.

While events are capable of carrying state information, generally you want to keep them as lite as possible, storying any state either in the dispatch queue or the user's session.

NOTE: As general good practice, you should try and provide a no-args public constructor for all event classes. Anything that implements Polymorphic or Exceptional MUST have a noargs constructor, or the system will not be able to instantiate it.


Field Summary
protected  java.lang.String ext
           
protected  boolean handled
           
protected  java.util.List idList
           
protected  java.lang.Object source
           
protected  java.util.EventObject sourceEvent
           
protected  StateMap statemap
           
protected  long timestamp
           
static boolean USE_ID_ALIASES
           
protected  boolean useIDAliases
           
 
Fields inherited from interface org.enhydra.barracuda.core.event.BaseEvent
EVENT_ID
 
Constructor Summary
DefaultBaseEvent()
          Default noargs constructor
DefaultBaseEvent(java.lang.Object source)
          Public constructor.
 
Method Summary
 void addListenerID(java.lang.String id)
          Add a specific listener id this event should be delivered to.
 java.lang.Object clone()
          clone the event
 boolean equals(java.lang.Object o)
          Events are generally considered equal if they are of the same class.
static java.lang.String getClassID(java.lang.Class cl)
          Get a class ID for a given class.
 java.lang.String getEventExtension()
          get the event extension
 java.lang.String getEventID()
          Get the ID that identifies this event.
 java.lang.String getEventIDWithExtension()
          Get the id + extension of this event.
 java.util.List getListenerIDs()
          Get the list of id's this event is specifically targeted for.
static BaseEvent getOriginalEvent(BaseEvent e)
          Find the original event in target event's event chain (if it exists)
 BaseEvent getRootEvent()
          get the root event source (may be null)
static BaseEvent getRootEvent(BaseEvent be)
          get the RootEvent that caused this event (if any).
 java.lang.Object getSource()
          get the event source (may be null)
 java.lang.Object getState(java.lang.Object key)
          get a property in this StateMap
 java.util.List getStateKeys()
          get a list of the keys for this StateMap
 java.util.Map getStateValues()
          get a copy of the underlying Map
 long getTimestamp()
          Get the timestamp
 boolean isHandled()
          get the handled status for the event
 void putState(java.lang.Object key, java.lang.Object val)
          set a property in this StateMap
 java.lang.Object removeState(java.lang.Object key)
          remove a property in this StateMap
 void reset()
          Reset the event to it's default state
 void setEventExtension(java.lang.String iext)
          set the event extension
 void setHandled(boolean val)
          mark the event as handled/unhandled
 void setSource(java.lang.Object isource)
          set the source for an event
 void setUseIDAliases(boolean val)
          determine whether or not we are using ID aliasing.
 void touch()
          Update the timestamp on the event
 boolean useIDAliases()
          see whether or not we are using ID aliasing
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_ID_ALIASES

public static boolean USE_ID_ALIASES

source

protected java.lang.Object source

sourceEvent

protected java.util.EventObject sourceEvent

ext

protected java.lang.String ext

handled

protected boolean handled

idList

protected java.util.List idList

timestamp

protected long timestamp

useIDAliases

protected boolean useIDAliases

statemap

protected StateMap statemap
Constructor Detail

DefaultBaseEvent

public DefaultBaseEvent()
Default noargs constructor


DefaultBaseEvent

public DefaultBaseEvent(java.lang.Object source)
Public constructor. Automatically sets the source parameter. If you do not use this method you should manually set the source before dispatching the event.

Method Detail

setSource

public void setSource(java.lang.Object isource)
set the source for an event

Specified by:
setSource in interface BaseEvent
Parameters:
isource - the source for this event

getSource

public java.lang.Object getSource()
get the event source (may be null)

Specified by:
getSource in interface BaseEvent
Returns:
the source for this event

getRootEvent

public BaseEvent getRootEvent()
get the root event source (may be null)

Specified by:
getRootEvent in interface BaseEvent
Returns:
the root source for this event

setEventExtension

public void setEventExtension(java.lang.String iext)
set the event extension

Specified by:
setEventExtension in interface BaseEvent
Parameters:
iext - the target event extension

getEventExtension

public java.lang.String getEventExtension()
get the event extension

Specified by:
getEventExtension in interface BaseEvent
Returns:
the target event extension

setUseIDAliases

public void setUseIDAliases(boolean val)
determine whether or not we are using ID aliasing. This can be used to override the default USE_ID_ALIASES setting.

Parameters:
val - true if we want to use ID aliasing

useIDAliases

public boolean useIDAliases()
see whether or not we are using ID aliasing

Returns:
true if we want to use ID aliasing

setHandled

public void setHandled(boolean val)
mark the event as handled/unhandled

Specified by:
setHandled in interface BaseEvent

isHandled

public boolean isHandled()
get the handled status for the event

Specified by:
isHandled in interface BaseEvent
Returns:
true if the event is handled

addListenerID

public void addListenerID(java.lang.String id)
Add a specific listener id this event should be delivered to. Events can be targeted to more than one ID.

Specified by:
addListenerID in interface BaseEvent
Parameters:
id - the Listener ID the event should target

getListenerIDs

public java.util.List getListenerIDs()
Get the list of id's this event is specifically targeted for. May return null if there are none.

Specified by:
getListenerIDs in interface BaseEvent
Returns:
a List of ID's this event is specifically targeting

getEventID

public java.lang.String getEventID()
Get the ID that identifies this event. This will typically be the class name.

Specified by:
getEventID in interface BaseEvent
Returns:
a string that uniquely identifies this event

getEventIDWithExtension

public java.lang.String getEventIDWithExtension()
Get the id + extension of this event.

Specified by:
getEventIDWithExtension in interface BaseEvent
Returns:
the id and extension of this event

getTimestamp

public long getTimestamp()
Get the timestamp

Specified by:
getTimestamp in interface BaseEvent
Returns:
the last time this event was touched

touch

public void touch()
Update the timestamp on the event

Specified by:
touch in interface BaseEvent

reset

public void reset()
Reset the event to it's default state

Specified by:
reset in interface BaseEvent

getOriginalEvent

public static BaseEvent getOriginalEvent(BaseEvent e)
Find the original event in target event's event chain (if it exists)

Parameters:
e - the target event
Returns:
the original BaseEvent that caused the target event

equals

public boolean equals(java.lang.Object o)
Events are generally considered equal if they are of the same class. If you don't want this to be the case for some events (ie. if you want to get every instance of an event through your dispatcher) then you should override this method.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object we are checking against for equality
Returns:
true if the objects are equal

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
clone the event

Overrides:
clone in class java.lang.Object
Returns:
a copy of this event
Throws:
java.lang.CloneNotSupportedException

getClassID

public static java.lang.String getClassID(java.lang.Class cl)
Get a class ID for a given class. The USE_ID_ALIASES parameter is taken into account when generating the ID.

Parameters:
cl - the target class
Returns:
the class ID for the target class

getRootEvent

public static BaseEvent getRootEvent(BaseEvent be)
get the RootEvent that caused this event (if any). Will look at the source object to see if it happens to be an instance of a BaseEvent, and will recursively work deeper until it finds the event which caused it all

Parameters:
be - a BaseEvent for which we wish to find the root event
Returns:
the root BaseEvent in an event chain (may return null)

putState

public void putState(java.lang.Object key,
                     java.lang.Object val)
set a property in this StateMap

Specified by:
putState in interface StateMap
Parameters:
key - the state key object
val - the state value object

getState

public java.lang.Object getState(java.lang.Object key)
get a property in this StateMap

Specified by:
getState in interface StateMap
Parameters:
key - the state key object
Returns:
the value for the given key

removeState

public java.lang.Object removeState(java.lang.Object key)
remove a property in this StateMap

Specified by:
removeState in interface StateMap
Parameters:
key - the key object
Returns:
the object which was removed

getStateKeys

public java.util.List getStateKeys()
get a list of the keys for this StateMap

Specified by:
getStateKeys in interface StateMap
Returns:
a list the keys for this StateMap

getStateValues

public java.util.Map getStateValues()
get a copy of the underlying Map

Specified by:
getStateValues in interface StateMap
Returns:
a copy of the underlying state Map


Copyright © 2001 Enhydra.org