public class Lookup
extends java.lang.Object
This class is a flexible alternative for a mediator. You can register and deregister implementation for services. And also you can lookup them up. Multiple implementations are possible; also notification on service change.
Lookup
can be arranged hierarchical, incl. support for notification.
Modifier and Type | Method and Description |
---|---|
<T> void |
addChangeListener(java.lang.Class<T> name,
LookupListener listener) |
void |
addChangeListener(LookupListener listener) |
<T> T |
createInstance(java.lang.Class<T> clazz)
Creates an instance of the given class by calling a suitable
Inject constructor. |
<T> void |
deregister(java.lang.Class<T> service) |
<T> void |
deregister(T obj,
java.lang.Class<T> service) |
void |
dispose() |
protected void |
firePropertyChange(java.lang.Class<?> name) |
<T> T |
get(java.lang.Class<T> service)
Get the current default implementation of the given service.
|
<T> java.util.List<LookupListener> |
getListeners(java.lang.Class<?> name) |
void |
inject(java.lang.Object instance)
Injects all known service implementation in the given instance.
|
protected void |
inject(java.lang.Object instance,
java.lang.reflect.Method setter) |
<T> java.util.Collection<T> |
lookupAll(java.lang.Class<T> service)
Get all registered implementations for the given service class.
|
<T> void |
register(T o) |
<T> void |
register(T obj,
java.lang.Class<T> service)
Register
|
<T> void |
removeChangeListener(java.lang.Class<?> name,
LookupListener listener) |
void |
removeChangeListener(LookupListener listener) |
protected <T> T |
tryToInject(java.lang.reflect.Constructor<T> ctor) |
public static Lookup DEFAULT
public Lookup()
public Lookup(Lookup parent)
public <T> java.util.Collection<T> lookupAll(java.lang.Class<T> service)
T
- service
- public <T> T get(java.lang.Class<T> service)
T
- service
- public <T> void register(T obj, java.lang.Class<T> service)
T
- obj
- service
- public <T> void deregister(T obj, java.lang.Class<T> service)
public <T> void deregister(java.lang.Class<T> service)
public void dispose()
public <T> java.util.List<LookupListener> getListeners(java.lang.Class<?> name)
public void addChangeListener(LookupListener listener)
public <T> void addChangeListener(java.lang.Class<T> name, LookupListener listener)
public <T> void removeChangeListener(java.lang.Class<?> name, LookupListener listener)
public void removeChangeListener(LookupListener listener)
protected void firePropertyChange(java.lang.Class<?> name)
public <T> void register(T o)
public <T> T createInstance(java.lang.Class<T> clazz) throws InjectionException
Inject
constructor.T
- clazz
- InjectionException
- if non suitable constructors could be found.protected <T> T tryToInject(java.lang.reflect.Constructor<T> ctor) throws InjectionException
T
- ctor
- InjectionException
public void inject(java.lang.Object instance) throws InjectionException
This method searchs for methods single argument methods, that are annotated with Inject
,
and calls it with the service implementation.
instance
- arbitrary non-null methodInjectionException
- is thrown iff a service is unknown but needed for an Inject
method.protected void inject(java.lang.Object instance, java.lang.reflect.Method setter) throws InjectionException
instance
- setter
- InjectionException
Copyright © 2003-2019 The KeY-Project.