org.jvnet.hk2.component
Class Inhabitants

java.lang.Object
  extended by org.jvnet.hk2.component.Inhabitants

public class Inhabitants
extends java.lang.Object

Factory for Inhabitant.

Author:
Kohsuke Kawaguchi

Constructor Summary
Inhabitants()
           
 
Method Summary
static
<T> Inhabitant<T>
create(java.lang.Class<T> c, Habitat habitat, MultiMap<java.lang.String,java.lang.String> metadata)
          Creates a Inhabitant by looking at annotations of the given type.
static
<T> Inhabitant<T>
create(T instance)
          Creates a singleton wrapper around existing object.
static
<T> java.util.Collection<java.lang.String>
getIndexes(Inhabitant<T> i)
          Calculate the list of indexes under which the inhabitant is registered.
static
<T> java.util.Collection<java.lang.String>
getNamesFor(Inhabitant<T> i, java.lang.String indexName)
          Returns the list of names the service implementation in known.
static
<T> Inhabitant<T>
wrapByScope(java.lang.Class<T> c, Womb<T> womb, Habitat habitat)
          Creates a Inhabitant by wrapping Womb to handle scoping right.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Inhabitants

public Inhabitants()
Method Detail

create

public static <T> Inhabitant<T> create(T instance)
Creates a singleton wrapper around existing object.


create

public static <T> Inhabitant<T> create(java.lang.Class<T> c,
                                       Habitat habitat,
                                       MultiMap<java.lang.String,java.lang.String> metadata)
Creates a Inhabitant by looking at annotations of the given type.


wrapByScope

public static <T> Inhabitant<T> wrapByScope(java.lang.Class<T> c,
                                            Womb<T> womb,
                                            Habitat habitat)
Creates a Inhabitant by wrapping Womb to handle scoping right.


getIndexes

public static <T> java.util.Collection<java.lang.String> getIndexes(Inhabitant<T> i)
Calculate the list of indexes under which the inhabitant is registered. An index is usually obtained from a contract implementation, a service can be implementing more than one contract and therefore be indexed by multiple contract names.

Type Parameters:
T - Contract type, optional
Parameters:
i - instance of inhabitant to obtain the indexes from
Returns:
a collection of indexes (usually there is only one) under which this service is available.

getNamesFor

public static <T> java.util.Collection<java.lang.String> getNamesFor(Inhabitant<T> i,
                                                                     java.lang.String indexName)
Returns the list of names the service implementation in known. Services in hk2 are indexed by the contract name and an optional name. There can also be some aliasing so the same service can be known under different names.

Type Parameters:
T - contract type, optional
Parameters:
i - instance of inhabitant to obtain its registration name
indexName - the contract name this service is implementing
Returns:
a collaction of names (usually there is only one) under which this service is registered for the passed contract name


Copyright © 2009 Sun Microsystems, Inc.. All Rights Reserved.