org.jvnet.hk2.component
Interface SimpleServiceLocator

All Known Implementing Classes:
Habitat

public interface SimpleServiceLocator

Provide a simple abstraction for getting services by contract or type.

Author:
Jerome Dochez, Jeff Trent

Method Summary
<T> T
getByType(Class<T> implType)
          Gets the object of the given type.
<T> T
getByType(String implType)
          Gets the object of the given type.
<T> T
getComponent(Class<T> contract, String name)
          Loads a component that implements the given contract and has the given name.
<T> T
getComponent(String fullQualifiedName, String name)
          Analogous to the following:
<T> Collection<Inhabitant<T>>
getInhabitantsByContract(String contractName)
           
<T> Collection<Inhabitant<T>>
getInhabitantsByContract(Type contract)
          Gets all the inhabitants that has the given contract.
<T> Collection<Inhabitant<T>>
getInhabitantsByType(Class<T> type)
          Gets all the inhabitants that has the given type.
<T> Collection<Inhabitant<T>>
getInhabitantsByType(String typeName)
           
<T> Inhabitant<T>
getProvider(String fqcn, String name)
           
<T> Inhabitant<T>
getProvider(Type type, String name)
          Gets an inhabitant from its type and optionally name
 

Method Detail

getComponent

<T> T getComponent(Class<T> contract,
                   String name)
               throws ComponentException
Loads a component that implements the given contract and has the given name.

Parameters:
name - can be null, in which case it'll only match to the unnamed component.
Returns:
null if no such service exists.
Throws:
ComponentException

getComponent

<T> T getComponent(String fullQualifiedName,
                   String name)
Analogous to the following:
 getComponent(contractClass.getName(), name);
 

Parameters:
fullQualifiedName - the contract class name
name - can be null, in which case it'll only match to the unnamed component.
Returns:
null if no such service exists.

getByType

<T> T getByType(Class<T> implType)
Gets the object of the given type.

Returns:
null if not found.

getByType

<T> T getByType(String implType)
Gets the object of the given type.

Returns:
null if not found.

getProvider

<T> Inhabitant<T> getProvider(Type type,
                              String name)
Gets an inhabitant from its type and optionally name

Parameters:
type - requested inhabitant type
name - optional name

getProvider

<T> Inhabitant<T> getProvider(String fqcn,
                              String name)

getInhabitantsByContract

<T> Collection<Inhabitant<T>> getInhabitantsByContract(Type contract)
                                                   throws ComponentException
Gets all the inhabitants that has the given contract.

Throws:
ComponentException

getInhabitantsByContract

<T> Collection<Inhabitant<T>> getInhabitantsByContract(String contractName)
                                                   throws ComponentException
Throws:
ComponentException

getInhabitantsByType

<T> Collection<Inhabitant<T>> getInhabitantsByType(Class<T> type)
                                               throws ComponentException
Gets all the inhabitants that has the given type.

Throws:
ComponentException

getInhabitantsByType

<T> Collection<Inhabitant<T>> getInhabitantsByType(String typeName)
                                               throws ComponentException
Throws:
ComponentException


Copyright © 2011 Oracle Corporation. All Rights Reserved.