Class RegistryMatcher

java.lang.Object
org.simpleframework.xml.transform.RegistryMatcher
All Implemented Interfaces:
Matcher

public class RegistryMatcher extends Object implements Matcher
The RegistryMatcher provides a simple matcher backed by a registry. Registration can be done to match a type to a Transform class or instance. If a transform class is registered an instance of it is created when requested using the default no argument constructor of the type, it is then cached so it can be reused on future requests.
See Also:
  • Field Details

    • transforms

      private final Cache<Transform> transforms
      This is used to fetch transform instances by type.
    • types

      private final Cache<Class> types
      This is used to determine the transform for a type.
  • Constructor Details

    • RegistryMatcher

      public RegistryMatcher()
      Constructor for the RegistryMatcher. This is used to create a matcher instance that can resolve a transform by type and can also instantiate new transforms if required. It is essentially a convenience implementation.
  • Method Details

    • bind

      public void bind(Class type, Class transform)
      This is used to bind a Transform type. The first time a transform is requested for the specified type a new instance of this Transform will be instantiated.
      Parameters:
      type - this is the type to resolve the transform for
      transform - this is the transform type to instantiate
    • bind

      public void bind(Class type, Transform transform)
      This is used to bind a Transform instance to the specified type. Each time a transform is requested for this type the provided instance will be returned.
      Parameters:
      type - this is the type to resolve the transform for
      transform - this transform instance to be used
    • match

      public Transform match(Class type) throws Exception
      This is used to match a Transform using the type specified. If no transform can be acquired then this returns a null value indicating that no transform could be found.
      Specified by:
      match in interface Matcher
      Parameters:
      type - this is the type to acquire the transform for
      Returns:
      returns a transform for processing the type given
      Throws:
      Exception
    • create

      private Transform create(Class type) throws Exception
      This is used to create a Transform using the type specified. If no transform can be acquired then this returns a null value indicating that no transform could be found.
      Parameters:
      type - this is the type to acquire the transform for
      Returns:
      returns a transform for processing the type given
      Throws:
      Exception
    • create

      private Transform create(Class type, Class factory) throws Exception
      This is used to create a Transform using the type specified. If the transform can not be instantiated then this will throw an exception. If it can then it is cached.
      Parameters:
      type - this is the type to acquire the transform for
      factory - the class for instantiating the transform
      Returns:
      returns a transform for processing the type given
      Throws:
      Exception