Package org.oddjob.arooa.registry
Class SimpleBeanDirectory
java.lang.Object
org.oddjob.arooa.registry.SimpleBeanDirectory
- All Implemented Interfaces:
BeanDirectory
Provide a BeanDirectory from some mapping functions.
TODO: This is only used by ForEach in Oddjob. It should probably move there.
- Author:
- Rob Gordon.
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleBeanDirectory(Function<? super String, ?> ids, Function<? super Object, ? extends String> toId, Supplier<Stream<?>> components, PropertyAccessor propertyAccessor, ArooaConverter converter) -
Method Summary
Modifier and TypeMethodDescription<T> Iterable<T> getAllByType(Class<T> type) Get all objects in the directory of the required type.Find the id for the given component.Get the value which is either a bean or the property of a bean.<T> TGet a value, as above, but also convert it into to given type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.oddjob.arooa.registry.BeanDirectory
getAllIds
-
Constructor Details
-
SimpleBeanDirectory
public SimpleBeanDirectory(Function<? super String, ?> ids, Function<? super Object, ? extends String> toId, Supplier<Stream<?>> components, PropertyAccessor propertyAccessor, ArooaConverter converter)
-
-
Method Details
-
getAllByType
Description copied from interface:BeanDirectoryGet 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:
getAllByTypein interfaceBeanDirectory- Type Parameters:
T- The required type.- Parameters:
type- The type.- Returns:
- An Iterable for matches. Never null.
-
lookup
Description copied from interface:BeanDirectoryGet 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:
lookupin interfaceBeanDirectory- 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:BeanDirectoryGet 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:
lookupin interfaceBeanDirectory- Type Parameters:
T- The required type.- Parameters:
path- The full pathrequired- 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
Find the id for the given component.- Specified by:
getIdForin interfaceBeanDirectory- Parameters:
component- The component.- Returns:
- The id or null if none can be found.
-