com.sun.hk2.component
Class AbstractInhabitantImpl<T>

java.lang.Object
  extended by com.sun.hk2.component.AbstractInhabitantImpl<T>
All Implemented Interfaces:
Holder<T>, Binding<T>, Factory<T>, ManagedComponentProvider<T>, Provider<T>, Inhabitant<T>
Direct Known Subclasses:
AbstractCreatorImpl, EventPublishingInhabitant, ExistingSingletonInhabitant, ScopedInhabitant, SingletonInhabitant

public abstract class AbstractInhabitantImpl<T>
extends Object
implements Inhabitant<T>, Binding<T>

Partial implementation of Inhabitant that defines methods whose semantics is fixed by Habitat.

Author:
Kohsuke Kawaguchi

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.hk2.component.Holder
Holder.Impl<T>
 
Field Summary
protected  Descriptor descriptor
           
protected static Logger logger
           
 
Constructor Summary
AbstractInhabitantImpl(Descriptor descriptorOfSelf)
           
 
Method Summary
 Collection<Inhabitant> companions()
          Returns the companion inhabitants associated with this inhabitant.
protected  void dispose(T object)
           
 T get()
          Returns the instance of this inhabitant.
static
<V extends Annotation>
V
getAnnotation(Class<?> annotated, Class<V> annotation, boolean walkParentChain)
          FOR INTERNAL USE TO HK2
<V extends Annotation>
V
getAnnotation(Class<V> annotation)
           
 Collection<Annotation> getAnnotations()
           
 Descriptor getDescriptor()
           
protected static Descriptor getDescriptorFor(Inhabitant<?> i)
           
 Provider<T> getProvider()
           
 Provider<T> getProvider(Context ctx)
           
<T> T
getSerializedMetadata(Class<T> type)
          Obtains the metadata serialized into String.
<T> T
getSerializedMetadata(Class<T> type, String key)
          Obtains the serialized metadata.
 Inhabitant lead()
          If this inhabitant is a companion to another inhabitant (called "lead"), This method returns that inhabitant.
 boolean matches(Descriptor matchTo)
           
 void setCompanions(Collection<Inhabitant> companions)
          This method is only meant to be invoked by Habitat.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jvnet.hk2.component.Inhabitant
get, metadata, release, type, typeName
 
Methods inherited from interface org.glassfish.hk2.ManagedComponentProvider
isActive
 

Field Detail

logger

protected static final Logger logger

descriptor

protected final Descriptor descriptor
Constructor Detail

AbstractInhabitantImpl

public AbstractInhabitantImpl(Descriptor descriptorOfSelf)
Method Detail

getDescriptorFor

protected static Descriptor getDescriptorFor(Inhabitant<?> i)

getProvider

public Provider<T> getProvider(Context ctx)
Specified by:
getProvider in interface Binding<T>

getProvider

public Provider<T> getProvider()
Specified by:
getProvider in interface Binding<T>

matches

public boolean matches(Descriptor matchTo)

getDescriptor

public Descriptor getDescriptor()
Specified by:
getDescriptor in interface Binding<T>

toString

public String toString()
Overrides:
toString in class Object

get

public final T get()
Description copied from interface: Inhabitant
Returns the instance of this inhabitant.

Some Inhabitants return the same instance for multiple invocations (AKA singleton), but the method may return different instances to invocations from different context (AKA scope.) The extreme case is where the each invocation returns a different object.

Specified by:
get in interface Factory<T>
Specified by:
get in interface Provider<T>
Specified by:
get in interface Inhabitant<T>

getSerializedMetadata

public <T> T getSerializedMetadata(Class<T> type,
                                   String key)
Description copied from interface: Inhabitant
Obtains the serialized metadata.

This method is a wrapper around Inhabitant.metadata() and useful for defining a highly structured metadata that doesn't easily fit a simple string representation.

The implementation of this method is to obtain the value associated with this key as metadata().getOne(key), and if that exists, treat the value as base64-encoded binary, and deserializes it and returns the object.

The classes used in the serialization need to be available during the build time (normally during the HK2 compile mojo runs) so that the metadata can be serialized. The evolution of these classes need to be careful done, otherwise the deserialization of the metadata may fail unexpectedly.

Specified by:
getSerializedMetadata in interface Inhabitant<T>
Returns:
the deserialized object.

getSerializedMetadata

public final <T> T getSerializedMetadata(Class<T> type)
Description copied from interface: Inhabitant
Obtains the metadata serialized into String.

This is a convenient short-cut that does getSerializedMetadata(type,type.getName())

Specified by:
getSerializedMetadata in interface Inhabitant<T>

lead

public Inhabitant lead()
Description copied from interface: Inhabitant
If this inhabitant is a companion to another inhabitant (called "lead"), This method returns that inhabitant. Otherwise null.

Specified by:
lead in interface Inhabitant<T>

companions

public final Collection<Inhabitant> companions()
Description copied from interface: Inhabitant
Returns the companion inhabitants associated with this inhabitant.

This method works with the Inhabitant.lead() method in pairs, such that the following condition always holds:

x.companions().contains(y) <-> y.lead()==x

Specified by:
companions in interface Inhabitant<T>
Returns:
Can be empty but never null.

setCompanions

public final void setCompanions(Collection<Inhabitant> companions)
Description copied from interface: Inhabitant
This method is only meant to be invoked by Habitat.

Specified by:
setCompanions in interface Inhabitant<T>

dispose

protected final void dispose(T object)

getAnnotation

public <V extends Annotation> V getAnnotation(Class<V> annotation)

getAnnotation

public static <V extends Annotation> V getAnnotation(Class<?> annotated,
                                                     Class<V> annotation,
                                                     boolean walkParentChain)
FOR INTERNAL USE TO HK2


getAnnotations

public Collection<Annotation> getAnnotations()
Specified by:
getAnnotations in interface Provider<T>


Copyright © 2011 Oracle Corporation. All Rights Reserved.