Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

This page exists so that we can discuss the on-going @ListenerList implementation.

Basic Usage

This example shows the most basic usage of the @ListenerList annotation. The easiest way to use this annotation is to annotate a field of type List and give the List a generic type. In this example we use a List of type MyListener. MyListener is a one method interface that takes a MyEvent as a parameter. The following code is some sample source code showing the simplest scenario.

  • + addMyListener(MyListener) : void - This method is created based on the generic type of your annotated List field. The name and parameter type is are based on the List field's generic parameter.
  • + removeMyListener(MyListener) : void- This method is created based on the generic type of your annotated List field. The name and parameter type is are based on the List field's generic parameter.
  • + getMyListeners() : MyListener[] - This method is created based on the generic type of your annotated List field.The name is the plural form of the List field's generic parameter, and the return type is an array of the generic parameter.
  • + fireEventOccurred(MyEvent) : void - This method is created based on the type that the List's generic type points to. In this case, MyListener is a one method interface with an eventOccurred(MyEvent) method. The method name is fire[MethodName of the interface] and the parameter is the parameter list from the interface. (Note: what happens where there are two parameters on the method?)
  • + fireEventOccurred(Object, String) : void - This should be removed as it is too complex to generate a proper parameter list. What if the object has 2 constructors? Are there two methods generated? 10 constructors = 10 methods? Yuck.
    Gets turned into:
    Notes - 1) add listener and remove listener have conflicting code. There is a guard clause that returns null when parameter is null and a guard clause that lazy instantiates the listener. Can't have both. 2) The fireEvent methods do not seem to be part of the bean spec. To simplify, let's remove the 2nd one with 2 parameters.
Next Example

This example shows the basic usage of the @ListenerList annotation.

Gets turned into:

Advanced Examples

All of these examples assume the following:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

This example:

Gets turned into:

  • No labels