at.ac.tuwien.infosys.sm4all.copal.api.listener
Class OnEventMethod

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.listener.OnEventMethod

public class OnEventMethod
extends Object

Invoker of an OnEvent Method. For method to be considered an OnEvent Method all these conditions must be met:

  1. Method must be annotated with OnEvent.
  2. Method must be public.
  3. Method must have exactly one parameter.
  4. The parameter of Method must be of type ContextEvent or a subclass of it.

Author:
sanjin

Constructor Summary
OnEventMethod(Object listener, Method method)
          Creates instance of invoker of specified OnEvent Method on specified listener.
 
Method Summary
 boolean canBeInvokedWith(ContextEvent event)
          Returns if specified ContextEvent can be passed as parameter to this OnEvent Method.
 String getName()
          Returns the name of this Actions Method.
 Class<?> getParameter()
          Returns type of parameter of this OnEvent Method.
 String getType()
          Returns type of ContextEvents caught by this OnEvent Method.
 void invoke(ContextEvent event)
          Invokes the underlying OnEvent Method with specified ContextEvent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnEventMethod

public OnEventMethod(Object listener,
                     Method method)
Creates instance of invoker of specified OnEvent Method on specified listener.

Parameters:
listener - the wrapped annotated listener.
method - the OnEvent Method.
Throws:
NullPointerException - if specified wrapped annotated listener or Method is null.
IllegalArgumentException - if specified Method has no OnEvent annotation, is not public, has zero or more than one parameter, or parameter is not ContextEvent or a subclass of it.
Method Detail

getName

public String getName()
Returns the name of this Actions Method.

Returns:
the name of this Actions Method.
See Also:
Method.getName()

getType

public String getType()
Returns type of ContextEvents caught by this OnEvent Method.

Returns:
type of ContextEvents.
See Also:
OnEvent.type()

getParameter

public Class<?> getParameter()
Returns type of parameter of this OnEvent Method.

Returns:
type of parameter.
See Also:
Method.getParameterTypes()

canBeInvokedWith

public boolean canBeInvokedWith(ContextEvent event)
Returns if specified ContextEvent can be passed as parameter to this OnEvent Method.

Parameters:
event - the ContextEvent.
Returns:
if specified ContextEvent can be passed as parameter.
Throws:
NullPointerException - if specified ContextEvent is null.

invoke

public void invoke(ContextEvent event)
            throws IllegalAccessException,
                   InvocationTargetException
Invokes the underlying OnEvent Method with specified ContextEvent.

Parameters:
event - the ContextEvent.
Throws:
IllegalAccessException - if this OnEvent Method enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the underlying OnEvent Method throws an Exception.
NullPointerException - if specified ContextEvent is null.
IllegalArgumentException - if specified ContextEvent can not be passed as parameter to this OnEvent Method i.e. the canBeInvokedWith(ContextEvent) method returns false.


Copyright © 2010 Distributed Systems Group, Vienna University of Technology. All Rights Reserved.