Class CompositeFactory
java.lang.Object
org.pipservices3.components.build.CompositeFactory
- All Implemented Interfaces:
IFactory
public class CompositeFactory extends Object implements IFactory
Aggregates multiple factories into a single factory component.
When a new component is requested, it iterates through
factories to locate the one able to create the requested component.
This component is used to conveniently keep all supported factories in a single place.
### Example ###
CompositeFactory factory = new CompositeFactory();
factory.add(new DefaultLoggerFactory());
factory.add(new DefaultCountersFactory());
Descriptor loggerLocator = new Descriptor("*", "logger", "*", "*", "1.0");
factory.canCreate(loggerLocator); // Result: Descriptor("pip-service", "logger", "null", "default", "1.0")
factory.create(loggerLocator); // Result: created NullLogger
-
Constructor Summary
Constructors Constructor Description CompositeFactory()Creates a new instance of the factory.CompositeFactory(IFactory... factories)Creates a new instance of the factory. -
Method Summary
Modifier and Type Method Description voidadd(IFactory factory)Adds a factory into the list of embedded factories.ObjectcanCreate(Object locator)Checks if this factory is able to create component by given locator.Objectcreate(Object locator)Creates a component identified by given locator.voidremove(IFactory factory)Removes a factory from the list of embedded factories.
-
Constructor Details
-
CompositeFactory
public CompositeFactory()Creates a new instance of the factory. -
CompositeFactory
Creates a new instance of the factory.- Parameters:
factories- a list of factories to embed into this factory.
-
-
Method Details
-
add
Adds a factory into the list of embedded factories.- Parameters:
factory- a factory to be added.
-
remove
Removes a factory from the list of embedded factories.- Parameters:
factory- the factory to remove.
-
canCreate
Checks if this factory is able to create component by given locator. This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null. -
create
Creates a component identified by given locator.- Specified by:
createin interfaceIFactory- Parameters:
locator- a locator to identify component to be created.- Returns:
- the created component.
- Throws:
CreateException- if the factory is not able to create the component.
-