|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jvnet.hk2.component.Habitat
public class Habitat
A set of templates that constitute a world of objects.
| Field Summary | |
|---|---|
String |
DEFAULT_NAME
Name to use to progammatically store default instances of a particular service. |
ScopeInstance |
singletonScope
|
| Constructor Summary | |
|---|---|
Habitat()
|
|
| Method Summary | ||
|---|---|---|
void |
add(Inhabitant<?> i)
Adds a new inhabitant. |
|
|
addComponent(String name,
T component)
Add an already instantiated component to this manager. |
|
void |
addIndex(Inhabitant<?> i,
String index,
String name)
Adds a new index to look up the given inhabitant. |
|
|
getAllByContract(Class<T> contractType)
Gets all the inhabitants registered under the given Contract. |
|
|
getAllByType(Class<T> implType)
Gets the object of the given type. |
|
Iterator<String> |
getAllContracts()
|
|
Iterator<String> |
getAllTypes()
|
|
|
getByContract(Class<T> contractType)
Gets the object that has the given contract. |
|
|
getByType(Class<T> implType)
Gets the object of the given type. |
|
|
getComponent(Class<T> clazz)
Obtains a reference to the component inside the manager. |
|
|
getComponent(Class<T> contract,
String name)
Loads a component that implements the given contract and has the given name. |
|
Object |
getComponent(String fullQualifiedName,
String name)
|
|
|
getInhabitant(Class<T> contract,
String name)
Gets a lazy reference to the component. |
|
Inhabitant<?> |
getInhabitantByAnnotation(Class<? extends Annotation> contract,
String name)
Gets the inhabitant that has the given contract annotation and the given name. |
|
Inhabitant |
getInhabitantByContract(String fullyQualifiedName,
String name)
|
|
|
getInhabitantByType(Class<T> implType)
Gets a lazy reference to the component. |
|
Inhabitant<?> |
getInhabitantByType(String fullyQualifiedClassName)
|
|
|
getInhabitants(Class<T> contract)
Gets all the inhabitants that has the given contract. |
|
|
getInhabitants(Class<T> contract,
String name)
Gets all the inhabitants that has the given contract and the given name |
|
Iterable<Inhabitant<?>> |
getInhabitantsByAnnotation(Class<? extends Annotation> contract,
String name)
Gets all the inhabitants that has the given contract annotation and the given name. |
|
Collection<Inhabitant<?>> |
getInhabitantsByContract(String fullyQualifiedClassName)
|
|
|
getInhabitantsByType(Class<T> implType)
Gets all the inhabitants that has the given implementation type. |
|
Collection<Inhabitant<?>> |
getInhabitantsByType(String fullyQualifiedClassName)
Gets all the inhabitants that has the given implementation type name. |
|
boolean |
isContract(Class<?> type)
Checks if the given type is a contract interface that has some implementations in this Habitat. |
|
boolean |
isContract(String fullyQualifiedClassName)
|
|
void |
release()
Releases all the components. |
|
boolean |
remove(Inhabitant<?> inhabitant)
Removes a inhabitant |
|
void |
removeAllByType(Class<?> type)
Removes all imhabitants for a particular type |
|
boolean |
removeIndex(String index,
Object service)
Removes a Contracted service |
|
boolean |
removeIndex(String index,
String name)
Removes a NamedInhabitant for a specific contract |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final String DEFAULT_NAME
public final ScopeInstance singletonScope
| Constructor Detail |
|---|
public Habitat()
| Method Detail |
|---|
public void removeAllByType(Class<?> type)
type - of the compomentpublic void add(Inhabitant<?> i)
See Inhabitants for typical ways to create Inhabitants.
public void addIndex(Inhabitant<?> i,
String index,
String name)
index - Primary index name, such as contract FQCN.name - Name that identifies the inhabitant among other inhabitants
in the same index. Can be null for unnamed inhabitants.public boolean remove(Inhabitant<?> inhabitant)
inhabitant - inhabitant to be removed
public boolean removeIndex(String index,
String name)
index - contract namename - instance name
public boolean removeIndex(String index,
Object service)
index - the contract nameservice - the instancepublic boolean isContract(Class<?> type)
Habitat.
There are two ways for a type to be marked as a contract.
Either it has Contract, or it's marked by ContractProvided from the implementation.
Note that just having Contract is not enough to make this method return true.
It can still return false if the contract has no implementation in this habitat.
This method is useful during the injection to determine what lookup to perform,
and it handles the case correctly when the type is marked as a contract by ContractProvided.
public boolean isContract(String fullyQualifiedClassName)
public <T> Collection<T> getAllByContract(Class<T> contractType)
Contract.
This is an example of heterogeneous type-safe container.
public <T> Collection<T> getAllByType(Class<T> implType)
public <T> void addComponent(String name,
T component)
throws ComponentException
name - name of the component, could be default namecomponent - component instance
ComponentException - if the passed object is not an HK2 component or
injection/extraction failed.
public <T> T getComponent(Class<T> clazz)
throws ComponentException
This is the "new Foo()" equivalent in the IoC world.
Depending on the Scope of the component, a new instance
might be created, or an existing instance might be returned.
ComponentException - If failed to obtain a requested instance.
In practice, failure only happens when we try to create a
new instance of the component.
public <T> T getComponent(Class<T> contract,
String name)
throws ComponentException
name - can be null, in which case it'll only match to the unnamed component.
ComponentException
public Object getComponent(String fullQualifiedName,
String name)
public <T> Inhabitant<? extends T> getInhabitant(Class<T> contract,
String name)
throws ComponentException
This method defers the actual instantiation of the component
until Inhabitant#get() is invoked.
ComponentExceptionpublic <T> Inhabitant<T> getInhabitantByType(Class<T> implType)
This method defers the actual instantiation of the component
until Inhabitant#get() is invoked.
public Inhabitant<?> getInhabitantByType(String fullyQualifiedClassName)
public Inhabitant<?> getInhabitantByAnnotation(Class<? extends Annotation> contract,
String name)
throws ComponentException
This method defers the actual instantiation of the component
until Inhabitant#get() is invoked.
ComponentException
public <T> Collection<Inhabitant<? extends T>> getInhabitants(Class<T> contract)
throws ComponentException
ComponentException
public <T> Collection<Inhabitant<T>> getInhabitantsByType(Class<T> implType)
throws ComponentException
ComponentExceptionpublic Collection<Inhabitant<?>> getInhabitantsByType(String fullyQualifiedClassName)
public Collection<Inhabitant<?>> getInhabitantsByContract(String fullyQualifiedClassName)
public Iterator<String> getAllContracts()
public Iterator<String> getAllTypes()
public Inhabitant getInhabitantByContract(String fullyQualifiedName,
String name)
public <T> Iterable<Inhabitant<? extends T>> getInhabitants(Class<T> contract,
String name)
throws ComponentException
This method defers the actual instantiation of the component
until Inhabitant#get() is invoked.
ComponentException
public Iterable<Inhabitant<?>> getInhabitantsByAnnotation(Class<? extends Annotation> contract,
String name)
throws ComponentException
This method defers the actual instantiation of the component
until Inhabitant#get() is invoked.
ComponentExceptionpublic <T> T getByType(Class<T> implType)
public <T> T getByContract(Class<T> contractType)
If there are more than one of them, this method arbitrarily return one of them.
public void release()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright © 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.
Generated on 12-March-2010 04:35