Interface Producer<I>
- Type Parameters:
I- the contextual instance type
- All Superinterfaces:
Aggregate
- All Known Implementing Classes:
InterceptingProducer
Producers are used to implement Factory instances' create(Creation) and destroy(Object, Destruction) methods.
A Producer normally initializes the contextual instances it produces as part of its produce(Creation) method implementation, but is not required to.
- Author:
- Laird Nelson
- See Also:
-
Field Summary
Fields inherited from interface org.microbean.bean.Aggregate
EMPTY_ASSIGNMENTS, EMPTY_DEPENDENCIES -
Method Summary
Modifier and TypeMethodDescriptiondefault SequencedSet<AttributedElement> A convenience method that returns an immutable, determinateSequencedSetofAttributedElements consisting of thisProducer's production dependencies followed by its initialization dependencies.default voiddispose(I i, Destruction r) Disposes of the supplied contextual instance.Returns an immutable, determinateSequencedSetofAttributedElements representing dependencies required for initialization.default IProduces a new contextual instance and returns it by calling theproduce(Id, SequencedSet)method with the return value of an invocation of theAggregate.assign(Function)method with a reference to the suppliedCreation'sreference(AttributedType)method.produce(Id id, SequencedSet<? extends Assignment<?>> assignments) Produces a new contextual instance and returns it, possibly (often) making use of the supplied assignments.Returns an immutable, determinateSequencedSetofAttributedElements representing dependencies required for production.
-
Method Details
-
dependencies
A convenience method that returns an immutable, determinateSequencedSetofAttributedElements consisting of thisProducer's production dependencies followed by its initialization dependencies.There is normally no need to override the default implementation of this method.
- Specified by:
dependenciesin interfaceAggregate- Returns:
- a non-
null, immutable, determinateSequencedSetofAttributedElements consisting of thisProducer's production dependencies followed by its initialization dependencies - See Also:
-
dispose
Disposes of the supplied contextual instance.The default implementation of this method checks to see if
iis an instance ofAutoCloseable, and, if so, callsclose()on it, throwing any resulting exception as aDisposalException.- Parameters:
i- a contextual instance produced by thisProducer; may benullr- theCreationthat was present at production time; must not benull- Throws:
NullPointerException- ifrisnullDisposalException- ifiis anAutoCloseableinstance, and if itsclose()method throws a checked exception
-
initializationDependencies
Returns an immutable, determinateSequencedSetofAttributedElements representing dependencies required for initialization.Such dependencies may represent initialization method parameters and/or fields.
Contrast initialization dependencies with production dependencies.
- Returns:
- a non-
null, immutable, determinateSequencedSetofAttributedElements representing dependencies required for initialization - See Also:
-
produce
Produces a new contextual instance and returns it by calling theproduce(Id, SequencedSet)method with the return value of an invocation of theAggregate.assign(Function)method with a reference to the suppliedCreation'sreference(AttributedType)method.- Parameters:
c- aCreation; must not benull- Returns:
- a new contextual instance, or
null - Throws:
NullPointerException- ifcisnull- See Also:
-
produce
Produces a new contextual instance and returns it, possibly (often) making use of the supplied assignments.Implementations of this method must not call
produce(Creation)or an infinite loop may result.- Parameters:
id- anIdfor which production is occurring; must not benullassignments- aSequencedSetofAssignments thisProducerneeds to complete production and possibly initialization; must not benull- Returns:
- a new contextual instance, or
null - Throws:
NullPointerException- ifassignmentsisnull
-
productionDependencies
Returns an immutable, determinateSequencedSetofAttributedElements representing dependencies required for production.Such dependencies normally represent constructor parameters.
Contrast production dependencies with initialization dependencies.
- Returns:
- a non-
null, immutable, determinateSequencedSetofAttributedElements representing dependencies required for production - See Also:
-