Class StrategyRegistry<A>

java.lang.Object
org.apache.tapestry5.commons.util.StrategyRegistry<A>
Type Parameters:
A - the type of the strategy adapter

public final class StrategyRegistry<A> extends Object
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 Details

    • newInstance

      public static <A> StrategyRegistry<A> newInstance(Class<A> adapterType, Map<Class,A> registrations)
      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 registry
      registrations - 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 registry
      registrations - map of registrations (the contents of the map are copied)
      allowNonMatch - if true, then the registry supports non-matches when retrieving an adapter
    • clearCache

      public void clearCache()
    • getAdapterType

      public Class<A> getAdapterType()
    • getByInstance

      public A getByInstance(Object value)
      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

      public A get(Class type)
      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

      public String toString()
      Overrides:
      toString in class Object