Interface ComponentFactory
- All Known Subinterfaces:
HttpRequestHandlerFactory
In some use cases, components may not be known at compile-time, but
only made available at run-time. The usual pattern for this is to lookup
a factory service using the ServiceLoader
and create the
components using the factory (or factories) found.
Because JGrapes components interact with their environment only
through events, they do not provide special APIs and it is possible
to define this generic factory service interface.
Of course, lookup by the ServiceLoader
will usually be done
using a derived interface (or base class) that represents the special
kind of components required and allows an invocation
of ServiceLoader.load(Class)
that returns a “filtered”
set of factories.
- Since:
- 1.3
-
Method Summary
Modifier and TypeMethodDescriptionClass
<? extends ComponentType> Returns the type of the components created by this factory.default ComponentType
create()
Creates a new component with its channel set to itself.default ComponentType
Creates a new component with its channel set to the given channel.Creates a new component with its channel set to the given channel using the given additional properties.static ComponentType
setStandardProperties
(ComponentType component, Map<?, ?> properties) Assigns standard properties from the given properties to the component.
-
Method Details
-
setStandardProperties
Assigns standard properties from the given properties to the component.Currently, the only standard property of a component is its name.
- Parameters:
component
- the componentproperties
- the properties- Returns:
- the optional
-
componentType
Class<? extends ComponentType> componentType()Returns the type of the components created by this factory.- Returns:
- the component type
-
create
Creates a new component with its channel set to itself.- Returns:
- the component
-
create
Creates a new component with its channel set to the given channel.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to- Returns:
- the component
-
create
Creates a new component with its channel set to the given channel using the given additional properties.If the requested properties or combination of properties cannot be provided by the component, the factory may return an empty
Optional
.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event toproperties
- additional properties for the creation of the component- Returns:
- the component
-