Class BaseThingHandlerFactory

  • All Implemented Interfaces:
    ThingHandlerFactory

    @NonNullByDefault
    public abstract class BaseThingHandlerFactory
    extends Object
    implements ThingHandlerFactory
    The BaseThingHandlerFactory provides a base implementation for the ThingHandlerFactory interface.

    It is recommended to extend this abstract base class, because it covers a lot of common logic.

    Author:
    Dennis Nobel - Initial contribution, Benedikt Niehues - fix for Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=445137 considering default values, Thomas Höfer - added config status provider and firmware update handler service registration, Stefan Bußweiler - API changes due to bridge/thing life cycle refactoring, removed OSGi service registration for thing handlers
    • Field Detail

      • bundleContext

        @NonNullByDefault({})
        protected org.osgi.framework.BundleContext bundleContext
    • Constructor Detail

      • BaseThingHandlerFactory

        public BaseThingHandlerFactory()
    • Method Detail

      • activate

        protected void activate​(org.osgi.service.component.ComponentContext componentContext)
        Initializes the BaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must call super.activate(componentContext) first.
        Parameters:
        componentContext - component context (must not be null)
      • deactivate

        protected void deactivate​(org.osgi.service.component.ComponentContext componentContext)
        Disposes the BaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must call super.deactivate(componentContext) first.
        Parameters:
        componentContext - component context (must not be null)
      • getBundleContext

        protected org.osgi.framework.BundleContext getBundleContext()
        Get the bundle context.
        Returns:
        the bundle context
        Throws:
        IllegalArgumentException - if the bundle thing handler is not active
      • createHandler

        protected abstract @Nullable ThingHandler createHandler​(Thing thing)
        Creates a ThingHandler for the given thing.
        Parameters:
        thing - the thing
        Returns:
        thing the created handler
      • unregisterHandler

        public void unregisterHandler​(Thing thing)
        Description copied from interface: ThingHandlerFactory
        Unregisters a ThingHandler instance.

        The framework expects this method to be non-blocking and return quickly.

        Specified by:
        unregisterHandler in interface ThingHandlerFactory
        Parameters:
        thing - the thing for which the handler must be unregistered
      • removeHandler

        protected void removeHandler​(ThingHandler thingHandler)
        This method is called when a thing handler should be removed. The implementing caller can override this method to release specific resources.
        Parameters:
        thingHandler - thing handler to be removed
      • getThingTypeByUID

        protected @Nullable ThingType getThingTypeByUID​(ThingTypeUID thingTypeUID)
        Returns the ThingType which is represented by the given ThingTypeUID.
        Parameters:
        thingTypeUID - the unique id of the thing type
        Returns:
        the thing type represented by the given unique id
      • createThing

        protected @Nullable Thing createThing​(ThingTypeUID thingTypeUID,
                                              Configuration configuration,
                                              ThingUID thingUID)
        Creates a thing based on given thing type uid.
        Parameters:
        thingTypeUID - thing type uid (can not be null)
        configuration - (can not be null)
        thingUID - thingUID (can not be null)
        Returns:
        thing (can be null, if thing type is unknown)
      • createThing

        public @Nullable Thing createThing​(ThingTypeUID thingTypeUID,
                                           Configuration configuration,
                                           @Nullable ThingUID thingUID,
                                           @Nullable ThingUID bridgeUID)
        Creates a thing based on given thing type uid.
        Specified by:
        createThing in interface ThingHandlerFactory
        Parameters:
        thingTypeUID - thing type uid (must not be null)
        thingUID - thingUID (can be null)
        configuration - (must not be null)
        bridgeUID - (can be null)
        Returns:
        thing (can be null, if thing type is unknown)