Annotation Type SlingAdapter


@ComponentPropertyType public @interface SlingAdapter
Component Property Type (as defined by OSGi DS 1.4) for Sling Adapters. Takes care of writing the service properties, that can be found as constants in AdapterFactory. The annotated component will be registered as a Sling adapter, using its minimum required configuration.

Due to technical limitations, it is possible to set either of the values to an empty array, in which case the adapter registration will not be picked up by the framework. Extra care must be taken by the developer to ensure that both values will are entered correctly.

If multiple implementations for the same combination of adapter and adaptable are registered, the implementation with the lowest service.ranking-property wins. This property can be set through the use of the ServiceRanking Component Property Type annotation.

The services defined through this annotation will be picked up by the AdapterManager, which is responsible for honoring the service.ranking when multiple matching factories are found.

Warning: It is up to the implementation of the annotated class to handle the adaption properly:

  • It is up to the implementation to always return the same object for the adaptable, or not;
  • It is up to the implementation to handle all combinations of the specified adaptables and adapters;
  • The adaptTo()-method's type-parameter can be used to check the adapter-type requested;
  • If the adaptTo()-method can return null, adapter.condition should be set to indicate this.

For the registration of the other related service properties, see also AdapterCondition and the lesser used AdapterDeprecated.

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<?>[]
    Specifies the adaptables for which this adapter will be called.
    Class<?>[]
    Specifies the adapters for which this adapter will be called, but only if the source adaptable matches any of the specified adaptables.
  • Element Details

    • adaptables

      Class<?>[] adaptables
      Specifies the adaptables for which this adapter will be called. For each adaptable specified, this adapter will be called to request a result of any of the specified adapters.
      Returns:
      The classes that can be used as an adaptable
    • adapters

      Class<?>[] adapters
      Specifies the adapters for which this adapter will be called, but only if the source adaptable matches any of the specified adaptables.
      Returns:
      The classes that this adapter can adapt to