Package org.rribbit.retrieval
Class DefaultListenerObjectRetriever
java.lang.Object
org.rribbit.retrieval.DefaultListenerObjectRetriever
- All Implemented Interfaces:
ListenerObjectRetriever
- Direct Known Subclasses:
CachedListenerObjectRetriever
This
ListenerObjectRetriever
provides common functionality that is required by typical implementations of ListenerObjectRetriever
.
This includes methods for checking whether a ListenerObject
matches a certain request.
This class uses a List
of ListenerObjectCreator
s for getting all ListenerObject
s to search in. It does not keep a local copy of this collection, so implementations of
ListenerObjectCreator
are responsible of caching it.
This implementation is quite naieve, checking each ListenerObject
in the Collection
for a match everytime a request is made. Subclasses may replace this behaviour with
more intelligent behaviour, such as caching of search results, or may implement ListenerObjectRetriever
directly.- Author:
- G.J. Schouten
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWhenever you use this constructor, be sure to set theListenerObjectCreator
with the setter provided by this class.DefaultListenerObjectRetriever
(ListenerObjectCreator... listenerObjectCreators) This constructor is recommended, since it forces you to specify theListenerObjectCreator
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListenerObjectCreator
(ListenerObjectCreator listenerObjectCreator) Adds aListenerObjectCreator
to thisDefaultListenerObjectRetriever
.Returns allListenerObjectCreator
s that are used by thisDefaultListenerObjectRetriever
.getListenerObjects
(Class<?> returnType) Returns aCollection
ofListenerObject
s that satisfy the following requirements.getListenerObjects
(Class<?> returnType, String hint) Returns aCollection
ofListenerObject
s that satisfy the following requirements.getListenerObjects
(String hint) Returns aCollection
ofListenerObject
s that satisfy the following requirements.protected Collection
<ListenerObject> protected boolean
matchesHint
(ListenerObject listenerObject, String hint) Checks whether theListenerObject
matches the hint.protected boolean
matchesReturnType
(ListenerObject listenerObject, Class<?> returnType) Checks whether theListenerObject
matches the returntype.void
setListenerObjectCreator
(ListenerObjectCreator listenerObjectCreator) Removes allListenerObjectCreator
s from thisDefaultListenerObjectRetriever
and adds only the given one.
-
Field Details
-
listenerObjectCreators
-
-
Constructor Details
-
DefaultListenerObjectRetriever
public DefaultListenerObjectRetriever()Whenever you use this constructor, be sure to set theListenerObjectCreator
with the setter provided by this class. If you don't, runtimeNullPointerException
s will occur. -
DefaultListenerObjectRetriever
This constructor is recommended, since it forces you to specify theListenerObjectCreator
. Passing a null value for this will result in a runtimeNullPointerException
whenever theDefaultListenerObjectRetriever
is used.- Parameters:
listenerObjectCreators
-
-
-
Method Details
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Returns:
- a
Collection
of all knownListenerObject
s, or an emptyCollection
if there are none. This method never returns null.
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Parameters:
returnType
- the return type that has to be assignable from the returntype of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The hints of the
ListenerObject
must contain the 'hint' parameter
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Parameters:
hint
- the hint that has to be contained by the hints of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The hints of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- The hints of the
ListenerObject
must contain the 'hint' parameter
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Parameters:
returnType
- the return type that has to be assignable from the returntype of eachListenerObject
hint
- the hint that has to be contained by the hints of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjectsFromAllCreators
-
matchesHint
Checks whether theListenerObject
matches the hint.- Parameters:
listenerObject
-hint
-- Returns:
- whether the
ListenerObject
matches the hint.
-
matchesReturnType
Checks whether theListenerObject
matches the returntype.- Parameters:
listenerObject
-returnType
-- Returns:
- whether the
ListenerObject
matches the returntype.
-
getListenerObjectCreators
Returns allListenerObjectCreator
s that are used by thisDefaultListenerObjectRetriever
.- Returns:
- All
ListenerObjectCreator
s that are used by thisDefaultListenerObjectRetriever
-
addListenerObjectCreator
Adds aListenerObjectCreator
to thisDefaultListenerObjectRetriever
.- Parameters:
listenerObjectCreator
- TheListenerObjectCreator
that needs to be added to thisDefaultListenerObjectRetriever
-
setListenerObjectCreator
Removes allListenerObjectCreator
s from thisDefaultListenerObjectRetriever
and adds only the given one. After invoking this method, only the givenListenerObjectCreator
will be used by thisDefaultListenerObjectRetriever
.- Parameters:
listenerObjectCreator
- TheListenerObjectCreator
that must be the soleListenerObjectCreator
used by thisDefaultListenerObjectRetriever
-