Search in sources :

Example 1 with ConfigDescriptionValidator

use of org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator in project smarthome by eclipse.

the class BaseThingHandler method setBundleContext.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setBundleContext(final BundleContext bundleContext) {
    this.bundleContext = bundleContext;
    thingRegistryServiceTracker = new ServiceTracker(this.bundleContext, ThingRegistry.class.getName(), null) {

        @Override
        public Object addingService(@Nullable final ServiceReference reference) {
            thingRegistry = (ThingRegistry) bundleContext.getService(reference);
            return thingRegistry;
        }

        @Override
        public void removedService(@Nullable final ServiceReference reference, @Nullable final Object service) {
            synchronized (BaseThingHandler.this) {
                thingRegistry = null;
            }
        }
    };
    thingRegistryServiceTracker.open();
    thingTypeRegistryServiceTracker = new ServiceTracker(this.bundleContext, ThingTypeRegistry.class.getName(), null) {

        @Override
        public Object addingService(@Nullable final ServiceReference reference) {
            thingTypeRegistry = (ThingTypeRegistry) bundleContext.getService(reference);
            return thingTypeRegistry;
        }

        @Override
        public void removedService(@Nullable final ServiceReference reference, @Nullable final Object service) {
            synchronized (BaseThingHandler.this) {
                thingTypeRegistry = null;
            }
        }
    };
    thingTypeRegistryServiceTracker.open();
    configDescriptionValidatorServiceTracker = new ServiceTracker(this.bundleContext, ConfigDescriptionValidator.class.getName(), null) {

        @Override
        public Object addingService(@Nullable final ServiceReference reference) {
            configDescriptionValidator = (ConfigDescriptionValidator) bundleContext.getService(reference);
            return configDescriptionValidator;
        }

        @Override
        public void removedService(@Nullable final ServiceReference reference, @Nullable final Object service) {
            synchronized (BaseThingHandler.this) {
                configDescriptionValidator = null;
            }
        }
    };
    configDescriptionValidatorServiceTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ConfigDescriptionValidator(org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator) ThingTypeRegistry(org.eclipse.smarthome.core.thing.type.ThingTypeRegistry) ServiceReference(org.osgi.framework.ServiceReference) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry)

Aggregations

ConfigDescriptionValidator (org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator)1 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)1 ThingTypeRegistry (org.eclipse.smarthome.core.thing.type.ThingTypeRegistry)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1