public class Service extends Object
API for retrieving a service from an object. Services
remove the need for a class to directly implement an interface;
instead a class can implement the Service.Provider inner
interface. This makes it possible to "decorate" another
generic class - like RenderKit - without needing to know
in advance what optional interfaces the decorated object
might implement, or to even switch on and off implementations
dynamically. A developer can still choose to directly
implement an interface. The getService(java.lang.Object, java.lang.Class<T>)
method
supports both direct implementation and the use of
the Service.Provider interface.
RenderKit rk = facesContext.getRenderKit(); // Retrieve the DialogService generically. DialogService service = (DialogService) ServiceUtils.getService(rk, DialogService.class);
Modifier and Type | Class and Description |
---|---|
static interface |
Service.Provider
Inner interface that should be implemented if a class needs to
provide services other than by the default approach.
|
Constructor and Description |
---|
Service() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
getRenderKitService(javax.faces.context.FacesContext context,
Class<T> serviceClass)
A convenience for retrieving a service from the current RenderKit.
|
static <T> T |
getService(Object from,
Class<T> serviceClass)
Returns a service that can be cast to the provided serviceClass,
as vended by the
from object. |
public static <T> T getService(Object from, Class<T> serviceClass)
from
object. If the class
implements Provider, its getService()
method will
be used. Otherwise, the default behavior will be to see
if from
is an instance of serviceClass
,
and return it if it is.from
- the object that is vending the serviceserviceClass
- the type of object that must be returnedserviceClass
, or null
if no such object could be locatedpublic static <T> T getRenderKitService(javax.faces.context.FacesContext context, Class<T> serviceClass)
Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.