Class StrategyRegistry<A>
java.lang.Object
org.apache.tapestry5.commons.util.StrategyRegistry<A>
- Type Parameters:
A- the type of the strategy adapter
A key component in implementing the "Gang of Four" Strategy pattern. A StrategyRegistry will match up a given input
type with a registered strategy for that type.
-
Method Summary
Modifier and TypeMethodDescriptionvoidSearches for an adapter corresponding to the given input type.getByInstance(Object value) Gets an adapter for an object.getTypes()Returns the registered types for which adapters are available.static <A> StrategyRegistry<A>newInstance(Class<A> adapterType, Map<Class, A> registrations) Creates a strategy registry for the given adapter type.static <A> StrategyRegistry<A>newInstance(Class<A> adapterType, Map<Class, A> registrations, boolean allowNonMatch) Creates a strategy registry for the given adapter type.toString()
-
Method Details
-
newInstance
Creates a strategy registry for the given adapter type. The registry will be configured to require matches.- Parameters:
adapterType- the type of adapter retrieved from the registryregistrations- map of registrations (the contents of the map are copied)
-
newInstance
public static <A> StrategyRegistry<A> newInstance(Class<A> adapterType, Map<Class, A> registrations, boolean allowNonMatch) Creates a strategy registry for the given adapter type.- Parameters:
adapterType- the type of adapter retrieved from the registryregistrations- map of registrations (the contents of the map are copied)allowNonMatch- if true, then the registry supports non-matches when retrieving an adapter
-
clearCache
-
getAdapterType
-
getByInstance
Gets an adapter for an object. Searches based on the value's class, unless the value is null, in which case, a search on class void is used.- Parameters:
value- for which an adapter is needed- Returns:
- the adapter for the value or null if not found (and allowNonMatch is true)
- Throws:
IllegalArgumentException- if no matching adapter may be found and allowNonMatch is false
-
get
Searches for an adapter corresponding to the given input type.- Parameters:
type- the type to search- Returns:
- the adapter for the type or null if not found (and allowNonMatch is true)
- Throws:
IllegalArgumentException- if no matching adapter may be found and allowNonMatch is false
-
getTypes
Returns the registered types for which adapters are available. -
toString
-