com.sun.hk2.component
Class RunLevelInhabitant<T,V>

java.lang.Object
  extended by com.sun.hk2.component.AbstractInhabitantImpl<T>
      extended by com.sun.hk2.component.EventPublishingInhabitant<T>
          extended by com.sun.hk2.component.RunLevelInhabitant<T,V>
All Implemented Interfaces:
Holder<T>, Inhabitant<T>

public class RunLevelInhabitant<T,V>
extends EventPublishingInhabitant<T>

An inhabitant that prevents activation unless the sufficient RunLevelState has been scheduled.

Since:
3.1
Author:
Jeff Trent

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.hk2.component.Holder
Holder.Impl<T>
 
Field Summary
 
Fields inherited from class com.sun.hk2.component.EventPublishingInhabitant
real
 
Method Summary
 T get(Inhabitant onBehalfOf)
          Returns the instance of this inhabitant.
 RunLevelState<?> getState()
           
 java.lang.Class<T> type()
          Type of the inhabitant.
protected  void verifyState()
          Verifies that the state of the RunLevelService is appropriate for this instance activation.
 
Methods inherited from class com.sun.hk2.component.EventPublishingInhabitant
addInhabitantListener, fetch, isInstantiated, metadata, notify, release, removeInhabitantListener, toString, typeName
 
Methods inherited from class com.sun.hk2.component.AbstractInhabitantImpl
companions, get, getAnnotation, getAnnotation, getSerializedMetadata, getSerializedMetadata, lead, setCompanions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

type

public java.lang.Class<T> type()
Description copied from interface: Inhabitant
Type of the inhabitant.

The only binding contract that needs to be honored is that the Inhabitant.get() method returns an instance assignable to this type. That is, get().getClass()==type() doesn't necessarily have to hold, but type().isInstance(get()) must.

This is particularly true when Factory is involved, as in such case HK2 has no way of knowing the actual type. That said, this method is not designed for the semantics of contract/implementation split --- implementations of a contract should return the concrete type from this method, and use habitat index to support look-up by contract.

Specified by:
type in interface Inhabitant<T>
Overrides:
type in class EventPublishingInhabitant<T>
Returns:
Always non-null, same value.

get

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

THIS METHOD SHOULD BE ONLY USED BY HK2 IMPLEMENTATION.

Inhabitants are often used with the decorator pattern (see AbstractCreatorInhabitantImpl for example), yet during the object initializtion inside the Inhabitant.get() method, we often need the reference to the outer-most Inhabitant registered to the Habitat (for example so that we can request the injection of {link Inhabita} that represents itself, or to inject companions.)

So this overloaded version of the get method takes the outer-most Inhabitant. This method is only invoked from within HK2 where the decorator pattern is used.

Specified by:
get in interface Inhabitant<T>
Overrides:
get in class EventPublishingInhabitant<T>

verifyState

protected void verifyState()
                    throws ComponentException
Verifies that the state of the RunLevelService is appropriate for this instance activation.

Throws:
ComponentException - if not in an appropriate state

getState

public RunLevelState<?> getState()


Copyright © 2010 Oracle Corporation. All Rights Reserved.