public abstract class Lookup extends Object
Lookup.getDefault()
is strongly encouraged to support
Lookups.metaInfServices(java.lang.ClassLoader)
for registration in addition to whatever
else it decides to support).
For a general talk about the idea behind the lookup pattern please see
AbstractLookup
,
Lookups
,
LookupListener
,
LookupEvent
Modifier and Type | Class and Description |
---|---|
static class |
Lookup.Item<T>
A single item in a lookup result.
|
static interface |
Lookup.Provider
Objects implementing interface Lookup.Provider are capable of
and willing to provide a lookup (usually bound to the object).
|
static class |
Lookup.Result<T>
Result of a lookup request.
|
static class |
Lookup.Template<T>
Template defining a pattern to filter instances by.
|
Modifier and Type | Field and Description |
---|---|
static Lookup |
EMPTY
A dummy lookup that never returns any results.
|
Constructor and Description |
---|
Lookup()
Empty constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
static Lookup |
getDefault()
Static method to obtain the global lookup in the whole system.
|
abstract <T> T |
lookup(Class<T> clazz)
Look up an object matching a given interface.
|
abstract <T> Lookup.Result<T> |
lookup(Lookup.Template<T> template)
The general lookup method.
|
<T> Collection<? extends T> |
lookupAll(Class<T> clazz)
Find all instances corresponding to a given class.
|
<T> Lookup.Item<T> |
lookupItem(Lookup.Template<T> template)
Look up the first item matching a given template.
|
<T> Lookup.Result<T> |
lookupResult(Class<T> clazz)
Find a result corresponding to a given class.
|
public static final Lookup EMPTY
public static Lookup getDefault()
Lookups.metaInfServices(java.lang.ClassLoader)
with the context classloader of the first caller. Each system is
adviced to honor this and include some form of metaInfServices
implementation in the returned lookup as usage of META-INF/services
is a JDK standard.ServiceProvider
public abstract <T> T lookup(Class<T> clazz)
clazz
- class of the object we are searching fornull
if no such
implementation is foundpublic abstract <T> Lookup.Result<T> lookup(Lookup.Template<T> template)
template
, request more info about
them in form of Lookup.Item
and attach a listener to
this be notified about changes. The general interface does not
specify whether subsequent calls with the same template produce new
instance of the Lookup.Result
or return shared instance. The
prefered behaviour however is to return shared one.template
- a template describing the services to look forpublic <T> Lookup.Item<T> lookupItem(Lookup.Template<T> template)
template
- the template to checknull
public <T> Lookup.Result<T> lookupResult(Class<T> clazz)
Lookup.lookup(Lookup.Template)
but slightly more convenient.
Subclasses may override this method to produce the same semantics more efficiently.clazz
- the supertype of the resultpublic <T> Collection<? extends T> lookupAll(Class<T> clazz)
Lookup.lookupResult(java.lang.Class<T>)
and asking for Lookup.Result.allInstances()
but slightly more convenient.
Subclasses may override this method to produce the same semantics more efficiently.
Example usage:
for (MyService svc : Lookup.getDefault().lookupAll(MyService.class)) { svc.useMe(); }
clazz
- the supertype of the result