org.glassfish.hk2
Interface Locator

All Known Subinterfaces:
Services

public interface Locator

This contract provides the starting point for querying HK2's backing service registry either by contract (e.g., classes annotated with @Contract) or by concrete service type (e.g., classes annotated with @Service).

Typically, DI is used to wire services together. Hk2 internals uses the Locator to resolve services used with @Inject during normal dependency injection.

The Locator interface can also be used for programmatic resolution of services. Note, however, that it is recommended for most developers to avoid programmatic service resolution, and to instead rely upon DI wherever possible.

Author:
Jerome Dochez, Jeff Trent, Mason Taube

Method Summary
<U> ServiceLocator<U>
byType(java.lang.Class<U> type)
          Retrieve a service locator via a concrete service class type.
 ServiceLocator<?> byType(java.lang.String typeName)
          See forContract(Class), with the exception that the type is provided as a string instead of a class instance.
<U> ContractLocator<U>
forContract(java.lang.Class<U> contract)
          Retrieve a service locator via a contract class.
 ContractLocator<?> forContract(java.lang.String contractName)
          See forContract(Class), with the exception that the type is provided as a string instead of a class instance.
<U> ContractLocator<U>
forContract(TypeLiteral<U> typeLiteral)
          See forContract(Class), with the exception that the type is a TypeLiteral, a parameterized type.
 

Method Detail

forContract

<U> ContractLocator<U> forContract(java.lang.Class<U> contract)
Retrieve a service locator via a contract class.
 // ExampleContract is an example of a contract type
 @Contract
 public interface ExampleContract {
 }
  
 @Service
 public class Example implements ExampleContract {
 } 
 

Parameters:
contract - the contract class
Returns:
a contract locator

forContract

ContractLocator<?> forContract(java.lang.String contractName)
See forContract(Class), with the exception that the type is provided as a string instead of a class instance.

Parameters:
contractName - the contract class type name
Returns:
a contract locator

forContract

<U> ContractLocator<U> forContract(TypeLiteral<U> typeLiteral)
See forContract(Class), with the exception that the type is a TypeLiteral, a parameterized type.

Parameters:
typeLiteral - the parameterized contract type literal name
Returns:
a contract locator

byType

<U> ServiceLocator<U> byType(java.lang.Class<U> type)
Retrieve a service locator via a concrete service class type.
 // Example is an example of a service type
 @Service
 public class Example ... {
 } 
 

Parameters:
type - the service class type
Returns:
a service locator

byType

ServiceLocator<?> byType(java.lang.String typeName)
See forContract(Class), with the exception that the type is provided as a string instead of a class instance.

Parameters:
typeName - the service class type name
Returns:
a service locator


Copyright © 2011 Oracle Corporation. All Rights Reserved.