Class SimpleBeanRegistry

java.lang.Object
org.oddjob.arooa.registry.SimpleBeanRegistry
All Implemented Interfaces:
BeanDirectory, BeanRegistry
Direct Known Subclasses:
LinkedBeanRegistry

public class SimpleBeanRegistry extends Object implements BeanRegistry
Register components by id and look them up by path. A ComponentRegistry is a hierarchy with child registery. The path identifies in the hierarchy where the component resides.

This class is thread safe. Beans may be registered and retrieved by different threads.

Author:
Rob Gordon.
  • Field Details

  • Constructor Details

    • SimpleBeanRegistry

      public SimpleBeanRegistry()
      Constructor for a local registry.
    • SimpleBeanRegistry

      public SimpleBeanRegistry(PropertyAccessor propertyAccessor, ArooaConverter converter)
  • Method Details

    • getAllByType

      public <T> Iterable<T> getAllByType(Class<T> type)
      Description copied from interface: BeanDirectory
      Get all objects in the directory of the required type.

      Why an Iterable not a Collection or Set? It was thought that this would force read only use. Maybe it should be an array...

      Specified by:
      getAllByType in interface BeanDirectory
      Type Parameters:
      T - The required type.
      Parameters:
      type - The type.
      Returns:
      An Iterable for matches. Never null.
    • register

      public void register(String id, Object component) throws InvalidIdException
      Register an object. The id should not contain reserved characters.
      Specified by:
      register in interface BeanRegistry
      Parameters:
      id - The id of the object.
      component - The object.
      Throws:
      InvalidIdException
    • lookup

      public Object lookup(String path) throws ArooaPropertyException
      Description copied from interface: BeanDirectory
      Get the value which is either a bean or the property of a bean.

      The path can be either:

      • The id of a bean e.g. mybean
      • A simple property of a bean e.g. mybean.simple
      • An indexed property of a bean e.g. mybean.indexed[1]
      • A mapped property of a bean e.g. mybean.mapped(key)
      • A nested property of a bean e.g. mybean.complex.simple
      • A nested beanownerid/mybean
      • Most combinations of the above.
      Specified by:
      lookup in interface BeanDirectory
      Parameters:
      path - The path.
      Returns:
      The resultant value or null.
      Throws:
      ArooaPropertyException - If property access fails.
    • lookup

      public <T> T lookup(String path, Class<T> required) throws ArooaPropertyException, ArooaConversionException
      Description copied from interface: BeanDirectory
      Get a value, as above, but also convert it into to given type.

      Conversion in the directory is required when the client code has no access to the converters required, for instance in a nested Oddjob.

      Specified by:
      lookup in interface BeanDirectory
      Type Parameters:
      T - The required type.
      Parameters:
      path - The full path
      required - The required type.
      Returns:
      An object of the required type or null if none can be found.
      Throws:
      ArooaPropertyException - If property access fails.
      ArooaConversionException - If an object can be found but it can't be converted into the required type.
    • getIdFor

      public String getIdFor(Object component)
      Find the id for the given component.
      Specified by:
      getIdFor in interface BeanDirectory
      Parameters:
      component - The component.
      Returns:
      The id or null if none can be found.
    • getAllIds

      public Collection<String> getAllIds()
      Description copied from interface: BeanDirectory
      Provide all the Ids in the directory. This was added to support Scripting with Graalvm. It isn't implemented everywhere yet, so may throw an UnsupportedOperationException for a bit.
      Specified by:
      getAllIds in interface BeanDirectory
      Returns:
      A Collection of Ids. Never null.
    • remove

      public void remove(Object component)
      Remove a component from the registry if it exists.
      Specified by:
      remove in interface BeanRegistry
      Parameters:
      component - The component.
    • toString

      public String toString()
      Overrides:
      toString in class Object