Interface IAdaptable
-
- All Known Implementing Classes:
AdapterStore
public interface IAdaptableAnIAdaptableallows to register and retrieve adapters under a givenAdapterKey, which combines aTypeToken-based type key and aString-based role.The combination of a type key with a role (by means of an
AdapterKey) allows to register multiple adapters with the same type under different roles. If there is only one adapter for specific type, it can easily be registered and retrieved without specifying a role, or by using the 'default' role (AdapterKey.DEFAULT_ROLE).Using a
TypeToken-based type key instead of a simpleClass-based type key, anIAdaptableallows to register and retrieve adapters also via parameterized types (e.g. by usingnew TypeToken<Provider<IGeometry>>(){}as a type key). For convenience, non-parameterized types can also be registered and retrieved via a rawClasstype key (aTypeTokenwill internally be computed for it usingTypeToken.of(Class)).If a to be registered adapter implements the
IAdaptable.Boundinterface, it is expected that theIAdaptable, on which the adapter is registered, binds itself to the adapter viaIAdaptable.Bound.setAdaptable(IAdaptable)during registration, and accordingly unbinds itself from the adapter (setAdaptable(null)) during un-registration.Any client implementing this interface may internally use an
AdaptableSupportas a delegate to realize the required functionality.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceIAdaptable.Bound<A extends IAdaptable>To be implemented by an adapter to indicate that it intends to be bounded to the respectiveIAdaptableit is registered at.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringADAPTERS_PROPERTYThe name of theadapters property.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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.<T> TgetAdapter(TypeToken<T> key)Returns an adapter for the givenTypeTokenkey if one can unambiguously be retrieved.<T> TgetAdapter(java.lang.Class<T> key)Returns an adapter for the givenClasskey if one can unambiguously be retrieved.<T> TgetAdapter(AdapterKey<T> key)Returns an adapter for the givenAdapterKeyif one can unambiguously be retrieved, i.e. if there is only a single adapter that 'matches' the givenAdapterKey.<T> AdapterKey<T>getAdapterKey(T adapter)Returns the key under which the given adapter is bound.javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object>getAdapters()Returns an unmodifiableObservableMapthat contains the registered adapters by their keys.<T> java.util.Map<AdapterKey<? extends T>,T>getAdapters(TypeToken<? super T> key)Returns all adapters 'matching' the givenTypeTokenkey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type or of the givenTypeTokenkey.<T> java.util.Map<AdapterKey<? extends T>,T>getAdapters(java.lang.Class<? super T> key)Returns all adapters 'matching' the givenClasskey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey.<T> voidsetAdapter(TypeToken<T> adapterType, T adapter)Registers the given adapter under the 'default' role (seeAdapterKey.DEFAULT_ROLE.<T> voidsetAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)Registers the given adapter under the given role.<T> voidsetAdapter(T adapter)Registers the given adapter under anAdapterKey, which takes the given raw type key as well as the 'default' role (seeAdapterKey.DEFAULT_ROLE.<T> voidsetAdapter(T adapter, java.lang.String role)Registers the given adapter under the given role .<T> voidunsetAdapter(T adapter)Unregisters the given adapter under all keys it was registered for.
-
-
-
Field Detail
-
ADAPTERS_PROPERTY
static final java.lang.String ADAPTERS_PROPERTY
The name of theadapters property.- See Also:
- Constant Field Values
-
-
Method Detail
-
adaptersProperty
javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty()
Returns an unmodifiable read-only map property that contains the registered adapters by their keys.- Returns:
- An unmodifiable read-only map property.
-
getAdapter
<T> T getAdapter(AdapterKey<T> key)
Returns an adapter for the givenAdapterKeyif one can unambiguously be retrieved, i.e. if there is only a single adapter that 'matches' the givenAdapterKey.An adapter 'matching' the
AdapterKeyis an adapter, which is registered with anAdapterKey, whoseTypeTokenkey (AdapterKey.getKey()) refers to the same type or a sub-type of the givenAdapterKey'sTypeTokenkey and whose role (AdapterKey.getRole())) equals the role of the givenAdapterKey's role.If there is more than one adapter that 'matches' the given
AdapterKey, or there is no one 'matching' it,nullwill be returned.- Type Parameters:
T- The adapter type.- Parameters:
key- TheAdapterKeyused to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
AdapterKeyornullif none could be retrieved.
-
getAdapter
<T> T getAdapter(java.lang.Class<T> key)
Returns an adapter for the givenClasskey if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenClasskey, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()).An adapter 'matching' the
Classkey is an adapter, which is registered with anAdapterKey, whose key (AdapterKey.getKey()) refers to the same type or a sub-type of the givenClasskey.If there is more than one adapter that 'matches' the given
Classkey, 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 returnnull.- Type Parameters:
T- The adapter type.- Parameters:
key- TheClasskey used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
Classkey ornullif none could be retrieved.
-
getAdapter
<T> T getAdapter(TypeToken<T> key)
Returns an adapter for the givenTypeTokenkey if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenTypeTokenkey, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()).An adapter 'matching' the
TypeTokenkey is an adapter, which is registered with anAdapterKey, whose key (AdapterKey.getKey()) refers to the same type or a sub-type of the given type key.If there is more than one adapter that 'matches' the given
TypeTokenkey, 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 returnnull.
-
getAdapterKey
<T> AdapterKey<T> getAdapterKey(T adapter)
Returns the key under which the given adapter is bound.- Type Parameters:
T- The adapter type.- Parameters:
adapter- The adapter whose key to retrieve.- Returns:
- The
AdapterKeyunder which the respective adapter is bound, ornullif the adapter is not registered.
-
getAdapters
javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> getAdapters()
Returns an unmodifiableObservableMapthat contains the registered adapters by their keys.- Returns:
- An unmodifiable
ObservableMap.
-
getAdapters
<T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(java.lang.Class<? super T> key)
Returns all adapters 'matching' the givenClasskey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey.- Type Parameters:
T- The adapter type.- Parameters:
key- TheClasskey to retrieve adapters for.- Returns:
- A
Mapcontaining all those adapters registered at thisIAdaptable, whoseAdapterKey'sTypeTokenkey (AdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey, qualified by their respectiveAdapterKeys. - See Also:
getAdapter(Class)
-
getAdapters
<T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(TypeToken<? super T> key)
Returns all adapters 'matching' the givenTypeTokenkey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type or of the givenTypeTokenkey.- Type Parameters:
T- The adapter type.- Parameters:
key- TheTypeTokenkey to retrieve adapters for.- Returns:
- A
Mapcontaining all those adapters registered at thisIAdaptable, whoseAdapterKey'sTypeTokenkey (AdapterKey.getKey()) refers to the same or a sub-type of the givenTypeTokenkey, qualified by their respectiveAdapterKeys. - See Also:
getAdapter(TypeToken)
-
setAdapter
<T> void setAdapter(T adapter)
Registers the given adapter under anAdapterKey, which takes the given raw type key as well as the 'default' role (seeAdapterKey.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 thisIAdaptablevia itsIAdaptable.Bound.setAdaptable(IAdaptable)method.- Type Parameters:
T- The adapter type.- Parameters:
adapter- The adapter to register under the givenClasskey.- See Also:
setAdapter(Object, String)
-
setAdapter
<T> void setAdapter(T adapter, java.lang.String role)Registers the given adapter under the given role .- Type Parameters:
T- The adapter type.- Parameters:
adapter- The adapter to register.role- The role to register this adapter with.- See Also:
setAdapter(TypeToken, Object)
-
setAdapter
<T> void setAdapter(TypeToken<T> adapterType, T adapter)
Registers the given adapter under the 'default' role (seeAdapterKey.DEFAULT_ROLE.If the given adapter implements
IAdaptable.Bound, the adapter will obtain a back-reference to thisIAdaptablevia itsIAdaptable.Bound.setAdaptable(IAdaptable)method.- Type Parameters:
T- The adapter type.- Parameters:
adapterType- TheTypeTokenunder which to register the given adapter, which should reflect the actual adapter type.adapter- The adapter to register under the givenTypeTokenkey.- See Also:
setAdapter(TypeToken, Object, String)
-
setAdapter
<T> void setAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)
Registers the given adapter under the given role.If the given adapter implements
IAdaptable.Bound, the adapter will obtain a back-reference to thisIAdaptablevia itsIAdaptable.Bound.setAdaptable(IAdaptable)method.- Type Parameters:
T- The adapter type.- Parameters:
adapterType- ATypeTokenrepresenting the actual type of the given adapter.adapter- The adapter to register.role- The role under which to register the adapter.
-
unsetAdapter
<T> void unsetAdapter(T adapter)
Unregisters the given adapter under all keys it was registered for.If the given adapter implements
IAdaptable.Bound, the back-reference to thisIAdaptablewill be removed via itsIAdaptable.Bound.setAdaptable(IAdaptable)method, passing overnull.- Type Parameters:
T- The adapter type.- Parameters:
adapter- The adapter which should be removed.
-
-