Package org.openhab.core.thing.binding
Class BaseThingHandlerFactory
java.lang.Object
org.openhab.core.thing.binding.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 Summary
Fields - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate(org.osgi.service.component.ComponentContext componentContext) Initializes theBaseThingHandlerFactory.protected abstract @Nullable ThingHandlercreateHandler(Thing thing) Creates aThingHandlerfor the given thing.@Nullable ThingcreateThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) Creates a thing based on given thing type uid.protected @Nullable ThingcreateThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID) Creates a thing based on given thing type uid.protected voiddeactivate(org.osgi.service.component.ComponentContext componentContext) Disposes theBaseThingHandlerFactory.protected org.osgi.framework.BundleContextGet the bundle context.protected @Nullable ConfigDescriptionRegistryprotected @Nullable ThingTypegetThingTypeByUID(ThingTypeUID thingTypeUID) Returns theThingTypewhich is represented by the givenThingTypeUID.registerHandler(Thing thing) Creates a newThingHandlerinstance.protected voidremoveHandler(ThingHandler thingHandler) This method is called when a thing handler should be removed.voidremoveThing(ThingUID thingUID) A thing with the givenThingUID was removed.voidunregisterHandler(Thing thing) Unregisters aThingHandlerinstance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openhab.core.thing.binding.ThingHandlerFactory
supportsThingType 
- 
Field Details
- 
bundleContext
@NonNullByDefault({}) protected org.osgi.framework.BundleContext bundleContext 
 - 
 - 
Constructor Details
- 
BaseThingHandlerFactory
public BaseThingHandlerFactory() 
 - 
 - 
Method Details
- 
activate
protected void activate(org.osgi.service.component.ComponentContext componentContext) Initializes theBaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must callsuper.activate(componentContext)first.- Parameters:
 componentContext- component context (must not be null)
 - 
deactivate
protected void deactivate(org.osgi.service.component.ComponentContext componentContext) Disposes theBaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must callsuper.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
 - 
registerHandler
Description copied from interface:ThingHandlerFactoryCreates a newThingHandlerinstance. In addition, the handler can be registered as a service if it is required, e.g. asFirmwareUpdateHandler,ConfigStatusProvider.This method is only called if the
ThingHandlerFactorysupports the type of the given thing.The framework expects this method to be non-blocking and return quickly.
- Specified by:
 registerHandlerin interfaceThingHandlerFactory- Parameters:
 thing- the thing for which a new handler must be registered- Returns:
 - the created thing handler instance, not null
 
 - 
createHandler
Creates aThingHandlerfor the given thing.- Parameters:
 thing- the thing- Returns:
 - thing the created handler
 
 - 
unregisterHandler
Description copied from interface:ThingHandlerFactoryUnregisters aThingHandlerinstance.The framework expects this method to be non-blocking and return quickly.
- Specified by:
 unregisterHandlerin interfaceThingHandlerFactory- Parameters:
 thing- the thing for which the handler must be unregistered
 - 
removeHandler
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
 - 
removeThing
Description copied from interface:ThingHandlerFactoryA thing with the givenThingUID was removed.- Specified by:
 removeThingin interfaceThingHandlerFactory- Parameters:
 thingUID- thing UID of the removed object
 - 
getThingTypeByUID
Returns theThingTypewhich is represented by the givenThingTypeUID.- 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:
 createThingin interfaceThingHandlerFactory- 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)
 
 - 
getConfigDescriptionRegistry
 
 -