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

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

public class EventsMethod
extends java.lang.Object

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

  1. Method must be annotated with Event or Events.
  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
EventsMethod(java.lang.Object listener, java.lang.reflect.Method method)
          Creates instance of invoker of specified Events Method on specified listener.
 
Method Summary
 boolean canBeInvokedWith(ContextEvent event)
          Returns if specified ContextEvent can be passed as parameter to this Events Method.
 java.lang.String getName()
          Returns the name of this Events Method.
 java.lang.Class<?> getParameter()
          Returns type of parameter of this Events Method.
 java.lang.String[] getTypes()
          Returns types of ContextEvents caught by this Events Method.
 void invoke(ContextEvent event)
          Invokes the underlying Events Method with specified ContextEvent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventsMethod

public EventsMethod(java.lang.Object listener,
                    java.lang.reflect.Method method)
Creates instance of invoker of specified Events Method on specified listener.

Parameters:
listener - the wrapped annotated listener.
method - the Events Method.
Throws:
java.lang.NullPointerException - if specified wrapped annotated listener or Method is null.
java.lang.IllegalArgumentException - if specified Method has no Event or Events 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 java.lang.String getName()
Returns the name of this Events Method.

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

getTypes

public java.lang.String[] getTypes()
Returns types of ContextEvents caught by this Events Method.

Returns:
types of ContextEvents.
See Also:
Events.value(), Event.type()

getParameter

public java.lang.Class<?> getParameter()
Returns type of parameter of this Events 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 Events Method.

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

invoke

public void invoke(ContextEvent event)
            throws java.lang.IllegalAccessException,
                   java.lang.reflect.InvocationTargetException
Invokes the underlying Events Method with specified ContextEvent.

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


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