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 ListenerObjectCreators for getting all ListenerObjects 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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWhenever you use this constructor, be sure to set theListenerObjectCreatorwith the setter provided by this class.DefaultListenerObjectRetriever(ListenerObjectCreator... listenerObjectCreators) This constructor is recommended, since it forces you to specify theListenerObjectCreator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListenerObjectCreator(ListenerObjectCreator listenerObjectCreator) Adds aListenerObjectCreatorto thisDefaultListenerObjectRetriever.Returns allListenerObjectCreators that are used by thisDefaultListenerObjectRetriever.getListenerObjects(Class<?> returnType) Returns aCollectionofListenerObjects that satisfy the following requirements.getListenerObjects(Class<?> returnType, String hint) Returns aCollectionofListenerObjects that satisfy the following requirements.getListenerObjects(String hint) Returns aCollectionofListenerObjects that satisfy the following requirements.protected Collection<ListenerObject> protected booleanmatchesHint(ListenerObject listenerObject, String hint) Checks whether theListenerObjectmatches the hint.protected booleanmatchesReturnType(ListenerObject listenerObject, Class<?> returnType) Checks whether theListenerObjectmatches the returntype.voidsetListenerObjectCreator(ListenerObjectCreator listenerObjectCreator) Removes allListenerObjectCreators from thisDefaultListenerObjectRetrieverand adds only the given one.
-
Field Details
-
listenerObjectCreators
-
-
Constructor Details
-
DefaultListenerObjectRetriever
public DefaultListenerObjectRetriever()Whenever you use this constructor, be sure to set theListenerObjectCreatorwith the setter provided by this class. If you don't, runtimeNullPointerExceptions will occur. -
DefaultListenerObjectRetriever
This constructor is recommended, since it forces you to specify theListenerObjectCreator. Passing a null value for this will result in a runtimeNullPointerExceptionwhenever theDefaultListenerObjectRetrieveris used.- Parameters:
listenerObjectCreators-
-
-
Method Details
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Returns:
- a
Collectionof all knownListenerObjects, or an emptyCollectionif there are none. This method never returns null.
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Parameters:
returnType- the return type that has to be assignable from the returntype of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The hints of the
ListenerObjectmust contain the 'hint' parameter
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Parameters:
hint- the hint that has to be contained by the hints of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The hints of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject - The hints of the
ListenerObjectmust contain the 'hint' parameter
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Parameters:
returnType- the return type that has to be assignable from the returntype of eachListenerObjecthint- the hint that has to be contained by the hints of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjectsFromAllCreators
-
matchesHint
Checks whether theListenerObjectmatches the hint.- Parameters:
listenerObject-hint-- Returns:
- whether the
ListenerObjectmatches the hint.
-
matchesReturnType
Checks whether theListenerObjectmatches the returntype.- Parameters:
listenerObject-returnType-- Returns:
- whether the
ListenerObjectmatches the returntype.
-
getListenerObjectCreators
Returns allListenerObjectCreators that are used by thisDefaultListenerObjectRetriever.- Returns:
- All
ListenerObjectCreators that are used by thisDefaultListenerObjectRetriever
-
addListenerObjectCreator
Adds aListenerObjectCreatorto thisDefaultListenerObjectRetriever.- Parameters:
listenerObjectCreator- TheListenerObjectCreatorthat needs to be added to thisDefaultListenerObjectRetriever
-
setListenerObjectCreator
Removes allListenerObjectCreators from thisDefaultListenerObjectRetrieverand adds only the given one. After invoking this method, only the givenListenerObjectCreatorwill be used by thisDefaultListenerObjectRetriever.- Parameters:
listenerObjectCreator- TheListenerObjectCreatorthat must be the soleListenerObjectCreatorused by thisDefaultListenerObjectRetriever
-