Package org.rribbit.creation
Class InstantiatingClassBasedListenerObjectCreator
java.lang.Object
org.rribbit.creation.ObjectBasedListenerObjectCreator
org.rribbit.creation.AbstractClassBasedListenerObjectCreator
org.rribbit.creation.InstantiatingClassBasedListenerObjectCreator
- All Implemented Interfaces:
ListenerObjectCreator
public class InstantiatingClassBasedListenerObjectCreator
extends AbstractClassBasedListenerObjectCreator
This
ListenerObjectCreator
creates ListenerObject
s from classes. Users can pass in Class
es or packagenames and this class will scan the Class
es
and create ListenerObject
s for the public methods that are annotated with Listener
. Note that public methods inherited from superclasses and superinterfaces will also be
scanned. This means that users must take care not to scan a method twice, once as a method of a class and once as a method of a superclass, by passing a class/interface and its
superclass/superinterface separately to this ListenerObjectCreator
.
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.
To get the actual Object
s that the listeners run on, this class simply attempts to instantiate an Object
for each Class
that it scans.
When there is no default constructor for a Class
, the Class
will simply be ignored.- Author:
- G.J. Schouten
-
Field Summary
Fields inherited from class org.rribbit.creation.AbstractClassBasedListenerObjectCreator
excludedClasses
Fields inherited from class org.rribbit.creation.ObjectBasedListenerObjectCreator
listenerObjects, observers
-
Constructor Summary
ConstructorDescriptionInstantiatingClassBasedListenerObjectCreator
(Class<?>... classes) InstantiatingClassBasedListenerObjectCreator
(Collection<Class<?>> excludedClasses, boolean scanSubPackages, String... packageNames) -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
getTargetObjectForClass
(Class<?> clazz) Gets a target executionObject
for the given class to be used by aListenerObject
to execute itsMethod
.Methods inherited from class org.rribbit.creation.AbstractClassBasedListenerObjectCreator
addClass, addPackage, excludeClass, findClassesInDirectory, findClassesInZipFile, getClasses, getClassLoader
Methods inherited from class org.rribbit.creation.ObjectBasedListenerObjectCreator
addObject, getIncompleteListenerObjectsFromClass, getListenerObjects, notifyObserversOnClassAdded, registerObserver
-
Constructor Details
-
InstantiatingClassBasedListenerObjectCreator
- Parameters:
classes
-- See Also:
-
InstantiatingClassBasedListenerObjectCreator
public InstantiatingClassBasedListenerObjectCreator(Collection<Class<?>> excludedClasses, boolean scanSubPackages, String... packageNames) - Parameters:
excludedClasses
-scanSubPackages
-packageNames
-- See Also:
-
-
Method Details
-
getTargetObjectForClass
Description copied from class:AbstractClassBasedListenerObjectCreator
Gets a target executionObject
for the given class to be used by aListenerObject
to execute itsMethod
.- Specified by:
getTargetObjectForClass
in classAbstractClassBasedListenerObjectCreator
- Parameters:
clazz
-- Returns:
- an
Object
that has the type 'clazz' and can be used as an execution target, or 'null' if no suchObject
can be found
-