org.barracudamvc.core.event
Class DefaultBaseEvent

java.lang.Object
  extended by org.barracudamvc.core.event.DefaultBaseEvent
All Implemented Interfaces:
Cloneable, BaseEvent, StateMap
Direct Known Subclasses:
ControlEvent, ViewEvent

public abstract class DefaultBaseEvent
extends 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  String ext
           
protected  boolean handled
           
protected  List idList
           
protected  Map params
           
protected  Object source
           
protected  EventObject sourceEvent
           
protected  StateMap statemap
           
protected  long timestamp
           
static boolean USE_ID_ALIASES
           
protected  boolean useIDAliases
           
 
Fields inherited from interface org.barracudamvc.core.event.BaseEvent
EVENT_ID
 
Constructor Summary
DefaultBaseEvent()
          Default noargs constructor
DefaultBaseEvent(Object source)
          Public constructor.
DefaultBaseEvent(String urlParamStr)
          Public constructor.
 
Method Summary
 void addListenerID(String id)
          Add a specific listener id this event should be delivered to.
 void clearState()
          clear all state information
 Object clone()
          clone the event
 boolean equals(Object o)
          Events are generally considered equal if they are of the same class.
static String getClassID(Class cl)
          Get a class ID for a given class.
 String getEventExtension()
          get the event extension
 String getEventID()
          Get the ID that identifies this event.
 String getEventIDWithExtension()
          Deprecated. csc010404_1; replaced by getEventURL()
 String getEventURL()
          Get the URL version of the event.
 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)
 Map getParams()
          Get any associated params
 BaseEvent getRootEvent()
          get the root event source (may be null)
static BaseEvent getRootEvent(BaseEvent be)
          get the RootEvent that caused this event (if any).
 Object getSource()
          get the event source (may be null)
 Object getState(Object key)
          get a property in this StateMap
 Set getStateKeys()
          get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)
 Map getStateStore()
          get a copy of the underlying Map
 long getTimestamp()
          Get the timestamp
 boolean isHandled()
          get the handled status for the event
 void putState(Object key, Object val)
          set a property in this StateMap
 Object removeState(Object key)
          remove a property in this StateMap
 void reset()
          Reset the event to it's default state
 void setEventExtension(String iext)
          set the event extension
 void setHandled(boolean val)
          mark the event as handled/unhandled
 void setParam(String key, String val)
          Set any associated params
 void setParam(String key, String[] val)
          Set any associated params
 void setSource(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 Object source

sourceEvent

protected EventObject sourceEvent

ext

protected String ext

handled

protected boolean handled

idList

protected List idList

timestamp

protected long timestamp

useIDAliases

protected boolean useIDAliases

statemap

protected StateMap statemap

params

protected Map params
Constructor Detail

DefaultBaseEvent

public DefaultBaseEvent()
Default noargs constructor


DefaultBaseEvent

public DefaultBaseEvent(String urlParamStr)
Public constructor. Automatically sets parameters associated with the event with a URL string of the form "key1=val1&key2=val2&..." (the param str may be prefixed by a '?')


DefaultBaseEvent

public DefaultBaseEvent(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(Object isource)
set the source for an event

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

getSource

public 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(String iext)
set the event extension

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

getEventExtension

public 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
Parameters:
val - true if the event is handled

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(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 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 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 String getEventIDWithExtension()
Deprecated. csc010404_1; replaced by getEventURL()

Get the ID that identifies this event, along with the event extension

Specified by:
getEventIDWithExtension in interface BaseEvent

getEventURL

public String getEventURL()
Get the URL version of the event. This method will also include any params associated with the event.

Specified by:
getEventURL 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(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 Object
Parameters:
o - the object we are checking against for equality
Returns:
true if the objects are equal

clone

public Object clone()
             throws CloneNotSupportedException
clone the event

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

getClassID

public static String getClassID(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(Object key,
                     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 Object getState(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 Object removeState(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 Set getStateKeys()
get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)

Specified by:
getStateKeys in interface StateMap
Returns:
a Set of keys for this StateMap

getStateStore

public Map getStateStore()
get a copy of the underlying Map

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

clearState

public void clearState()
clear all state information

Specified by:
clearState in interface StateMap

setParam

public void setParam(String key,
                     String val)
Set any associated params

Specified by:
setParam in interface BaseEvent

setParam

public void setParam(String key,
                     String[] val)
Set any associated params

Specified by:
setParam in interface BaseEvent

getParams

public Map getParams()
Get any associated params

Specified by:
getParams in interface BaseEvent


Copyright © 2006 BarracudaMVC.org All Rights Reserved.