Class Scopelet<S extends Scopelet<S>>
- Type Parameters:
S
- theScopelet
subtype extending this class
- All Implemented Interfaces:
AutoCloseable
,Constable
,Aggregate
,Factory<S>
,ScopeMember
- Direct Known Subclasses:
MapBackedScopelet
,NoneScopelet
- Author:
- Laird Nelson
- See Also:
-
Field Summary
Fields inherited from interface org.microbean.bean.Aggregate
EMPTY_ASSIGNMENTS, EMPTY_DEPENDENCIES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Scopelet
(NamedAttributeMap<?> scopeId) Creates a newScopelet
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
active()
Returnstrue
if and only if thisScopelet
is active at the moment of the call.bean()
void
close()
protected final boolean
closed()
Returnstrue
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active).boolean
containsId
(Object id) final S
Creates thisScopelet
by simply returning it.final boolean
destroys()
boolean
final <I> I
final boolean
governedBy
(NamedAttributeMap<?> scopeId) Returnstrue
if thisScopelet
is governed by the scope represented by the suppliedNamedAttributeMap
.final NamedAttributeMap
<?> Returns theNamedAttributeMap
representing the identifier of the scope to which thisScopelet
belongs.int
hashCode()
Returns a hashcode for thisScopelet
.abstract Id
id()
abstract <I> I
final <I> I
Checks to see if thisScopelet
is active and then eturns a contextual instance identified by the identifying information present within the suppliedRequest
, creating the instance and associating it with the identifying information present within the suppliedRequest
if necessary.boolean
final NamedAttributeMap
<?> scopeId()
Returns theNamedAttributeMap
that identifies thisScopelet
's affiliated scope.final S
Returns thisScopelet
if it has been created via thecreate(Request)
method, ornull
if that method has not yet been invoked.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.microbean.bean.Aggregate
assign, dependencies
Methods inherited from interface org.microbean.bean.Factory
describeConstable, destroy
-
Constructor Details
-
Scopelet
Creates a newScopelet
.- Parameters:
scopeId
- aNamedAttributeMap
identifying the scope being implemented; must not benull
- Throws:
NullPointerException
- ifscopeId
isnull
-
-
Method Details
-
id
-
bean
-
create
-
singleton
-
destroys
-
hashCode
-
equals
-
governingScopeId
Returns theNamedAttributeMap
representing the identifier of the scope to which thisScopelet
belongs.- Specified by:
governingScopeId
in interfaceScopeMember
- Returns:
- the
NamedAttributeMap
representing the identifier of the scope to which thisScopelet
belongs; nevernull
- See Also:
-
governedBy
Returnstrue
if thisScopelet
is governed by the scope represented by the suppliedNamedAttributeMap
.- Specified by:
governedBy
in interfaceScopeMember
- Parameters:
scopeId
- aNamedAttributeMap
identifying a scope; must not benull
- Returns:
true
if thisScopelet
is governed by the scope represented by the suppliedNamedAttributeMap
- Throws:
NullPointerException
- ifscopeId
isnull
-
scopeId
Returns theNamedAttributeMap
that identifies thisScopelet
's affiliated scope.- Returns:
- the
NamedAttributeMap
that identifies thisScopelet
's affiliated scope; nevernull
-
active
-
containsId
Checks to see if thisScopelet
is active and then returnstrue
if and only if, at the moment of an invocation, thisScopelet
is active and already contains an object identified by the suppliedObject
.The default implementation of this method checks to see if this
Scopelet
is active, and thentrue
if and only if the result of invoking theinstance(Object, Factory, Request)
method with the suppliedid
,null
, andnull
is notnull
.Subclasses are encouraged to override this method to be more efficient or to use a different algorithm.
- Parameters:
id
- theObject
serving as an identifier; may benull
in certain pathological cases- Returns:
true
if and only if, at the moment of an invocation, thisScopelet
is active and contains a preexisting object identified by the suppliedObject
- Throws:
InactiveScopeletException
- if thisScopelet
is not active- See Also:
-
get
Checks to see if thisScopelet
is active, and then returns the preexisting contextual instance identified by the suppliedObject
, ornull
if no such instance exists.This convenience method checks to see if this
Scopelet
is active, and then, if the suppliedObject
is not aRequest
, calls theinstance(Object, Factory, Request)
method with the suppliedid
,null
, andnull
, and returns its result.If the supplied
Object
is aRequest
, this method calls theinstance(Request)
method with the supplied (cast)id
and returns its result.- Type Parameters:
I
- the type of contextual instance- Parameters:
id
- anObject
serving as an identifier; may benull
in certain pathological cases- Returns:
- the contextual instance identified by the supplied
Object
, ornull
if no such instance exists - Throws:
InactiveScopeletException
- if thisScopelet
is not active- See Also:
-
instance
Checks to see if thisScopelet
is active and then eturns a contextual instance identified by the identifying information present within the suppliedRequest
, creating the instance and associating it with the identifying information present within the suppliedRequest
if necessary.- Type Parameters:
I
- the type of contextual instance- Parameters:
request
- aRequest
; may benull
in which case the return value of an invocation ofinstance(Object, Factory, Request)
withnull
supplied for all three arguments will be returned instead- Returns:
- an appropriate contextual instance, or
null
- Throws:
InactiveScopeletException
- if thisScopelet
is not active- See Also:
-
instance
Checks to see if thisScopelet
is active and then returns a pre-existing or created-on-demand contextual instance suitable for the combination of identifier,Factory
andRequest
.- Type Parameters:
I
- the type of contextual instance- Parameters:
id
- an identifier that can identify a contextual instance; may benull
factory
- aFactory
; may benull
request
- aRequest
, typically the one in effect that is causing this method to be invoked in the first place; may benull
- Returns:
- a contextual instance, possibly pre-existing, or possibly created just in time, or
null
- Throws:
InactiveScopeletException
- if thisScopelet
is not active
-
remove
Checks to see if thisScopelet
is active and then removes any contextual instance stored under the suppliedid
, returningtrue
if and only if removal actually took place.The default implementation of this method always returns
false
. Subclasses are encouraged to override it as appropriate.- Parameters:
id
- an identifier; may benull
- Returns:
true
if and only if removal actually occurred- Throws:
InactiveScopeletException
- if thisScopelet
is not active
-
close
- Specified by:
close
in interfaceAutoCloseable
- See Also:
-
closed
Returnstrue
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active).- Returns:
true
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active)
-