Package org.rribbit.creation
Class ObjectBasedListenerObjectCreator
java.lang.Object
org.rribbit.creation.ObjectBasedListenerObjectCreator
- All Implemented Interfaces:
ListenerObjectCreator
- Direct Known Subclasses:
AbstractClassBasedListenerObjectCreator
This
ListenerObjectCreator
creates ListenerObject
s from objects. Users can pass in Object
s and this class will scan the Object
's
class and create ListenerObject
s for the public methods that are annotated with Listener
. This includes all public methods that are declared in superclasses.
Please note that in Java, method annotations are NOT inherited. This means that, if you override/implement a method in a subclass or subinterface, and the overriding/implementing method
does not have the annotation, then that method will not inherit it. If a class or interface just inherits a method, without overriding it, then the annotation WILL exist.
Subclasses of this class are required to call notifyObserversOnClassAdded(Class)
whenever a class is scanned and its listeners are created.- Author:
- G.J. Schouten
-
Field Summary
Modifier and TypeFieldDescriptionprotected Collection
<ListenerObject> Subclasses are recommended to use thisCollection
to store theListenerObject
s in.protected Collection
<ListenerObjectCreationObserver> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Scans all public methods of the dynamic runtimeClass
of the givenObject
(theClass
returned byObject.getClass()
) and createsListenerObject
s for them if they have aListener
annotation, then initializes thoseListenerObject
s with the givenObject
as execution target.protected Collection
<ListenerObject> getIncompleteListenerObjectsFromClass
(Class<?> clazz) Scans all public methods in the givenClass
, including those inherited from superclasses / superinterfaces and createsListenerObject
s for them if they have aListener
annotation.GetListenerObject
s from methods that have registered themselves as aListener
.protected void
notifyObserversOnClassAdded
(Class<?> addedClass) Notifies all registeredListenerObjectCreationObserver
s that a class is scanned and its listeners created.void
registerObserver
(ListenerObjectCreationObserver listenerObjectCreationObserver) Adds aListenerObjectCreationObserver
to the list ofListenerObjectCreationObserver
s to be notified when a class is scanned and its listeners created.
-
Field Details
-
listenerObjects
Subclasses are recommended to use thisCollection
to store theListenerObject
s in. -
observers
-
-
Constructor Details
-
ObjectBasedListenerObjectCreator
- Parameters:
objects
-
-
-
Method Details
-
addObject
Scans all public methods of the dynamic runtimeClass
of the givenObject
(theClass
returned byObject.getClass()
) and createsListenerObject
s for them if they have aListener
annotation, then initializes thoseListenerObject
s with the givenObject
as execution target.- Parameters:
object
-
-
getIncompleteListenerObjectsFromClass
Scans all public methods in the givenClass
, including those inherited from superclasses / superinterfaces and createsListenerObject
s for them if they have aListener
annotation. TheseListenerObject
have their targetObject
NOT YET SET! This is the responsibility of the caller of this method.- Parameters:
clazz
- the class to scan- Returns:
- a
Collection
of incompleteListenerObject
s that have their targetObject
not yet set.
-
notifyObserversOnClassAdded
Notifies all registeredListenerObjectCreationObserver
s that a class is scanned and its listeners created.- Parameters:
addedClass
-
-
getListenerObjects
Description copied from interface:ListenerObjectCreator
GetListenerObject
s from methods that have registered themselves as aListener
. Implementations are responsible for keeping a local copy of thisCollection
instead of recreating it everytime this method is called.- Specified by:
getListenerObjects
in interfaceListenerObjectCreator
- Returns:
- a
Collection
ofListenerObject
from methods that have registered themselves as aListener
or an emptyCollection
if there are no such methods
-
registerObserver
Description copied from interface:ListenerObjectCreator
Adds aListenerObjectCreationObserver
to the list ofListenerObjectCreationObserver
s to be notified when a class is scanned and its listeners created.- Specified by:
registerObserver
in interfaceListenerObjectCreator
- Parameters:
listenerObjectCreationObserver
-
-