Package org.rribbit.creation
Class ObjectBasedListenerObjectCreator
java.lang.Object
org.rribbit.creation.ObjectBasedListenerObjectCreator
- All Implemented Interfaces:
ListenerObjectCreator
- Direct Known Subclasses:
AbstractClassBasedListenerObjectCreator
This
ListenerObjectCreator creates ListenerObjects from objects. Users can pass in Objects and this class will scan the Object's
class and create ListenerObjects 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
FieldsModifier and TypeFieldDescriptionprotected Collection<ListenerObject> Subclasses are recommended to use thisCollectionto store theListenerObjects in.protected Collection<ListenerObjectCreationObserver> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidScans all public methods of the dynamic runtimeClassof the givenObject(theClassreturned byObject.getClass()) and createsListenerObjects for them if they have aListenerannotation, then initializes thoseListenerObjects with the givenObjectas execution target.protected Collection<ListenerObject> getIncompleteListenerObjectsFromClass(Class<?> clazz) Scans all public methods in the givenClass, including those inherited from superclasses / superinterfaces and createsListenerObjects for them if they have aListenerannotation.GetListenerObjects from methods that have registered themselves as aListener.protected voidnotifyObserversOnClassAdded(Class<?> addedClass) Notifies all registeredListenerObjectCreationObservers that a class is scanned and its listeners created.voidregisterObserver(ListenerObjectCreationObserver listenerObjectCreationObserver) Adds aListenerObjectCreationObserverto the list ofListenerObjectCreationObservers to be notified when a class is scanned and its listeners created.
-
Field Details
-
listenerObjects
Subclasses are recommended to use thisCollectionto store theListenerObjects in. -
observers
-
-
Constructor Details
-
ObjectBasedListenerObjectCreator
- Parameters:
objects-
-
-
Method Details
-
addObject
Scans all public methods of the dynamic runtimeClassof the givenObject(theClassreturned byObject.getClass()) and createsListenerObjects for them if they have aListenerannotation, then initializes thoseListenerObjects with the givenObjectas execution target.- Parameters:
object-
-
getIncompleteListenerObjectsFromClass
Scans all public methods in the givenClass, including those inherited from superclasses / superinterfaces and createsListenerObjects for them if they have aListenerannotation. TheseListenerObjecthave their targetObjectNOT YET SET! This is the responsibility of the caller of this method.- Parameters:
clazz- the class to scan- Returns:
- a
Collectionof incompleteListenerObjects that have their targetObjectnot yet set.
-
notifyObserversOnClassAdded
Notifies all registeredListenerObjectCreationObservers that a class is scanned and its listeners created.- Parameters:
addedClass-
-
getListenerObjects
Description copied from interface:ListenerObjectCreatorGetListenerObjects from methods that have registered themselves as aListener. Implementations are responsible for keeping a local copy of thisCollectioninstead of recreating it everytime this method is called.- Specified by:
getListenerObjectsin interfaceListenerObjectCreator- Returns:
- a
CollectionofListenerObjectfrom methods that have registered themselves as aListeneror an emptyCollectionif there are no such methods
-
registerObserver
Description copied from interface:ListenerObjectCreatorAdds aListenerObjectCreationObserverto the list ofListenerObjectCreationObservers to be notified when a class is scanned and its listeners created.- Specified by:
registerObserverin interfaceListenerObjectCreator- Parameters:
listenerObjectCreationObserver-
-