it.amattioli.workstate.core
Class MetaEvent

Show UML class diagram
java.lang.Object
  extended by it.amattioli.workstate.core.MetaEvent

public class MetaEvent
extends Object

A MetaEvent is the configuration of an Event that can be sent to a Machine.

Each MetaEvent has a tag that identifies it and a set of MetaAttribute that are its parameters.


Field Summary
static MetaEvent NULL
           
 
Constructor Summary
MetaEvent(String tag)
          Build a new MetaEvent given its tag.
 
Method Summary
 void addParameter(MetaAttribute param)
          Add a new parameter to this MetaEvent.
 void addValidator(EventValidator validator)
           
 void checkValidEvent(Event event)
           
 void checkValidParameter(String tag, Object value)
           
 boolean equals(Object obj)
          Two MetaEvents are considered equals if they have the same tag.
 MetaAttribute getParameter(String tag)
          Returns the given parameter definition.
 String getTag()
          Returns this MetaEvent tag
 Map<String,Object> initParameters(Map<String,Object> params)
          Returns the actual parameters of an event given a map of the parameters passed by the user.
 boolean isAllowedParameter(String tag)
          Check if a parameter exists.
 Event newEvent(Map<String,Object> parameters)
          Build a new Event using this MetaEvent as its definition.
 String toString()
          Return a string representation of this MetaEvent.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final MetaEvent NULL
Constructor Detail

MetaEvent

public MetaEvent(String tag)
Build a new MetaEvent given its tag.

Parameters:
tag - the MetaEvent tag
Throws:
NullPointerException - if the tag is null
IllegalArgumentException - if the tag is an empty sting
Method Detail

getTag

public String getTag()
Returns this MetaEvent tag

Returns:
this MetaEvent tag.

addParameter

public void addParameter(MetaAttribute param)
Add a new parameter to this MetaEvent.

Parameters:
the - parameter to be added
Throws:
IllegalArgumentException - if a parameter with the same tag already exists

getParameter

public MetaAttribute getParameter(String tag)
Returns the given parameter definition.

Parameters:
tag - the desired parameter tag
Returns:
the given parameter definition or null if no parameter has been set that has the given tag

addValidator

public void addValidator(EventValidator validator)

checkValidParameter

public void checkValidParameter(String tag,
                                Object value)
                         throws WorkflowException
Throws:
WorkflowException

checkValidEvent

public void checkValidEvent(Event event)
                     throws WorkflowException
Throws:
WorkflowException

initParameters

public Map<String,Object> initParameters(Map<String,Object> params)
                                  throws WorkflowException
Returns the actual parameters of an event given a map of the parameters passed by the user.

For parameters that have been defined but for which there is no parameter in the given Map, the initial value will be used.

Parameters:
params - a map containing the parameters passed by the user. The keys are the parameter tag while the values are the parameter values. If null is passed it will be considered as an empty map.
Throws:
IllegalArgumentException - if the map contains at least a key that is not the tag of a parameter of this event
ClassCastException - if the class of at least one of the passed parameter is not compatible with the corresponding parameter definition
WorkflowException

newEvent

public Event newEvent(Map<String,Object> parameters)
               throws WorkflowException
Build a new Event using this MetaEvent as its definition.

Parameters:
params - a map containing the parameters passed by the user. The keys are the parameter tag while the values are the parameter values. If null is passed it will be considered as an empty map.
Throws:
IllegalArgumentException - if the map contains at least a key that is not the tag of a parameter of this event
ClassCastException - if the class of at least one of the passed parameter is not compatible with the corresponding parameter definition
WorkflowException

isAllowedParameter

public boolean isAllowedParameter(String tag)
Check if a parameter exists.

Parameters:
tag - the parameter tag
Returns:
true if this MetaEvent has a parameter with the given tag, false otherwise

toString

public String toString()
Return a string representation of this MetaEvent. The string will consist of the MetaEvent tag followed by the parameters between parentheses.

Overrides:
toString in class Object
Returns:
the string representation of this MetaEvent

equals

public boolean equals(Object obj)
Two MetaEvents are considered equals if they have the same tag.

Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.