Interface IAdaptable

All Known Implementing Classes:
AdapterStore

public interface IAdaptable
An IAdaptable allows to register and retrieve adapters under a given AdapterKey, which combines a TypeToken-based type key and a String-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 simple Class -based type key, an IAdaptable allows to register and retrieve adapters also via parameterized types (e.g. by using new TypeToken<Provider<IGeometry>>(){} as a type key). For convenience, non-parameterized types can also be registered and retrieved via a raw Class type key (a TypeToken will internally be computed for it using TypeToken.of(Class)).

If a to be registered adapter implements the IAdaptable.Bound interface, it is expected that the IAdaptable, on which the adapter is registered, binds itself to the adapter via IAdaptable.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 AdaptableSupport as a delegate to realize the required functionality.

  • Property Details

  • Field Details

  • Method Details

    • adaptersProperty

      ReadOnlyMapProperty<AdapterKey<?>,Object> adaptersProperty()
      Returns an unmodifiable read-only map property that contains the registered adapters by their keys.
      See Also:
    • getAdapter

      <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.

      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 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.

      Type Parameters:
      T - The adapter type.
      Parameters:
      key - The AdapterKey used to retrieve a registered adapter.
      Returns:
      The unambiguously retrievable adapter for the given AdapterKey or null if none could be retrieved.
    • getAdapter

      <T> T getAdapter(Class<T> key)
      Returns an adapter for the given 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.

      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.

      Type Parameters:
      T - The adapter type.
      Parameters:
      key - The Class key used to retrieve a registered adapter.
      Returns:
      The unambiguously retrievable adapter for the given Class key or null if none could be retrieved.
    • getAdapter

      <T> T getAdapter(TypeToken<T> key)
      Returns an adapter for the given 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.

      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.

      Type Parameters:
      T - The adapter type.
      Parameters:
      key - The TypeToken key used to retrieve a registered adapter.
      Returns:
      The unambiguously retrievable adapter for the given TypeToken key or null if none could be retrieved.
    • 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 AdapterKey under which the respective adapter is bound, or null if the adapter is not registered.
    • getAdapters

      ObservableMap<AdapterKey<?>,Object> getAdapters()
      Returns an unmodifiable ObservableMap that contains the registered adapters by their keys.
      Returns:
      An unmodifiable ObservableMap.
    • getAdapters

      <T> Map<AdapterKey<? extends T>,T> getAdapters(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.
      Type Parameters:
      T - The adapter type.
      Parameters:
      key - The Class key to retrieve adapters for.
      Returns:
      A 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 AdapterKeys.
      See Also:
    • getAdapters

      <T> Map<AdapterKey<? extends T>,T> getAdapters(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.
      Type Parameters:
      T - The adapter type.
      Parameters:
      key - The TypeToken key to retrieve adapters for.
      Returns:
      A 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 AdapterKeys.
      See Also:
    • setAdapter

      <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. 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.

      Type Parameters:
      T - The adapter type.
      Parameters:
      adapter - The adapter to register under the given Class key.
      See Also:
    • setAdapter

      <T> void setAdapter(T adapter, 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

      <T> void setAdapter(TypeToken<T> adapterType, T adapter)
      Registers the given adapter under the 'default' role (see 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.

      Type Parameters:
      T - The adapter type.
      Parameters:
      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.
      See Also:
    • setAdapter

      <T> void setAdapter(TypeToken<T> adapterType, T adapter, 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 this IAdaptable via its IAdaptable.Bound.setAdaptable(IAdaptable) method.

      Type Parameters:
      T - The adapter type.
      Parameters:
      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.
    • 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 this IAdaptable will be removed via its IAdaptable.Bound.setAdaptable(IAdaptable) method, passing over null.

      Type Parameters:
      T - The adapter type.
      Parameters:
      adapter - The adapter which should be removed.