Interface Producer<I>
- Type Parameters:
I
- the contextual instance type
- All Superinterfaces:
Aggregate
- All Known Implementing Classes:
InterceptingProducer
Producer
s 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, determinateSequencedSet
ofAttributedElement
s consisting of thisProducer
's production dependencies followed by its initialization dependencies.default void
dispose
(I i, Destruction r) Disposes of the supplied contextual instance.Returns an immutable, determinateSequencedSet
ofAttributedElement
s representing dependencies required for initialization.default I
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.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, determinateSequencedSet
ofAttributedElement
s representing dependencies required for production.
-
Method Details
-
dependencies
A convenience method that returns an immutable, determinateSequencedSet
ofAttributedElement
s 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:
dependencies
in interfaceAggregate
- Returns:
- a non-
null
, immutable, determinateSequencedSet
ofAttributedElement
s 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
i
is an instance ofAutoCloseable
, and, if so, callsclose()
on it, throwing any resulting exception as aDisposalException
.- Parameters:
i
- a contextual instance produced by thisProducer
; may benull
r
- theCreation
that was present at production time; must not benull
- Throws:
NullPointerException
- ifr
isnull
DisposalException
- ifi
is anAutoCloseable
instance, and if itsclose()
method throws a checked exception
-
initializationDependencies
Returns an immutable, determinateSequencedSet
ofAttributedElement
s 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, determinateSequencedSet
ofAttributedElement
s 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
- ifc
isnull
- 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
- anId
for which production is occurring; must not benull
assignments
- aSequencedSet
ofAssignment
s thisProducer
needs to complete production and possibly initialization; must not benull
- Returns:
- a new contextual instance, or
null
- Throws:
NullPointerException
- ifassignments
isnull
-
productionDependencies
Returns an immutable, determinateSequencedSet
ofAttributedElement
s representing dependencies required for production.Such dependencies normally represent constructor parameters.
Contrast production dependencies with initialization dependencies.
- Returns:
- a non-
null
, immutable, determinateSequencedSet
ofAttributedElement
s representing dependencies required for production - See Also:
-