public class AdapterStore extends java.lang.Object implements IAdaptable
AdapterStore
is a basic IAdaptable
implementation that can
be used standalone.Type | Property and Description |
---|---|
javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> |
adapters
Returns an unmodifiable read-only map property that contains the
registered adapters by their keys.
|
IAdaptable.Bound<A extends IAdaptable>
ADAPTERS_PROPERTY
Constructor and Description |
---|
AdapterStore()
Creates a new
AdapterStore with no initial adapters. |
AdapterStore(T adapter)
Creates a new AdapterStore with the single given initial adapter, using
the 'default' role.
|
AdapterStore(com.google.common.reflect.TypeToken<T> adapterType,
T adapter)
Creates a new AdapterStore with the single given initial adapter, using
the 'default' role.
|
AdapterStore(com.google.common.reflect.TypeToken<T> adapterType,
T adapter,
java.lang.String role)
Creates a new AdapterStore with the single given initial adapter.
|
Modifier and Type | Method and Description |
---|---|
javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> |
adaptersProperty()
Returns an unmodifiable read-only map property that contains the
registered adapters by their keys.
|
void |
clear()
Removes all registered adapters from this
AdapterStore . |
<T> T |
getAdapter(AdapterKey<T> key)
Returns an adapter for the given
AdapterKey if one can
unambiguously be retrieved, i.e. if there is only a single adapter that
'matches' the given AdapterKey . |
<T> T |
getAdapter(java.lang.Class<T> key)
Returns an adapter for the given
Class key if one can
unambiguously be retrieved. |
<T> T |
getAdapter(com.google.common.reflect.TypeToken<T> key)
Returns an adapter for the given
TypeToken key if one can
unambiguously be retrieved. |
javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> |
getAdapters()
Gets the value of the property adapters.
|
<T> java.util.Map<AdapterKey<? extends T>,T> |
getAdapters(java.lang.Class<? super T> key)
Returns all adapters 'matching' the given
Class key, i.e. all
adapters whose AdapterKey 's TypeToken key
AdapterKey.getKey() ) refers to the same or a sub-type of the
given Class key (see TypeToken.isAssignableFrom(Type) ). |
<T> java.util.Map<AdapterKey<? extends T>,T> |
getAdapters(com.google.common.reflect.TypeToken<? super T> key)
Returns all adapters 'matching' the given
TypeToken key, i.e. all
adapters whose AdapterKey 's TypeToken key
AdapterKey.getKey() ) refers to the same or a sub-type or of the
given TypeToken key (see
TypeToken.isAssignableFrom(TypeToken) ). |
<T> void |
setAdapter(T adapter)
Registers the given adapter under an
AdapterKey , which takes the
given raw type key as well as the 'default' role (see
AdapterKey.DEFAULT_ROLE . |
<T> void |
setAdapter(T adapter,
java.lang.String role)
Registers the given adapter under the given role .
|
<T> void |
setAdapter(com.google.common.reflect.TypeToken<T> adapterType,
T adapter)
Registers the given adapter under the 'default' role (see
AdapterKey.DEFAULT_ROLE . |
<T> void |
setAdapter(com.google.common.reflect.TypeToken<T> adapterType,
T adapter,
java.lang.String role)
Registers the given adapter under the given role.
|
<T> void |
unsetAdapter(T adapter)
Unregisters the given adapter under all keys it was registered for.
|
public javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty
adaptersProperty
in interface IAdaptable
getAdapters()
public AdapterStore()
AdapterStore
with no initial adapters.public AdapterStore(T adapter)
T
- The adapter type.adapter
- The adapter to be registered.public AdapterStore(com.google.common.reflect.TypeToken<T> adapterType, T adapter)
T
- The adapter type.adapterType
- The runtime type of the adapter to be registered.adapter
- The adapter to be registered.public AdapterStore(com.google.common.reflect.TypeToken<T> adapterType, T adapter, java.lang.String role)
T
- The adapter type.adapterType
- The runtime type of the adapter to be registered.adapter
- The adapter to be registered.role
- The role under which the adapter is to be registered.public <T> T getAdapter(AdapterKey<T> key)
IAdaptable
AdapterKey
if one can
unambiguously be retrieved, i.e. if there is only a single adapter that
'matches' the given AdapterKey
.
An adapter 'matching' the AdapterKey
is an adapter, which is
registered with an AdapterKey
, whose TypeToken
key (
AdapterKey.getKey()
) refers to the same type or a sub-type of the
given AdapterKey
's TypeToken
key (@see
TypeToken.isAssignableFrom(TypeToken)
and whose role (
AdapterKey.getRole()
)) equals the role of the given
AdapterKey
's role.
If there is more than one adapter that 'matches' the given
AdapterKey
, or there is no one 'matching' it, null
will be returned.
getAdapter
in interface IAdaptable
T
- The adapter type.key
- The AdapterKey
used to retrieve a registered adapter.AdapterKey
or null
if none could be
retrieved.public <T> T getAdapter(java.lang.Class<T> key)
IAdaptable
Class
key if one can
unambiguously be retrieved. That is, if there is only a single adapter
that 'matches' the given Class
key, this adapter is returned,
ignoring the role under which it is registered (see
AdapterKey.getRole()
).
An adapter 'matching' the Class
key is an adapter, which is
registered with an AdapterKey
, whose key (
AdapterKey.getKey()
) refers to the same type or a sub-type of the
given Class
key (see TypeToken.isAssignableFrom(Type)
).
If there is more than one adapter that 'matches' the given Class
key, it will return the single adapter that is registered for the default
role (AdapterKey.DEFAULT_ROLE
), if there is a single adapter for
which this holds. Otherwise it will return null
.
getAdapter
in interface IAdaptable
T
- The adapter type.key
- The Class
key used to retrieve a registered adapter.Class
key or null
if none could be retrieved.public <T> T getAdapter(com.google.common.reflect.TypeToken<T> key)
IAdaptable
TypeToken
key if one can
unambiguously be retrieved. That is, if there is only a single adapter
that 'matches' the given TypeToken
key, this adapter is returned,
ignoring the role under which it is registered (see
AdapterKey.getRole()
).
An adapter 'matching' the TypeToken
key is an adapter, which is
registered with an AdapterKey
, whose key (
AdapterKey.getKey()
) refers to the same type or a sub-type of the
given type key (see TypeToken.isAssignableFrom(TypeToken)
.
If there is more than one adapter that 'matches' the given
TypeToken
key, it will return the single adapter that is
registered for the default role (AdapterKey.DEFAULT_ROLE
), if
there is a single adapter for which this holds. Otherwise it will return
null
.
getAdapter
in interface IAdaptable
T
- The adapter type.key
- The TypeToken
key used to retrieve a registered
adapter.TypeToken
key or null
if none could be
retrieved.public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(java.lang.Class<? super T> key)
IAdaptable
Class
key, i.e. all
adapters whose AdapterKey
's TypeToken
key
AdapterKey.getKey()
) refers to the same or a sub-type of the
given Class
key (see TypeToken.isAssignableFrom(Type)
).getAdapters
in interface IAdaptable
T
- The adapter type.key
- The Class
key to retrieve adapters for.Map
containing all those adapters registered at this
IAdaptable
, whose AdapterKey
's TypeToken
key (AdapterKey.getKey()
) refers to the same or a
sub-type of the given Class
key, qualified by their
respective AdapterKey
s.IAdaptable.getAdapter(Class)
public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(com.google.common.reflect.TypeToken<? super T> key)
IAdaptable
TypeToken
key, i.e. all
adapters whose AdapterKey
's TypeToken
key
AdapterKey.getKey()
) refers to the same or a sub-type or of the
given TypeToken
key (see
TypeToken.isAssignableFrom(TypeToken)
).getAdapters
in interface IAdaptable
T
- The adapter type.key
- The TypeToken
key to retrieve adapters for.Map
containing all those adapters registered at this
IAdaptable
, whose AdapterKey
's TypeToken
key (AdapterKey.getKey()
) refers to the same or a
sub-type of the given TypeToken
key, qualified by their
respective AdapterKey
s.IAdaptable.getAdapter(TypeToken)
public <T> void unsetAdapter(T adapter)
IAdaptable
If the given adapter implements IAdaptable.Bound
, the
back-reference to this IAdaptable
will be removed via its
IAdaptable.Bound.setAdaptable(IAdaptable)
method, passing over
null
.
unsetAdapter
in interface IAdaptable
T
- The adapter type.adapter
- The adapter which should be removed.public <T> void setAdapter(T adapter)
IAdaptable
AdapterKey
, which takes the
given raw type key as well as the 'default' role (see
AdapterKey.DEFAULT_ROLE
. The adapter may afterwards be retrieved
by any type key 'in between' the given key type and actual raw type. If
the actual type of the parameter is not a raw type but a parameterized
type, it is not legitimate to use this method.
If the given adapter implements IAdaptable.Bound
, the adapter
will obtain a back-reference to this IAdaptable
via its
IAdaptable.Bound.setAdaptable(IAdaptable)
method.
setAdapter
in interface IAdaptable
T
- The adapter type.adapter
- The adapter to register under the given Class
key.IAdaptable.setAdapter(Object, String)
public <T> void setAdapter(com.google.common.reflect.TypeToken<T> adapterType, T adapter)
IAdaptable
AdapterKey.DEFAULT_ROLE
.
If the given adapter implements IAdaptable.Bound
, the adapter
will obtain a back-reference to this IAdaptable
via its
IAdaptable.Bound.setAdaptable(IAdaptable)
method.
setAdapter
in interface IAdaptable
T
- The adapter type.adapterType
- The TypeToken
under which to register the given
adapter, which should reflect the actual adapter type.adapter
- The adapter to register under the given TypeToken
key.IAdaptable.setAdapter(TypeToken, Object, String)
public <T> void setAdapter(T adapter, java.lang.String role)
IAdaptable
setAdapter
in interface IAdaptable
T
- The adapter type.adapter
- The adapter to register.role
- The role to register this adapter with.IAdaptable.setAdapter(TypeToken, Object)
@InjectAdapters public <T> void setAdapter(com.google.common.reflect.TypeToken<T> adapterType, T adapter, java.lang.String role)
IAdaptable
If the given adapter implements IAdaptable.Bound
, the adapter
will obtain a back-reference to this IAdaptable
via its
IAdaptable.Bound.setAdaptable(IAdaptable)
method.
setAdapter
in interface IAdaptable
T
- The adapter type.adapterType
- A TypeToken
representing the actual type of the given
adapter.adapter
- The adapter to register.role
- The role under which to register the adapter.public void clear()
AdapterStore
.public javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty()
IAdaptable
adaptersProperty
in interface IAdaptable
getAdapters()
public javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> getAdapters()
getAdapters
in interface IAdaptable
ObservableMap
.Copyright (c) 2014 itemis AG and others. All rights reserved.