Class ComponentProvider
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
- Direct Known Subclasses:
ComponentCollector
ComponentFactory
s.An instance is configured with a collection of ComponentFactory
s
(see setFactories(ComponentFactory...)
) and component
configurations (see setPinned(List)
and
onConfigurationUpdate(ConfigurationUpdate)
).
For each configuration that references a known factory, a component is created and attached to this component provider as child.
- Since:
- 1.3
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a new component with its channel set to this object.ComponentProvider
(Channel componentChannel) Creates a new component with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the configurations for components to be provided from an entry in aConfigurationUpdate
event.Gets the factories as a map, indexed by component type.void
Uses the information from the event to configure the provided components.pinned()
Gets the pinned configurations.Selects configuration information targeted at this component from the event.setComponentsEntry
(String name) Sets the name of the entry in this component’s configuration information (as returned byproviderConfiguration(ConfigurationUpdate)
) that holds the information about the components to be provided.setFactories
(ComponentFactory... factories) Sets the factories that this provider knows about.Sets the pinned configurations.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
COMPONENT_TYPE
The entry name for the component’s type.- See Also:
-
COMPONENT_NAME
The entry name for the component’s name.- See Also:
-
-
Constructor Details
-
ComponentProvider
public ComponentProvider()Creates a new component with its channel set to this object. -
ComponentProvider
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
-
-
Method Details
-
setComponentsEntry
Sets the name of the entry in this component’s configuration information (as returned byproviderConfiguration(ConfigurationUpdate)
) that holds the information about the components to be provided.Defaults to “components”.
If set to
null
, handlingConfigurationUpdate
events is effectively disabled (unlesscomponentConfigurations(ConfigurationUpdate)
is overridden by a method that ignores the setting).- Parameters:
name
- the name of the entry- Returns:
- the component provider for easy chaining
-
setFactories
Sets the factories that this provider knows about.Only configurations with a component type that matches one of the factories are handled by this provider.
- Parameters:
factories
- the factories- Returns:
- the component provider for easy chaining
-
factories
Gets the factories as a map, indexed by component type.- Returns:
- the factories
-
setPinned
Sets the pinned configurations.Components provided due to these configurations exist independent of any information passed by
ConfigurationUpdate
events.- Parameters:
pinnedConfigurations
- the configurations to be pinned- Returns:
- the component provider for easy chaining
-
pinned
Gets the pinned configurations.- Returns:
- the pinned configurations
-
providerConfiguration
Selects configuration information targeted at this component from the event.The default implementation invokes
ConfigurationUpdate.structured(String)
with this component’s path to obtain the information. Called bycomponentConfigurations(ConfigurationUpdate)
.- Parameters:
evt
- the event- Returns:
- the configuration information as provided by
ConfigurationUpdate.structured(String)
if it exists
-
componentConfigurations
Retrieves the configurations for components to be provided from an entry in aConfigurationUpdate
event.Overriding this method enables derived classes to fully control how this information is retrieved from the
ConfigurationUpdate
event.This implementation of the method calls
providerConfiguration(ConfigurationUpdate)
to obtain all configuration information targeted at this component provider. It then uses the configured entry (seesetComponentsEntry(String)
) to retrieve the information about the components to be provided.The method must ensure that the result is a collection of maps, where each map has at least entries with keys “componentType” and “name”, each associated with a value of type
String
.- Parameters:
evt
- the event- Returns:
- the collection
-
onConfigurationUpdate
Uses the information from the event to configure the provided components.- Parameters:
evt
- the event- See Also:
-