Package cdc.args
Class Factories
java.lang.Object
cdc.args.Factories
Registry of factories.
- Author:
- Damien Carbonne
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface used to convert arguments.protected static class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ArgconvertToStringValues(Arg arg) static ArgsconvertToStringValues(Args args) Converts arguments to strings.static ObjectCreates an object.static ObjectCreates an object.static ObjectCreates an object.static ObjectCreates an object.static <T> Factory<T>getFactory(Class<T> cls) static <T> Factory<T>getFactory(Class<T> cls, cdc.util.lang.FailureReaction reaction) Returns the factory associated to a class.static voidRegisters a factory.static voidsetConverter(Factories.ArgsConverter converter) Sets the arguments converter.
-
Field Details
-
PRINTER
public static final cdc.util.debug.Printable PRINTER
-
-
Method Details
-
setConverter
Sets the arguments converter.This is useful when passed arguments don't have the expected types by can be converted to.
This is typically the case when arguments are loaded from a file as strings, and must be converted to something else (Integer, Float, ...) to match factory expectations.- Parameters:
converter- The converter.
-
convertToStringValues
-
convertToStringValues
Converts arguments to strings.- Parameters:
args- The arguments.- Returns:
- Arguments with same names, but with all values converted to strings.
-
register
Registers a factory.- Parameters:
factory- The factory.- Throws:
IllegalArgumentException- whenfactoryis invalid or another factory is already associated to the built class.
-
getClasses
- Returns:
- A set of classes for which a factory is registered.
-
getFactory
Returns the factory associated to a class.If not factory was registered for the desired class, we try:
- To detect and register a declared one. It is searched as a Factory instance in the class.
- To create a new factory and register it. The is possible for singletons. This does not permit to attach meta parameters to the created factory.
- Type Parameters:
T- The object type.- Parameters:
cls- The class.reaction- The reaction to adopt when no factory is registered forcls.- Returns:
- The factory associated to
clsornull. - Throws:
cdc.util.lang.NotFoundException- When reaction is FAIL and no factory is associated tocls.
-
getFactory
-
create
Creates an object.- Parameters:
cls- The class of the object to create.args- The creation arguments.- Returns:
- The created object.
- Throws:
cdc.util.lang.NotFoundException- When no adequate factory is found.IllegalArgumentException- Whenargsare are not compliant with factory expectations.
-
create
Creates an object.- Parameters:
cls- The class of the object to create.- Returns:
- The created object.
- Throws:
cdc.util.lang.NotFoundException- When no adequate factory is found.IllegalArgumentException- WhenArgs.NO_ARGSare are not compliant with factory expectations.
-
create
Creates an object.- Parameters:
className- The class name of the object to create.args- The creation arguments.- Returns:
- The created object.
- Throws:
cdc.util.lang.NotFoundException- When no adequate factory is found.IllegalArgumentException- Whenargsare are not compliant with factory expectations.
-
create
Creates an object.- Parameters:
className- The class name of the object to create.- Returns:
- The created object.
- Throws:
cdc.util.lang.NotFoundException- When no adequate factory is found.IllegalArgumentException- WhenArgs.NO_ARGSare are not compliant with factory expectations.
-