listener : listeners) {
- listener.removed(this, getMetadata(itemName));
- }
- }
-
- private Metadata getMetadata(String itemName) {
- return new Metadata(new MetadataKey(AUTOUPDATE_KEY, itemName), "false", null);
- }
-
- @Override
- public void added(Item element) {
- String itemName = element.getName();
- refreshVetoForItem(itemName);
- }
-
- private void refreshVetoForItem(String itemName) {
- synchronized (itemUpdateVetos) {
- boolean removed = itemUpdateVetos.remove(itemName);
- for (AutoUpdateBindingProvider provider : providers) {
- Boolean autoUpdate = provider.autoUpdate(itemName);
- if (Boolean.FALSE.equals(autoUpdate)) {
- itemUpdateVetos.add(itemName);
- notifyAboutAddedMetadata(itemName);
- return;
- }
- }
- if (removed) {
- notifyAboutRemovedMetadata(itemName);
- }
- }
- }
-
- @Override
- public void removed(Item element) {
- itemUpdateVetos.remove(element.getName());
- }
-
- @Override
- public void updated(Item oldElement, Item element) {
- refreshVetoForItem(element.getName());
- }
-
- @Override
- public void bindingChanged(@Nullable BindingProvider provider, @Nullable String itemName) {
- if (itemName != null) {
- refreshVetoForItem(itemName);
- }
- }
-
- @Override
- public void allBindingsChanged(@Nullable BindingProvider provider) {
- refreshItemUpdateVetos();
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractActiveBinding.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractActiveBinding.java
deleted file mode 100644
index cbf8ca525..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractActiveBinding.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding;
-
-import org.openhab.core.service.AbstractActiveService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Base class for active bindings which polls something and sends events frequently.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class AbstractActiveBinding extends AbstractBinding
{
-
- private static final Logger LOGGER = LoggerFactory.getLogger(AbstractActiveBinding.class);
-
- /** embedded active service to allow the binding to have some code executed in a given interval. */
- protected AbstractActiveService activeService = new BindingActiveService();
-
- /**
- * Adds provider
to the list of {@link BindingProvider}s and
- * adds this
as {@link BindingConfigChangeListener}. If
- * provider
contains any binding an the refresh-Thread is
- * stopped it will be started.
- *
- * @param provider the new {@link BindingProvider} to add
- */
- @Override
- public void addBindingProvider(BindingProvider provider) {
- super.addBindingProvider(provider);
- activeService.activate();
- }
-
- /**
- * Removes provider
from the list of providers. If there is no
- * provider left the refresh thread is getting interrupted.
- *
- * @param provider the {@link BindingProvider} to remove
- */
- @Override
- public void removeBindingProvider(BindingProvider provider) {
- super.removeBindingProvider(provider);
-
- // if there are no binding providers there is no need to run this
- // refresh thread any longer ...
- if (this.providers.isEmpty()) {
- activeService.deactivate();
- }
- }
-
- @Override
- public void bindingChanged(BindingProvider provider, String itemName) {
- super.bindingChanged(provider, itemName);
-
- if (bindingsExist()) {
- activeService.activate();
- } else {
- activeService.deactivate();
- }
- }
-
- @Override
- public void allBindingsChanged(BindingProvider provider) {
- super.allBindingsChanged(provider);
-
- if (bindingsExist()) {
- activeService.activate();
- } else {
- activeService.deactivate();
- }
- }
-
- /**
- * Used to define whether this binding is fully configured so that it can be
- * activated and used.
- * Note that the implementation will automatically start the active service if
- * true
is passed as a parameter and there are binding providers available.
- *
- * @param properlyConfigured
- */
- protected void setProperlyConfigured(boolean properlyConfigured) {
- if (!providers.isEmpty()) {
- activeService.setProperlyConfigured(properlyConfigured);
- }
- }
-
- /**
- * @return true
if this binding is configured properly which means
- * that all necessary data is available
- */
- protected boolean isProperlyConfigured() {
- return activeService.isProperlyConfigured();
- }
-
- /**
- * The working method which is called by the refresh thread frequently.
- * Developers should put their binding code here.
- */
- protected abstract void execute();
-
- /**
- * Returns the refresh interval to be used by the RefreshThread between to
- * calls of the execute method.
- *
- * @return the refresh interval
- */
- protected abstract long getRefreshInterval();
-
- /**
- * Returns the name of the Refresh thread.
- *
- * @return the name of the refresh thread.
- */
- protected abstract String getName();
-
- /** private inner class, which delegates method calls to the outer binding instance */
- private class BindingActiveService extends AbstractActiveService {
- @Override
- protected void start() {
- super.start();
- }
-
- @Override
- public void interrupt() {
- if (!bindingsExist()) {
- super.interrupt();
- } else {
- LOGGER.trace("{} won't be interrupted because bindings exist.", getName());
- }
- }
-
- @Override
- protected void execute() {
- AbstractActiveBinding.this.execute();
- }
-
- @Override
- protected long getRefreshInterval() {
- return AbstractActiveBinding.this.getRefreshInterval();
- }
-
- @Override
- protected String getName() {
- return AbstractActiveBinding.this.getName();
- }
-
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractBinding.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractBinding.java
deleted file mode 100644
index c98f40a2b..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/AbstractBinding.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding;
-
-import java.util.Collection;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.openhab.core.events.AbstractEventSubscriber;
-import org.openhab.core.events.EventPublisher;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-
-/**
- * Base class for bindings which send events.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class AbstractBinding
extends AbstractEventSubscriber
- implements BindingChangeListener {
-
- /** to keep track of all binding providers */
-
- protected Collection
providers = new CopyOnWriteArraySet<>();
-
- protected EventPublisher eventPublisher = null;
-
- public void setEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- public void unsetEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = null;
- }
-
- public void activate() {
- };
-
- public void deactivate() {
- };
-
- /**
- * Adds provider
to the list of {@link BindingProvider}s and
- * adds this
as {@link BindingConfigChangeListener}. If
- * provider
contains any binding an the refresh-Thread is
- * stopped it will be started.
- *
- * @param provider the new {@link BindingProvider} to add
- */
- @SuppressWarnings("unchecked")
- public void addBindingProvider(BindingProvider provider) {
- this.providers.add((P) provider);
- provider.addBindingChangeListener(this);
- allBindingsChanged(provider);
- }
-
- /**
- * Removes provider
from the list of providers. If there is no
- * provider left the refresh thread is getting interrupted.
- *
- * @param provider the {@link BindingProvider} to remove
- */
- public void removeBindingProvider(BindingProvider provider) {
- this.providers.remove(provider);
- provider.removeBindingChangeListener(this);
- }
-
- /**
- * @return true
if any of the {@link BindingProvider}s provides
- * a binding
- */
- protected boolean bindingsExist() {
- for (BindingProvider provider : providers) {
- if (provider.providesBinding()) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void receiveCommand(String itemName, Command command) {
- // does any provider contain a binding config?
- if (!providesBindingFor(itemName)) {
- return;
- }
- internalReceiveCommand(itemName, command);
- }
-
- /**
- * Is called by receiveCommand()
only if one of the
- * {@link BindingProvider}s provide a binding for itemName
.
- *
- * @param itemName the item on which command
will be executed
- * @param command the {@link Command} to be executed on itemName
- */
- protected void internalReceiveCommand(String itemName, Command command) {
- };
-
- @Override
- public void receiveUpdate(String itemName, State newState) {
- // does any provider contain a binding config?
- if (!providesBindingFor(itemName)) {
- return;
- }
- internalReceiveUpdate(itemName, newState);
- }
-
- /**
- * Is called by receiveUpdate()
only if one of the
- * {@link BindingProvider}s provide a binding for itemName
.
- *
- * @param itemName the item on which command
will be executed
- * @param newState the {@link State} to be update
- */
- protected void internalReceiveUpdate(String itemName, State newState) {
- };
-
- /**
- * checks if any of the bindingProviders contains an adequate mapping
- *
- * @param itemName the itemName to check
- * @return true
if any of the bindingProviders contains an
- * adequate mapping for itemName
and false
- * otherwise
- */
- protected boolean providesBindingFor(String itemName) {
- for (P provider : providers) {
- if (provider.providesBindingFor(itemName)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void allBindingsChanged(BindingProvider provider) {
- }
-
- @Override
- public void bindingChanged(BindingProvider provider, String itemName) {
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingChangeListener.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingChangeListener.java
deleted file mode 100644
index e60634df2..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingChangeListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding;
-
-/**
- * This interface must be implemented by classes which want to be notified by a
- * {@link BindingProvider} about changes in the binding configuration.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface BindingChangeListener {
-
- /**
- * Called, if a single binding has changed. The given item could have been
- * added or removed.
- *
- * @param provider the binding provider where the binding has changed
- * @param itemName the item name for which the binding has changed
- */
- public void bindingChanged(BindingProvider provider, String itemName);
-
- /**
- * Called, if all bindings (might) have changed.
- *
- * @param provider the binding provider whose bindings have changed
- */
- public void allBindingsChanged(BindingProvider provider);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingConfig.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingConfig.java
deleted file mode 100644
index d25551357..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingConfig.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding;
-
-/**
- * This is a simple marker interface to define data structures that are
- * used as binding configurations.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface BindingConfig {
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingProvider.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingProvider.java
deleted file mode 100644
index 3feffab7a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/BindingProvider.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding;
-
-import java.util.Collection;
-
-/**
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- * @author Kai Kreuzer - Initial contribution
- */
-public interface BindingProvider {
-
- /**
- * Adds a binding change listener, which gets notified whenever there
- * are changes in the binding configuration
- *
- * @param listener the binding change listener to add
- */
- public void addBindingChangeListener(BindingChangeListener listener);
-
- /**
- * Removes a binding change listener again.
- * Does nothing, if this listener has not been added before.
- *
- * @param listener the binding listener to remove
- */
- public void removeBindingChangeListener(BindingChangeListener listener);
-
- /**
- * Indicates whether this binding provider contains a binding for the given
- * itemName
- *
- * @param itemName the itemName to check
- * @return true
if this provider contains an adequate mapping
- * for itemName
and false
otherwise.
- */
- boolean providesBindingFor(String itemName);
-
- /**
- * Indicates whether this binding provider contains any binding
- *
- * @return true
if this provider contains any binding
- * configuration and false
otherwise
- */
- boolean providesBinding();
-
- /**
- * Returns all items which are mapped to this binding
- *
- * @return items which are mapped to this binding
- */
- Collection getItemNames();
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderDelegate.java
deleted file mode 100644
index b038c3908..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderDelegate.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding.internal;
-
-import org.eclipse.smarthome.config.core.Configuration;
-import org.eclipse.smarthome.core.items.ItemUtil;
-import org.eclipse.smarthome.model.item.BindingConfigParseException;
-import org.eclipse.smarthome.model.item.BindingConfigReader;
-
-/**
- * This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
- * namespace for the binding config readers. It wraps an instance with the old interface
- * into a class with the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class BindingConfigReaderDelegate implements BindingConfigReader {
-
- private org.openhab.model.item.binding.BindingConfigReader reader;
-
- public BindingConfigReaderDelegate(org.openhab.model.item.binding.BindingConfigReader reader) {
- this.reader = reader;
- }
-
- @Override
- public String getBindingType() {
- return reader.getBindingType();
- }
-
- @Override
- public void validateItemType(String itemType, String bindingConfig) throws BindingConfigParseException {
- try {
- reader.validateItemType(getOpenHABItem(itemType), bindingConfig);
- } catch (org.openhab.model.item.binding.BindingConfigParseException e) {
- throw new BindingConfigParseException(e.getMessage(), e);
- }
- }
-
- @Override
- public void processBindingConfiguration(String context, String itemType, String itemName, String bindingConfig,
- Configuration configuration) throws BindingConfigParseException {
- try {
- reader.processBindingConfiguration(context, getOpenHABItem(itemType, itemName), bindingConfig);
- } catch (org.openhab.model.item.binding.BindingConfigParseException e) {
- throw new BindingConfigParseException(e.getMessage(), e);
- }
- }
-
- private org.openhab.core.items.Item getOpenHABItem(String itemType) throws BindingConfigParseException {
- return getOpenHABItem(itemType, "itemName");
- }
-
- private org.openhab.core.items.Item getOpenHABItem(String itemType, String itemName)
- throws BindingConfigParseException {
- String mainType = ItemUtil.getMainItemType(itemType);
-
- switch (mainType) {
- case "Group":
- return new org.openhab.core.items.GroupItem(itemName);
- case "Switch":
- return new org.openhab.core.library.items.SwitchItem(itemName);
- case "Dimmer":
- return new org.openhab.core.library.items.DimmerItem(itemName);
- case "Color":
- return new org.openhab.core.library.items.ColorItem(itemName);
- case "String":
- return new org.openhab.core.library.items.StringItem(itemName);
- case "Number":
- return new org.openhab.core.library.items.NumberItem(itemName);
- case "Contact":
- return new org.openhab.core.library.items.ContactItem(itemName);
- case "Rollershutter":
- return new org.openhab.core.library.items.RollershutterItem(itemName);
- case "DateTime":
- return new org.openhab.core.library.items.DateTimeItem(itemName);
- case "Location":
- return new org.openhab.core.library.items.LocationItem(itemName);
- case "Call":
- return new org.openhab.library.tel.items.CallItem(itemName);
- }
- throw new BindingConfigParseException("cannot process unknown item type " + itemType);
- }
-
- @Override
- public void startConfigurationUpdate(String context) {
- reader.removeConfigurations(context);
- }
-
- @Override
- public void stopConfigurationUpdate(String context) {
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderFactory.java
deleted file mode 100644
index a6da0f438..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/binding/internal/BindingConfigReaderFactory.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.binding.internal;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import org.openhab.model.item.binding.BindingConfigReader;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-
-/**
- * This class listens for services that implement the old binding config reader interface and registers
- * an according service for each under the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component
-public class BindingConfigReaderFactory {
-
- private Map> delegates = new HashMap<>();
- private BundleContext context;
-
- private Set readers = new HashSet<>();
-
- @Activate
- public void activate(BundleContext context) {
- this.context = context;
- for (BindingConfigReader reader : readers) {
- registerDelegateService(reader);
- }
- }
-
- @Deactivate
- public void deactivate() {
- for (ServiceRegistration serviceReg : delegates
- .values()) {
- serviceReg.unregister();
- }
- delegates.clear();
- this.context = null;
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void addBindingConfigReader(BindingConfigReader reader) {
- if (context != null) {
- registerDelegateService(reader);
- } else {
- readers.add(reader);
- }
- }
-
- public void removeBindingConfigReader(BindingConfigReader reader) {
- if (context != null) {
- unregisterDelegateService(reader);
- }
- }
-
- private void registerDelegateService(BindingConfigReader reader) {
- if (!delegates.containsKey(reader.getBindingType())) {
- BindingConfigReaderDelegate service = new BindingConfigReaderDelegate(reader);
- Dictionary props = new Hashtable<>();
- ServiceRegistration serviceReg = context
- .registerService(org.eclipse.smarthome.model.item.BindingConfigReader.class, service, props);
- delegates.put(reader.getBindingType(), serviceReg);
- }
- }
-
- private void unregisterDelegateService(BindingConfigReader reader) {
- if (delegates.containsKey(reader.getBindingType())) {
- ServiceRegistration serviceReg = delegates
- .get(reader.getBindingType());
- delegates.remove(reader.getBindingType());
- serviceReg.unregister();
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/CompatibilityActivator.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/CompatibilityActivator.java
deleted file mode 100644
index f4d398768..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/CompatibilityActivator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.compat1x.internal;
-
-import org.eclipse.smarthome.model.script.engine.ScriptEngine;
-import org.openhab.core.events.EventPublisher;
-import org.openhab.core.items.ItemRegistry;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class CompatibilityActivator implements BundleActivator {
-
- private static BundleContext context;
-
- public static ServiceTracker itemRegistryTracker;
- public static ServiceTracker eventPublisherTracker;
- public static ServiceTracker scriptEngineTracker;
-
- public static BundleContext getContext() {
- return context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext bundleContext) throws Exception {
- CompatibilityActivator.context = bundleContext;
-
- itemRegistryTracker = new ServiceTracker<>(bundleContext, ItemRegistry.class, null);
- itemRegistryTracker.open();
-
- eventPublisherTracker = new ServiceTracker<>(bundleContext, EventPublisher.class, null);
- eventPublisherTracker.open();
-
- scriptEngineTracker = new ServiceTracker<>(bundleContext, ScriptEngine.class, null);
- scriptEngineTracker.open();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext bundleContext) throws Exception {
- CompatibilityActivator.context = null;
- itemRegistryTracker.close();
- eventPublisherTracker.close();
- scriptEngineTracker.close();
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/ItemMapper.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/ItemMapper.java
deleted file mode 100644
index 5ca69c73a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/ItemMapper.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.compat1x.internal;
-
-import org.eclipse.smarthome.core.items.GroupItem;
-import org.eclipse.smarthome.core.items.Item;
-import org.eclipse.smarthome.core.library.items.CallItem;
-import org.eclipse.smarthome.core.library.items.ColorItem;
-import org.eclipse.smarthome.core.library.items.ContactItem;
-import org.eclipse.smarthome.core.library.items.DateTimeItem;
-import org.eclipse.smarthome.core.library.items.DimmerItem;
-import org.eclipse.smarthome.core.library.items.NumberItem;
-import org.eclipse.smarthome.core.library.items.RollershutterItem;
-import org.eclipse.smarthome.core.library.items.StringItem;
-import org.eclipse.smarthome.core.library.items.SwitchItem;
-import org.eclipse.smarthome.core.types.State;
-import org.openhab.core.items.GenericItem;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ItemMapper {
-
- public static org.openhab.core.items.Item mapToOpenHABItem(Item item) {
- if (item == null) {
- return null;
- }
-
- org.openhab.core.items.Item result = null;
- Class extends Item> itemClass = item.getClass();
-
- if (itemClass.equals(StringItem.class)) {
- result = new org.openhab.core.library.items.StringItem(item.getName());
- } else if (itemClass.equals(SwitchItem.class)) {
- result = new org.openhab.core.library.items.SwitchItem(item.getName());
- } else if (itemClass.equals(ContactItem.class)) {
- result = new org.openhab.core.library.items.ContactItem(item.getName());
- } else if (itemClass.equals(NumberItem.class)) {
- result = new org.openhab.core.library.items.NumberItem(item.getName());
- } else if (itemClass.equals(RollershutterItem.class)) {
- result = new org.openhab.core.library.items.RollershutterItem(item.getName());
- } else if (itemClass.equals(DimmerItem.class)) {
- result = new org.openhab.core.library.items.DimmerItem(item.getName());
- } else if (itemClass.equals(ColorItem.class)) {
- result = new org.openhab.core.library.items.ColorItem(item.getName());
- } else if (itemClass.equals(DateTimeItem.class)) {
- result = new org.openhab.core.library.items.DateTimeItem(item.getName());
- } else if (itemClass.equals(CallItem.class)) {
- result = new org.openhab.library.tel.items.CallItem(item.getName());
- }
-
- if (item instanceof GroupItem) {
- GroupItem gItem = (GroupItem) item;
-
- org.openhab.core.items.Item baseItem = ItemMapper.mapToOpenHABItem(gItem.getBaseItem());
- org.openhab.core.items.GroupItem ohgItem;
-
- if (baseItem instanceof GenericItem) {
- ohgItem = new org.openhab.core.items.GroupItem(item.getName(), (GenericItem) baseItem);
- } else {
- ohgItem = new org.openhab.core.items.GroupItem(item.getName());
- }
-
- for (Item member : gItem.getMembers()) {
- org.openhab.core.items.Item ohMember = ItemMapper.mapToOpenHABItem(member);
- if (ohMember != null) {
- ohgItem.addMember(ohMember);
- }
- }
- result = ohgItem;
- }
-
- if (result instanceof org.openhab.core.items.GenericItem) {
- org.openhab.core.items.GenericItem genericItem = (GenericItem) result;
- State state = item.getState();
- if (state != null) {
- org.openhab.core.types.State ohState = (org.openhab.core.types.State) TypeMapper
- .mapToOpenHABType(state);
- if (ohState != null) {
- genericItem.setState(ohState);
- }
- }
- }
-
- return result;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/TypeMapper.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/TypeMapper.java
deleted file mode 100644
index ecf46a048..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/compat1x/internal/TypeMapper.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.compat1x.internal;
-
-import java.lang.reflect.Field;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-
-import org.eclipse.smarthome.core.library.types.DateTimeType;
-import org.eclipse.smarthome.core.library.types.DecimalType;
-import org.eclipse.smarthome.core.library.types.HSBType;
-import org.eclipse.smarthome.core.library.types.IncreaseDecreaseType;
-import org.eclipse.smarthome.core.library.types.OnOffType;
-import org.eclipse.smarthome.core.library.types.OpenClosedType;
-import org.eclipse.smarthome.core.library.types.PercentType;
-import org.eclipse.smarthome.core.library.types.PointType;
-import org.eclipse.smarthome.core.library.types.QuantityType;
-import org.eclipse.smarthome.core.library.types.StopMoveType;
-import org.eclipse.smarthome.core.library.types.StringListType;
-import org.eclipse.smarthome.core.library.types.StringType;
-import org.eclipse.smarthome.core.library.types.UpDownType;
-import org.eclipse.smarthome.core.types.Type;
-import org.eclipse.smarthome.core.types.UnDefType;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class TypeMapper {
-
- public static org.openhab.core.types.Type mapToOpenHABType(Type type) {
- if (type == null) {
- return null;
- }
-
- org.openhab.core.types.Type result = org.openhab.core.types.UnDefType.UNDEF;
- Class extends Type> typeClass = type.getClass();
-
- if (type == UnDefType.NULL) {
- result = org.openhab.core.types.UnDefType.NULL;
- } else if (type == UnDefType.UNDEF) {
- result = org.openhab.core.types.UnDefType.UNDEF;
- } else if (type == OnOffType.ON) {
- result = org.openhab.core.library.types.OnOffType.ON;
- } else if (type == OnOffType.OFF) {
- result = org.openhab.core.library.types.OnOffType.OFF;
- } else if (type == OpenClosedType.OPEN) {
- result = org.openhab.core.library.types.OpenClosedType.OPEN;
- } else if (type == OpenClosedType.CLOSED) {
- result = org.openhab.core.library.types.OpenClosedType.CLOSED;
- } else if (type == IncreaseDecreaseType.INCREASE) {
- result = org.openhab.core.library.types.IncreaseDecreaseType.INCREASE;
- } else if (type == IncreaseDecreaseType.DECREASE) {
- result = org.openhab.core.library.types.IncreaseDecreaseType.DECREASE;
- } else if (type == StopMoveType.MOVE) {
- result = org.openhab.core.library.types.StopMoveType.MOVE;
- } else if (type == StopMoveType.STOP) {
- result = org.openhab.core.library.types.StopMoveType.STOP;
- } else if (type == UpDownType.UP) {
- result = org.openhab.core.library.types.UpDownType.UP;
- } else if (type == UpDownType.DOWN) {
- result = org.openhab.core.library.types.UpDownType.DOWN;
- } else if (typeClass.equals(StringType.class)) {
- result = new org.openhab.core.library.types.StringType(type.toString());
- } else if (typeClass.equals(DecimalType.class)) {
- result = new org.openhab.core.library.types.DecimalType(type.toString());
- } else if (typeClass.equals(QuantityType.class)) {
- result = new org.openhab.core.library.types.DecimalType(((QuantityType>) type).toBigDecimal());
- } else if (typeClass.equals(HSBType.class)) {
- result = new org.openhab.core.library.types.HSBType(type.toString());
- } else if (typeClass.equals(PercentType.class)) {
- result = new org.openhab.core.library.types.PercentType(type.toString());
- } else if (typeClass.equals(DateTimeType.class)) {
- result = new org.openhab.core.library.types.DateTimeType(
- GregorianCalendar.from(((DateTimeType) type).getZonedDateTime()));
- } else if (typeClass.equals(PointType.class)) {
- result = new org.openhab.core.library.types.PointType(type.toString());
- } else if (typeClass.equals(StringListType.class)) {
- result = new org.openhab.library.tel.types.CallType(type.toString().replace(",", "##"));
- }
-
- return result;
- }
-
- public static Type mapToESHType(org.openhab.core.types.Type type) {
- if (type == null) {
- return null;
- }
-
- Type result = UnDefType.UNDEF;
- Class extends org.openhab.core.types.Type> typeClass = type.getClass();
-
- if (type == org.openhab.core.types.UnDefType.NULL) {
- result = UnDefType.NULL;
- } else if (type == org.openhab.core.types.UnDefType.UNDEF) {
- result = UnDefType.UNDEF;
- } else if (type == org.openhab.core.library.types.OnOffType.ON) {
- result = OnOffType.ON;
- } else if (type == org.openhab.core.library.types.OnOffType.OFF) {
- result = OnOffType.OFF;
- } else if (type == org.openhab.core.library.types.OpenClosedType.OPEN) {
- result = OpenClosedType.OPEN;
- } else if (type == org.openhab.core.library.types.OpenClosedType.CLOSED) {
- result = OpenClosedType.CLOSED;
- } else if (type == org.openhab.core.library.types.IncreaseDecreaseType.INCREASE) {
- result = IncreaseDecreaseType.INCREASE;
- } else if (type == org.openhab.core.library.types.IncreaseDecreaseType.DECREASE) {
- result = IncreaseDecreaseType.DECREASE;
- } else if (type == org.openhab.core.library.types.StopMoveType.MOVE) {
- result = StopMoveType.MOVE;
- } else if (type == org.openhab.core.library.types.StopMoveType.STOP) {
- result = StopMoveType.STOP;
- } else if (type == org.openhab.core.library.types.UpDownType.UP) {
- result = UpDownType.UP;
- } else if (type == org.openhab.core.library.types.UpDownType.DOWN) {
- result = UpDownType.DOWN;
- } else if (typeClass.equals(org.openhab.core.library.types.StringType.class)) {
- result = new StringType(type.toString());
- } else if (typeClass.equals(org.openhab.core.library.types.DecimalType.class)) {
- result = new DecimalType(type.toString());
- } else if (typeClass.equals(org.openhab.core.library.types.HSBType.class)) {
- result = new HSBType(type.toString());
- } else if (typeClass.equals(org.openhab.core.library.types.PercentType.class)) {
- result = new PercentType(type.toString());
- } else if (typeClass.equals(org.openhab.core.library.types.DateTimeType.class)) {
- result = new DateTimeType(cloneCalendar(type));
- } else if (typeClass.equals(org.openhab.core.library.types.PointType.class)) {
- result = new PointType(type.toString());
- } else if (typeClass.equals(org.openhab.library.tel.types.CallType.class)) {
- result = new StringListType(type.toString().replace("##", ","));
- }
-
- return result;
- }
-
- private static Calendar cloneCalendar(Object type) {
- try {
- Field calField = type.getClass().getDeclaredField("calendar");
- calField.setAccessible(true);
- Calendar cal = (Calendar) calField.get(type);
- return (Calendar) cal.clone();
- } catch (Exception e) {
- return null;
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/AbstractEventSubscriber.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/AbstractEventSubscriber.java
deleted file mode 100644
index a2cbde51c..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/AbstractEventSubscriber.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events;
-
-import static org.openhab.core.events.EventConstants.*;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.EventType;
-import org.openhab.core.types.State;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventHandler;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class AbstractEventSubscriber implements EventHandler {
- @Override
- public void handleEvent(Event event) {
- String itemName = (String) event.getProperty("item");
-
- String topic = event.getTopic();
- String[] topicParts = topic.split(TOPIC_SEPERATOR);
-
- if (!(topicParts.length > 2) || !topicParts[0].equals(TOPIC_PREFIX)) {
- return; // we have received an event with an invalid topic
- }
- String operation = topicParts[1];
-
- if (operation.equals(EventType.UPDATE.toString())) {
- State newState = (State) event.getProperty("state");
- if (newState != null) {
- receiveUpdate(itemName, newState);
- }
- }
- if (operation.equals(EventType.COMMAND.toString())) {
- Command command = (Command) event.getProperty("command");
- if (command != null) {
- receiveCommand(itemName, command);
- }
- }
- }
-
- public void receiveCommand(String itemName, Command command) {
- // default implementation: do nothing
- }
-
- public void receiveUpdate(String itemName, State newState) {
- // default implementation: do nothing
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventConstants.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventConstants.java
deleted file mode 100644
index d508f7815..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventConstants.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events;
-
-/**
- * This interface defines constants required for using the OSGi Event Admin service.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface EventConstants {
-
- public static final String TOPIC_PREFIX = "openhab";
-
- public static final String TOPIC_SEPERATOR = "/";
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisher.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisher.java
deleted file mode 100644
index 6946199bd..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisher.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-
-/**
- * An EventPublisher is used to send commands or status updates to the openHAB event bus.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface EventPublisher {
-
- /**
- * Initiate synchronous sending of a command.
- * This method does not return to the caller until all subscribers have processed the command.
- *
- * @param itemName name of the item to send the command for
- * @param command the command to send
- */
- public abstract void sendCommand(String itemName, Command command);
-
- /**
- * Initiate asynchronous sending of a command.
- * This method returns immediately to the caller.
- *
- * @param itemName name of the item to send the command for
- * @param command the command to send
- */
- public abstract void postCommand(String itemName, Command command);
-
- /**
- * Initiate asynchronous sending of a status update.
- * This method returns immediately to the caller.
- *
- * @param itemName name of the item to send the update for
- * @param newState the new state to send
- */
- public abstract void postUpdate(String itemName, State newState);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisherDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisherDelegate.java
deleted file mode 100644
index ac19a91d9..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventPublisherDelegate.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events;
-
-import org.eclipse.smarthome.core.events.EventPublisher;
-import org.eclipse.smarthome.core.items.events.ItemCommandEvent;
-import org.eclipse.smarthome.core.items.events.ItemEventFactory;
-import org.eclipse.smarthome.core.items.events.ItemStateEvent;
-import org.openhab.core.compat1x.internal.TypeMapper;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component(immediate = true)
-public class EventPublisherDelegate implements org.openhab.core.events.EventPublisher {
-
- private final Logger logger = LoggerFactory.getLogger(EventPublisherDelegate.class);
-
- private EventPublisher eventPublisher;
-
- @Reference
- public void setEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- public void unsetEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = null;
- }
-
- @Override
- public void sendCommand(String itemName, Command command) {
- // we do not offer synchronous sending of commands anymore
- postCommand(itemName, command);
- }
-
- @Override
- public void postCommand(String itemName, Command command) {
- org.eclipse.smarthome.core.types.Command eshCommand = (org.eclipse.smarthome.core.types.Command) TypeMapper
- .mapToESHType(command);
- if (eshCommand != null) {
- ItemCommandEvent event = ItemEventFactory.createCommandEvent(itemName, eshCommand);
- eventPublisher.post(event);
- } else if (command != null) {
- logger.warn("Compatibility layer could not convert {} of type {}.", command,
- command.getClass().getSimpleName());
- } else {
- logger.warn("given command is NULL, couldn't post command for '{}'", itemName);
- }
- }
-
- @Override
- public void postUpdate(String itemName, State newState) {
- org.eclipse.smarthome.core.types.State eshState = (org.eclipse.smarthome.core.types.State) TypeMapper
- .mapToESHType(newState);
- if (eshState != null) {
- ItemStateEvent event = ItemEventFactory.createStateEvent(itemName, eshState);
- eventPublisher.post(event);
- } else if (newState != null) {
- logger.warn("Compatibility layer could not convert {} of type {}.", newState,
- newState.getClass().getSimpleName());
- } else {
- logger.warn("given new state is NULL, couldn't post update for '{}'", itemName);
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventSubscriber.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventSubscriber.java
deleted file mode 100644
index ac3d1e358..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/EventSubscriber.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-
-/**
- * An EventSubscriber receives events from the openHAB event bus for further processing.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface EventSubscriber {
-
- /**
- * Callback method if a command was sent on the event bus
- *
- * @param itemName the item for which a command was sent
- * @param command the command that was sent
- */
- public void receiveCommand(String itemName, Command command);
-
- /**
- * Callback method if a state update was sent on the event bus
- *
- * @param itemName the item for which a state update was sent
- * @param state the state that was sent
- */
- public void receiveUpdate(String itemName, State newStatus);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/internal/EventBridge.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/internal/EventBridge.java
deleted file mode 100644
index 38ed33e8e..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/events/internal/EventBridge.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.events.internal;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.smarthome.core.events.EventFilter;
-import org.eclipse.smarthome.core.events.EventPublisher;
-import org.eclipse.smarthome.core.events.EventSubscriber;
-import org.eclipse.smarthome.core.items.events.ItemCommandEvent;
-import org.eclipse.smarthome.core.items.events.ItemEventFactory;
-import org.eclipse.smarthome.core.items.events.ItemStateEvent;
-import org.openhab.core.compat1x.internal.TypeMapper;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.EventType;
-import org.openhab.core.types.State;
-import org.openhab.core.types.Type;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.event.EventHandler;
-
-/**
- * This class acts as a bridge between events from openHAB 1.x (using "openhab" as a topic prefix) and
- * openHAB (using "smarthome" as a topic prefix).
- * It simply duplicates events with an updated topic prefix and works both ways.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component(immediate = true, property = "event.topics=smarthome/*")
-public class EventBridge implements EventHandler, EventSubscriber {
-
- private static final String BRIDGEMARKER = "bridgemarker";
- private EventAdmin eventAdmin;
- private EventPublisher eventPublisher;
-
- @Reference(policy = ReferencePolicy.DYNAMIC)
- public void setEventAdmin(EventAdmin eventAdmin) {
- this.eventAdmin = eventAdmin;
- }
-
- public void unsetEventAdmin(EventAdmin eventAdmin) {
- this.eventAdmin = null;
- }
-
- @Reference
- public void setEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- public void unsetEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = null;
- }
-
- @Override
- public void handleEvent(Event event) {
- if (!Boolean.TRUE.equals(event.getProperty(BRIDGEMARKER))) {
- // map event from openHAB to ESH
- if (event.getTopic().startsWith(org.openhab.core.events.EventConstants.TOPIC_PREFIX)) {
- if (event.getTopic().endsWith(EventType.COMMAND.name())) {
- String itemName = (String) event.getProperty("item");
- Command ohCommand = (Command) event.getProperty("command");
- ItemCommandEvent eshEvent = ItemEventFactory.createCommandEvent(itemName,
- (org.eclipse.smarthome.core.types.Command) TypeMapper.mapToESHType(ohCommand));
- eventPublisher.post(eshEvent);
- } else if (event.getTopic().endsWith(EventType.UPDATE.name())) {
- String itemName = (String) event.getProperty("item");
- State ohState = (State) event.getProperty("state");
- ItemStateEvent eshEvent = ItemEventFactory.createStateEvent(itemName,
- (org.eclipse.smarthome.core.types.State) TypeMapper.mapToESHType(ohState));
- eventPublisher.post(eshEvent);
- }
- }
- }
- }
-
- private Map constructProperties(org.eclipse.smarthome.core.events.Event event) {
- Map properties = new HashMap<>();
- if (event instanceof ItemCommandEvent) {
- ItemCommandEvent icEvent = (ItemCommandEvent) event;
- String itemName = icEvent.getItemName();
- properties.put("item", itemName);
- Type eshType = TypeMapper.mapToOpenHABType(icEvent.getItemCommand());
- if (eshType instanceof Command) {
- properties.put("command", eshType);
- } else {
- return null;
- }
- } else {
- ItemStateEvent isEvent = (ItemStateEvent) event;
- String itemName = isEvent.getItemName();
- properties.put("item", itemName);
- Type eshType = TypeMapper.mapToOpenHABType(isEvent.getItemState());
- if (eshType instanceof State) {
- properties.put("state", eshType);
- } else {
- return null;
- }
- }
- properties.put(BRIDGEMARKER, true);
- return properties;
- }
-
- @Override
- public Set getSubscribedEventTypes() {
- Set types = new HashSet<>(2);
- types.add(ItemCommandEvent.TYPE);
- types.add(ItemStateEvent.TYPE);
- return types;
- }
-
- @Override
- public EventFilter getEventFilter() {
- return null;
- }
-
- @Override
- public void receive(org.eclipse.smarthome.core.events.Event event) {
- if (event.getType().equals(ItemCommandEvent.TYPE)) {
- Map properties = constructProperties(event);
- if (properties != null) {
- String topic = org.openhab.core.events.EventConstants.TOPIC_PREFIX + "/" + EventType.COMMAND + "/"
- + properties.get("item");
- eventAdmin.postEvent(new Event(topic, properties));
- }
- } else if (event.getType().equals(ItemStateEvent.TYPE)) {
- Map properties = constructProperties(event);
- if (properties != null) {
- String topic = org.openhab.core.events.EventConstants.TOPIC_PREFIX + "/" + EventType.UPDATE + "/"
- + properties.get("item");
- ;
- eventAdmin.postEvent(new Event(topic, properties));
- }
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GenericItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GenericItem.java
deleted file mode 100644
index 33e8c112c..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GenericItem.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.openhab.core.events.EventPublisher;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * The abstract base class for all items. It provides all relevant logic
- * for the infrastructure, such as publishing updates to the event bus
- * or notifying listeners.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class GenericItem implements Item {
-
- protected EventPublisher eventPublisher;
-
- protected Set listeners = new CopyOnWriteArraySet<>(
- Collections.newSetFromMap(new WeakHashMap<>()));
-
- protected List groupNames = new ArrayList<>();
-
- protected final String name;
-
- protected State state = UnDefType.NULL;
-
- public GenericItem(String name) {
- this.name = name;
- }
-
- @Override
- public State getState() {
- return state;
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (typeClass != null && typeClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
-
- public void initialize() {
- }
-
- public void dispose() {
- this.eventPublisher = null;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public List getGroupNames() {
- return groupNames;
- }
-
- public void setEventPublisher(EventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- protected void internalSend(Command command) {
- // try to send the command to the bus
- if (eventPublisher != null) {
- eventPublisher.sendCommand(this.getName(), command);
- }
- }
-
- public void setState(State state) {
- State oldState = this.state;
- this.state = state;
- notifyListeners(oldState, state);
- }
-
- private void notifyListeners(State oldState, State newState) {
- // if nothing has changed, we send update notifications
- Set clonedListeners = null;
- clonedListeners = new CopyOnWriteArraySet<>(listeners);
- for (StateChangeListener listener : clonedListeners) {
- listener.stateUpdated(this, newState);
- }
- if (!oldState.equals(newState)) {
- for (StateChangeListener listener : clonedListeners) {
- listener.stateChanged(this, oldState, newState);
- }
- }
- }
-
- @Override
- public String toString() {
- return getName() + " (" + "Type=" + getClass().getSimpleName() + ", " + "State=" + getState() + ")";
- }
-
- public void addStateChangeListener(StateChangeListener listener) {
- synchronized (listeners) {
- listeners.add(listener);
- }
- }
-
- public void removeStateChangeListener(StateChangeListener listener) {
- synchronized (listeners) {
- listeners.remove(listener);
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((groupNames == null) ? 0 : groupNames.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((state == null) ? 0 : state.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GenericItem other = (GenericItem) obj;
- if (groupNames == null) {
- if (other.groupNames != null) {
- return false;
- }
- } else if (!groupNames.equals(other.groupNames)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (state == null) {
- if (other.state != null) {
- return false;
- }
- } else if (!state.equals(other.state)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupFunction.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupFunction.java
deleted file mode 100644
index 7cc53be17..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupFunction.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.List;
-
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * Group functions are used by active group items to calculate a state for the group
- * out of the states of all its member items.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract interface GroupFunction {
-
- /**
- * Determines the current state of a group based on a list of items
- *
- * @param items the items to calculate a group state for
- * @return the calculated group state
- */
- public State calculate(List- items);
-
- /**
- * Calculates the group state and returns it as a state of the requested type.
- *
- * @param items the items to calculate a group state for
- * @param stateClass the type in which the state should be returned
- * @return the calculated group state of the requested type or null, if type is not supported
- */
- public State getStateAs(List
- items, Class extends State> stateClass);
-
- /**
- * This is the default group function that does nothing else than to check if all member items
- * have the same state. If this is the case, this state is returned, otherwise UNDEF is returned.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class Equality implements GroupFunction {
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- if (!items.isEmpty()) {
- State state = items.get(0).getState();
- for (int i = 1; i < items.size(); i++) {
- if (!state.equals(items.get(i).getState())) {
- return UnDefType.UNDEF;
- }
- }
- return state;
- } else {
- return UnDefType.UNDEF;
- }
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupItem.java
deleted file mode 100644
index 3da3169be..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/GroupItem.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.stream.Collectors;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class GroupItem extends GenericItem implements StateChangeListener {
-
- private final Logger logger = LoggerFactory.getLogger(GroupItem.class);
-
- protected final GenericItem baseItem;
-
- protected final List
- members;
-
- protected GroupFunction function;
-
- public GroupItem(String name) {
- this(name, null);
- }
-
- public GroupItem(String name, GenericItem baseItem) {
- this(name, baseItem, new GroupFunction.Equality());
- }
-
- public GroupItem(String name, GenericItem baseItem, GroupFunction function) {
- super(name);
- members = new CopyOnWriteArrayList<>();
- this.function = function;
- this.baseItem = baseItem;
- }
-
- /**
- * Returns the base item of this {@link GroupItem}. This method is only
- * intended to allow instance checks of the underlying BaseItem. It must
- * not be changed in any way.
- *
- * @return the base item of this GroupItem
- */
- public GenericItem getBaseItem() {
- return baseItem;
- }
-
- /**
- * Returns the direct members of this {@link GroupItem} regardless if these
- * members are {@link GroupItem}s as well.
- *
- * @return the direct members of this {@link GroupItem}
- */
- public List
- getMembers() {
- return members;
- }
-
- /**
- * Returns the direct members of this {@link GroupItem} and recursively all
- * members of the potentially contained {@link GroupItem}s as well. The
- * {@link GroupItem}s itself aren't contained. The returned items are unique.
- *
- * @return all members of this and all contained {@link GroupItem}s
- */
- public List
- getAllMembers() {
- Set
- allMembers = new HashSet<>();
- collectMembers(allMembers, members);
- return new ArrayList<>(allMembers);
- }
-
- private void collectMembers(Set
- allMembers, List
- members) {
- for (Item member : members) {
- if (member instanceof GroupItem) {
- collectMembers(allMembers, ((GroupItem) member).members);
- } else {
- allMembers.add(member);
- }
- }
- }
-
- public void addMember(Item item) {
- members.add(item);
- if (item instanceof GenericItem) {
- GenericItem genericItem = (GenericItem) item;
- genericItem.addStateChangeListener(this);
- }
- }
-
- public void removeMember(Item item) {
- members.remove(item);
- if (item instanceof GenericItem) {
- GenericItem genericItem = (GenericItem) item;
- genericItem.removeStateChangeListener(this);
- }
- }
-
- /**
- * The accepted data types of a group item is the same as of the underlying base item.
- * If none is defined, the intersection of all sets of accepted data types of all group
- * members is used instead.
- *
- * @return the accepted data types of this group item
- */
- @Override
- public List> getAcceptedDataTypes() {
- if (baseItem != null) {
- return baseItem.getAcceptedDataTypes();
- } else {
- List> acceptedDataTypes = null;
- for (Item item : members) {
- if (acceptedDataTypes == null || acceptedDataTypes.isEmpty()) {
- acceptedDataTypes = item.getAcceptedDataTypes();
- } else {
- acceptedDataTypes = item.getAcceptedDataTypes().stream().distinct()
- .filter(acceptedDataTypes::contains).collect(Collectors.toList());
- }
- }
- return acceptedDataTypes == null ? Collections.emptyList() : acceptedDataTypes;
- }
- }
-
- /**
- * The accepted command types of a group item is the same as of the underlying base item.
- * If none is defined, the intersection of all sets of accepted command types of all group
- * members is used instead.
- *
- * @return the accepted command types of this group item
- */
- @Override
- public List> getAcceptedCommandTypes() {
- if (baseItem != null) {
- return baseItem.getAcceptedCommandTypes();
- } else {
- List> acceptedCommandTypes = null;
- for (Item item : members) {
- if (acceptedCommandTypes == null || acceptedCommandTypes.isEmpty()) {
- acceptedCommandTypes = item.getAcceptedCommandTypes();
- } else {
- acceptedCommandTypes = item.getAcceptedCommandTypes().stream().distinct()
- .filter(acceptedCommandTypes::contains).collect(Collectors.toList());
- }
- }
- return acceptedCommandTypes == null ? Collections.emptyList() : acceptedCommandTypes;
- }
- }
-
- public void send(Command command) {
- if (getAcceptedCommandTypes().contains(command.getClass())) {
- internalSend(command);
- } else {
- logger.warn("Command '{}' has been ignored for group '{}' as it is not accepted.", command.toString(),
- getName());
- }
- }
-
- @Override
- protected void internalSend(Command command) {
- if (eventPublisher != null) {
- for (Item member : members) {
- // try to send the command to the bus
- eventPublisher.sendCommand(member.getName(), command);
- }
- }
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- State newState = function.getStateAs(getAllMembers(), typeClass);
- if (newState == null && baseItem != null) {
- // we use the transformation method from the base item
- baseItem.setState(state);
- newState = baseItem.getStateAs(typeClass);
- }
- if (newState == null) {
- newState = super.getStateAs(typeClass);
- }
- return newState;
- }
-
- @Override
- public String toString() {
- return getName() + " (" + "Type=" + getClass().getSimpleName() + ", "
- + (baseItem != null ? "BaseType=" + baseItem.getClass().getSimpleName() + ", " : "") + "Members="
- + members.size() + ", " + "State=" + getState() + ")";
- }
-
- @Override
- public void stateChanged(Item item, State oldState, State newState) {
- setState(function.calculate(members));
- }
-
- @Override
- public void stateUpdated(Item item, State state) {
- setState(function.calculate(members));
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/Item.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/Item.java
deleted file mode 100644
index 1a580325f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/Item.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.List;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-
-/**
- *
- * This interface defines the core features of an openHAB item.
- *
- *
- * Item instances are used for all stateful services and are especially
- * important for the {@link ItemRegistry}.
- *
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface Item {
-
- /**
- * returns the current state of the item
- *
- * @return the current state
- */
- public State getState();
-
- /**
- * returns the current state of the item as a specific type
- *
- * @return the current state in the requested type or
- * null, if state cannot be provided as the requested type
- */
- public State getStateAs(Class extends State> typeClass);
-
- /**
- * returns the name of the item
- *
- * @return the name of the item
- */
- public String getName();
-
- /**
- *
- * This method provides a list of all data types that can be used to update the item state
- *
- *
- * Imagine e.g. a dimmer device: It's status could be 0%, 10%, 50%, 100%, but also OFF or ON and
- * maybe UNDEFINED. So the accepted data types would be in this case {@link PercentType}, {@link OnOffType}
- * and {@link UnDefType}
- *
- *
- * @return a list of data types that can be used to update the item state
- */
- public List> getAcceptedDataTypes();
-
- /**
- *
- * This method provides a list of all command types that can be used for this item
- *
- *
- * Imagine e.g. a dimmer device: You could ask it to dim to 0%, 10%, 50%, 100%, but
- * also to turn OFF or ON. So the accepted command types would be in this case {@link PercentType},
- * {@link OnOffType}
- *
- *
- * @return a list of all command types that can be used for this item
- */
- public List> getAcceptedCommandTypes();
-
- /**
- * Returns a list of the names of the groups this item belongs to.
- *
- * @return list of item group names
- */
- public List getGroupNames();
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemFactory.java
deleted file mode 100644
index e180c6779..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-/**
- * This Factory creates concrete instances of the known ItemTypes.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- */
-public interface ItemFactory {
-
- /**
- * Creates a new Item instance of type itemTypeName
and the name
- * itemName
- *
- * @param itemTypeName
- * @param itemName
- * @return a new Item of type itemTypeName
or
- * null
if no matching class is known.
- */
- GenericItem createItem(String itemTypeName, String itemName);
-
- /**
- * Returns the list of all supported ItemTypes of this Factory.
- *
- * @return the supported ItemTypes
- */
- String[] getSupportedItemTypes();
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemLookupException.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemLookupException.java
deleted file mode 100644
index ff677ce15..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemLookupException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-/**
- * This is an abstract parent exception to be extended by any exceptions
- * related to item lookups in the item registry.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class ItemLookupException extends Exception {
-
- public ItemLookupException(String string) {
- super(string);
- }
-
- private static final long serialVersionUID = -4617708589675048859L;
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotFoundException.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotFoundException.java
deleted file mode 100644
index 13523e2cd..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotFoundException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-/**
- * This exception is thrown by the {@link ItemRegistry} if an item could
- * not be found.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ItemNotFoundException extends ItemLookupException {
-
- public ItemNotFoundException(String name) {
- super("Item '" + name + "' could not be found in the item registry");
- }
-
- private static final long serialVersionUID = -3720784568250902711L;
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotUniqueException.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotUniqueException.java
deleted file mode 100644
index 8fd33e9fa..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemNotUniqueException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.Collection;
-
-/**
- * This exception can be thrown whenever a search pattern does not uniquely identify
- * an item. The list of matching items must be made available through this exception.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ItemNotUniqueException extends ItemLookupException {
-
- private static final long serialVersionUID = 5154625234283910124L;
-
- private final Collection- matchingItems;
-
- public ItemNotUniqueException(String string, Collection
- items) {
- super("Item cannot be uniquely identified by '" + string + "'");
- this.matchingItems = items;
- }
-
- /**
- * Returns all items that match the search pattern
- *
- * @return collection of items matching the search pattern
- */
- public Collection
- getMatchingItems() {
- return matchingItems;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemProvider.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemProvider.java
deleted file mode 100644
index 44c480df0..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemProvider.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.Collection;
-
-/**
- * An item provider provides instances of {@link GenericItem}. These
- * items can be constructed from some static configuration files or
- * they can be derived from some dynamic logic.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ItemProvider {
-
- /**
- * Provides an array of items.
- *
- * @return a collection of items
- */
- Collection
- getItems();
-
- public void addItemChangeListener(ItemsChangeListener listener);
-
- public void removeItemChangeListener(ItemsChangeListener listener);
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistry.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistry.java
deleted file mode 100644
index 6ee2437b0..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistry.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.Collection;
-
-/**
- * The ItemRegistry is the central place, where items are kept in memory and their state
- * is permanently tracked. So any code that requires the current state of items should use
- * this service (instead of trying to keep their own local copy of the items).
- *
- * Items are registered by {@link ItemProvider}s, which can provision them from any source
- * they like and also dynamically remove or add items.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ItemRegistry {
-
- /**
- * This method retrieves a single item from the registry.
- *
- * @param name the item name
- * @return the uniquely identified item
- * @throws ItemNotFoundException if no item matches the input
- */
- public Item getItem(String name) throws ItemNotFoundException;
-
- /**
- * This method retrieves a single item from the registry.
- * Search patterns and shortened versions are supported, if they uniquely identify an item
- *
- * @param name the item name, a part of the item name or a search pattern
- * @return the uniquely identified item
- * @throws ItemNotFoundException if no item matches the input
- * @throws ItemNotUniqueException if multiply items match the input
- */
- public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException;
-
- /**
- * This method retrieves all items that are currently available in the registry
- *
- * @return a collection of all available items
- */
- public Collection
- getItems();
-
- /**
- * This method retrieves all items that match a given search pattern
- *
- * @return a collection of all items matching the search pattern
- */
- public Collection
- getItems(String pattern);
-
- /**
- * Checks whether itemName matches the item name conventions.
- * Item names must only consist out of alpha-numerical characters and
- * underscores (_).
- *
- * @param itemName the item name to validate
- * @return true, if the name is valid
- */
- public boolean isValidItemName(String itemName);
-
- public void addItemRegistryChangeListener(ItemRegistryChangeListener listener);
-
- public void removeItemRegistryChangeListener(ItemRegistryChangeListener listener);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistryChangeListener.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistryChangeListener.java
deleted file mode 100644
index b4fb2f36c..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemRegistryChangeListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.Collection;
-
-/**
- * This is a listener interface which should be implemented where ever the item registry is
- * used in order to be notified of any dynamic changes in the provided items.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ItemRegistryChangeListener {
-
- /**
- * Notifies the listener that all items in the registry have changed and thus should be reloaded.
- *
- * @param oldItemNames a collection of all previous item names, so that references can be removed
- */
- public void allItemsChanged(Collection oldItemNames);
-
- /**
- * Notifies the listener that a single item has been added
- *
- * @param item the item that has been added
- */
- public void itemAdded(Item item);
-
- /**
- * Notifies the listener that a single item has been removed
- *
- * @param item the item that has been removed
- */
- public void itemRemoved(Item item);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemsChangeListener.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemsChangeListener.java
deleted file mode 100644
index ba07a3989..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/ItemsChangeListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import java.util.Collection;
-
-/**
- * This is a listener interface which should be implemented where ever item providers or
- * the item registry are used in order to be notified of any dynamic changes in the provided items.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ItemsChangeListener {
-
- /**
- * Notifies the listener that all items of a provider have changed and thus should be reloaded.
- *
- * @param provider the concerned item provider
- * @param oldItemNames a collection of all previous item names, so that references can be removed
- */
- public void allItemsChanged(ItemProvider provider, Collection oldItemNames);
-
- /**
- * Notifies the listener that a single item has been added
- *
- * @param provider the concerned item provider
- * @param item the item that has been added
- */
- public void itemAdded(ItemProvider provider, Item item);
-
- /**
- * Notifies the listener that a single item has been removed
- *
- * @param provider the concerned item provider
- * @param item the item that has been removed
- */
- public void itemRemoved(ItemProvider provider, Item item);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/StateChangeListener.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/StateChangeListener.java
deleted file mode 100644
index bb6ef8f3e..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/StateChangeListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items;
-
-import org.openhab.core.types.State;
-
-/**
- *
- * This interface must be implemented by all classes that want to be notified
- * about changes in the state of an item.
- *
- *
- * The {@link GenericItem} class provides the possibility to register such
- * listeners.
- *
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface StateChangeListener {
-
- /**
- * This method is called, if a state has changed.
- *
- * @param item the item whose state has changed
- * @param oldState the previous state
- * @param newState the new state
- */
- public void stateChanged(Item item, State oldState, State newState);
-
- /**
- * This method is called, if a state was updated, but has not changed
- *
- * @param item the item whose state was updated
- * @param state the current state, same before and after the update
- */
- public void stateUpdated(Item item, State state);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java
deleted file mode 100644
index 9233ca139..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/items/internal/ItemUIRegistryDelegate.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.items.internal;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.smarthome.core.common.registry.RegistryChangeListener;
-import org.eclipse.smarthome.core.items.ItemUtil;
-import org.openhab.core.compat1x.internal.ItemMapper;
-import org.openhab.core.items.Item;
-import org.openhab.core.items.ItemNotFoundException;
-import org.openhab.core.items.ItemNotUniqueException;
-import org.openhab.core.items.ItemRegistry;
-import org.openhab.core.items.ItemRegistryChangeListener;
-import org.openhab.core.types.State;
-import org.openhab.model.sitemap.LinkableWidget;
-import org.openhab.model.sitemap.Sitemap;
-import org.openhab.model.sitemap.Widget;
-import org.openhab.ui.items.ItemUIRegistry;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component(service = { ItemRegistry.class, ItemUIRegistry.class })
-public class ItemUIRegistryDelegate
- implements ItemUIRegistry, RegistryChangeListener {
-
- private org.eclipse.smarthome.ui.items.ItemUIRegistry itemUIRegistry;
- private final Set listeners = new HashSet<>();
-
- @Reference
- protected void setItemUIRegistry(org.eclipse.smarthome.ui.items.ItemUIRegistry itemUIRegistry) {
- this.itemUIRegistry = itemUIRegistry;
- itemUIRegistry.addRegistryChangeListener(this);
- }
-
- protected void unsetItemUIRegistry(org.eclipse.smarthome.ui.items.ItemUIRegistry itemUIRegistry) {
- this.itemUIRegistry = null;
- }
-
- @Override
- public Item getItem(String name) throws ItemNotFoundException {
- org.eclipse.smarthome.core.items.Item eshItem;
- try {
- eshItem = itemUIRegistry.getItem(name);
- } catch (org.eclipse.smarthome.core.items.ItemNotFoundException e) {
- throw new ItemNotFoundException(name);
- }
- return ItemMapper.mapToOpenHABItem(eshItem);
- }
-
- @Override
- public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
- org.eclipse.smarthome.core.items.Item eshItem;
- try {
- eshItem = itemUIRegistry.getItemByPattern(name);
- } catch (org.eclipse.smarthome.core.items.ItemNotFoundException e) {
- throw new ItemNotFoundException(name);
- } catch (org.eclipse.smarthome.core.items.ItemNotUniqueException e) {
- throw new ItemNotUniqueException(name, null);
- }
- return ItemMapper.mapToOpenHABItem(eshItem);
- }
-
- @Override
- public Collection- getItems() {
- Collection eshItems = itemUIRegistry.getItems();
- Collection
- ohItems = new HashSet<>(eshItems.size());
-
- for (org.eclipse.smarthome.core.items.Item eshItem : eshItems) {
- ohItems.add(ItemMapper.mapToOpenHABItem(eshItem));
- }
- return ohItems;
- }
-
- @Override
- public Collection
- getItems(String pattern) {
- Collection eshItems = itemUIRegistry.getItems(pattern);
- Collection
- ohItems = new HashSet<>(eshItems.size());
-
- for (org.eclipse.smarthome.core.items.Item eshItem : eshItems) {
- ohItems.add(ItemMapper.mapToOpenHABItem(eshItem));
- }
- return ohItems;
- }
-
- @Override
- public boolean isValidItemName(String itemName) {
- return ItemUtil.isValidItemName(itemName);
- }
-
- @Override
- public void addItemRegistryChangeListener(ItemRegistryChangeListener listener) {
- this.listeners.add(listener);
- }
-
- @Override
- public void removeItemRegistryChangeListener(ItemRegistryChangeListener listener) {
- this.listeners.remove(listener);
- }
-
- @Override
- public void added(org.eclipse.smarthome.core.items.Item element) {
- Item ohItem = ItemMapper.mapToOpenHABItem(element);
- for (ItemRegistryChangeListener listener : listeners) {
- listener.itemAdded(ohItem);
- }
- }
-
- @Override
- public void removed(org.eclipse.smarthome.core.items.Item element) {
- Item ohItem = ItemMapper.mapToOpenHABItem(element);
- for (ItemRegistryChangeListener listener : listeners) {
- listener.itemRemoved(ohItem);
- }
- }
-
- @Override
- public void updated(org.eclipse.smarthome.core.items.Item oldElement,
- org.eclipse.smarthome.core.items.Item element) {
- Item ohItem = ItemMapper.mapToOpenHABItem(element);
- for (ItemRegistryChangeListener listener : listeners) {
- listener.itemRemoved(ohItem);
- listener.itemAdded(ohItem);
- }
- }
-
- @Override
- public String getIcon(String itemName) {
- return itemUIRegistry.getCategory(itemName);
- }
-
- @Override
- public String getLabel(String itemName) {
- return itemUIRegistry.getLabel(itemName);
- }
-
- @Override
- public Widget getDefaultWidget(Class extends Item> itemType, String itemName) {
- return null;
- }
-
- @Override
- public Widget getWidget(String itemName) {
- return null;
- }
-
- @Override
- public String getLabel(Widget w) {
- return itemUIRegistry.getLabel(w.getItem());
- }
-
- @Override
- public String getIcon(Widget w) {
- return itemUIRegistry.getCategory(w.getItem());
- }
-
- @Override
- public State getState(Widget w) {
- return null;
- }
-
- @Override
- public Widget getWidget(Sitemap sitemap, String id) {
- return null;
- }
-
- @Override
- public String getWidgetId(Widget w) {
- return null;
- }
-
- @Override
- public EList getChildren(LinkableWidget w) {
- return null;
- }
-
- @Override
- public boolean iconExists(String icon) {
- return true;
- }
-
- @Override
- public String getLabelColor(Widget w) {
- return null;
- }
-
- @Override
- public String getValueColor(Widget w) {
- return null;
- }
-
- @Override
- public boolean getVisiblity(Widget w) {
- return true;
- }
-
- @Override
- public State getItemState(String itemName) {
- try {
- return getItem(itemName).getState();
- } catch (ItemNotFoundException e) {
- return null;
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ColorItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ColorItem.java
deleted file mode 100644
index 1c2ca87ad..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ColorItem.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.HSBType;
-import org.openhab.core.library.types.IncreaseDecreaseType;
-import org.openhab.core.library.types.OnOffType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A ColorItem can be used for color values, e.g. for LED lights
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ColorItem extends DimmerItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(OnOffType.class);
- acceptedDataTypes.add(PercentType.class);
- acceptedDataTypes.add(HSBType.class);
- acceptedDataTypes.add(UnDefType.class);
-
- acceptedCommandTypes.add(OnOffType.class);
- acceptedCommandTypes.add(IncreaseDecreaseType.class);
- acceptedCommandTypes.add(PercentType.class);
- acceptedCommandTypes.add(HSBType.class);
- }
-
- public ColorItem(String name) {
- super(name);
- }
-
- public void send(HSBType command) {
- internalSend(command);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public void setState(State state) {
- State currentState = this.state;
-
- if (currentState instanceof HSBType) {
- DecimalType hue = ((HSBType) currentState).getHue();
- PercentType saturation = ((HSBType) currentState).getSaturation();
- // we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed
- if (state == OnOffType.OFF) {
- super.setState(new HSBType(hue, saturation, PercentType.ZERO));
- } else if (state == OnOffType.ON) {
- super.setState(new HSBType(hue, saturation, PercentType.HUNDRED));
- } else if (state instanceof PercentType && !(state instanceof HSBType)) {
- super.setState(new HSBType(hue, saturation, (PercentType) state));
- } else {
- super.setState(state);
- }
- } else {
- // we map ON/OFF values to black/white and percentage values to grey scale
- if (state == OnOffType.OFF) {
- super.setState(HSBType.BLACK);
- } else if (state == OnOffType.ON) {
- super.setState(HSBType.WHITE);
- } else if (state instanceof PercentType && !(state instanceof HSBType)) {
- super.setState(new HSBType(DecimalType.ZERO, PercentType.ZERO, (PercentType) state));
- } else {
- super.setState(state);
- }
- }
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (typeClass == HSBType.class) {
- return this.state;
- } else if (typeClass == OnOffType.class) {
- if (state instanceof HSBType) {
- HSBType hsbState = (HSBType) state;
- // if brightness is not completely off, we consider the state to be on
- return hsbState.getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON;
- }
- } else if (typeClass == DecimalType.class) {
- if (state instanceof HSBType) {
- HSBType hsbState = (HSBType) state;
- return new DecimalType(
- hsbState.getBrightness().toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
- }
- }
- return super.getStateAs(typeClass);
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ContactItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ContactItem.java
deleted file mode 100644
index cd2b045d9..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/ContactItem.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.OpenClosedType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A ContactItem can be used for sensors that return an "open" or "close" as a state.
- * This is useful for doors, windows, etc.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ContactItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(OpenClosedType.class);
- acceptedDataTypes.add(UnDefType.class);
- }
-
- public ContactItem(String name) {
- super(name);
- }
-
- public void send(OpenClosedType command) {
- internalSend(command);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (typeClass == DecimalType.class) {
- return state == OpenClosedType.OPEN ? new DecimalType(1) : DecimalType.ZERO;
- } else if (typeClass == PercentType.class) {
- return state == OpenClosedType.OPEN ? PercentType.HUNDRED : PercentType.ZERO;
- } else {
- return super.getStateAs(typeClass);
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DateTimeItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DateTimeItem.java
deleted file mode 100644
index 731418c82..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DateTimeItem.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DateTimeType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A DateTimeItem stores a timestamp including a valid time zone.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- * @author Kai Kreuzer - Initial contribution
- */
-public class DateTimeItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add((DateTimeType.class));
- acceptedDataTypes.add(UnDefType.class);
- }
-
- public DateTimeItem(String name) {
- super(name);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DimmerItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DimmerItem.java
deleted file mode 100644
index eb52bbeea..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/DimmerItem.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.IncreaseDecreaseType;
-import org.openhab.core.library.types.OnOffType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A DimmerItem can be used as a switch (ON/OFF), but it also accepts percent values
- * to reflect the dimmed state.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class DimmerItem extends SwitchItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(OnOffType.class);
- acceptedDataTypes.add(PercentType.class);
- acceptedDataTypes.add(UnDefType.class);
-
- acceptedCommandTypes.add(OnOffType.class);
- acceptedCommandTypes.add(IncreaseDecreaseType.class);
- acceptedCommandTypes.add(PercentType.class);
- }
-
- public DimmerItem(String name) {
- super(name);
- }
-
- public void send(PercentType command) {
- internalSend(command);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public void setState(State state) {
- // we map ON/OFF values to the percent values 0 and 100
- if (state == OnOffType.OFF) {
- super.setState(PercentType.ZERO);
- } else if (state == OnOffType.ON) {
- super.setState(PercentType.HUNDRED);
- } else {
- super.setState(state);
- }
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (state.getClass() == typeClass) {
- return state;
- } else if (typeClass == OnOffType.class) {
- // if it is not completely off, we consider the dimmer to be on
- return state.equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON;
- } else if (typeClass == DecimalType.class) {
- if (state instanceof PercentType) {
- return new DecimalType(
- ((PercentType) state).toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
- }
- } else if (typeClass == PercentType.class) {
- if (state instanceof DecimalType) {
- return new PercentType(((DecimalType) state).toBigDecimal().multiply(new BigDecimal(100)));
- }
- }
-
- return super.getStateAs(typeClass);
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/LocationItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/LocationItem.java
deleted file mode 100644
index fe865ab0a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/LocationItem.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.PointType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A LocationItem can be used to store GPS related informations, addresses...
- * This is useful for location awareness related functions
- *
- * @author Gaël L'hopital - Initial contribution
- */
-public class LocationItem extends GenericItem {
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(PointType.class);
- acceptedDataTypes.add(UnDefType.class);
- }
-
- public LocationItem(String name) {
- super(name);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- /**
- * Compute the distance with another Point type,
- * http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-java
- *
- * @return distance between the two points in meters
- */
- public DecimalType distanceFrom(PointType away) {
- double dist = -1;
-
- if ((away != null) && (this.state instanceof PointType)) {
- PointType me = (PointType) this.state;
-
- double dLat = Math.pow(
- Math.sin(Math.toRadians(away.getLatitude().doubleValue() - me.getLatitude().doubleValue()) / 2), 2);
- double dLng = Math.pow(
- Math.sin(Math.toRadians(away.getLongitude().doubleValue() - me.getLongitude().doubleValue()) / 2),
- 2);
- double a = dLat + Math.cos(Math.toRadians(me.getLatitude().doubleValue()))
- * Math.cos(Math.toRadians(away.getLatitude().doubleValue())) * dLng;
-
- dist = PointType.WGS84_A * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- }
-
- return new DecimalType(dist);
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/NumberItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/NumberItem.java
deleted file mode 100644
index db75282ea..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/NumberItem.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A NumberItem has a decimal value and is usually used for all kinds
- * of sensors, like temperature, brightness, wind, etc.
- * It can also be used as a counter or as any other thing that can be expressed
- * as a number.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class NumberItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(DecimalType.class);
- acceptedDataTypes.add(UnDefType.class);
-
- acceptedCommandTypes.add(DecimalType.class);
- }
-
- public NumberItem(String name) {
- super(name);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/RollershutterItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/RollershutterItem.java
deleted file mode 100644
index 5bf3b7de3..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/RollershutterItem.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.library.types.StopMoveType;
-import org.openhab.core.library.types.UpDownType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A RollershutterItem allows the control of roller shutters, i.e.
- * moving them up, down, stopping or setting it to close to a certain percentage.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class RollershutterItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(UnDefType.class);
- acceptedDataTypes.add(UpDownType.class);
- acceptedDataTypes.add(PercentType.class);
-
- acceptedCommandTypes.add(UpDownType.class);
- acceptedCommandTypes.add(StopMoveType.class);
- acceptedCommandTypes.add(PercentType.class);
- }
-
- public RollershutterItem(String name) {
- super(name);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public void setState(State state) {
- // we map UP/DOWN values to the percent values 0 and 100
- if (state == UpDownType.UP) {
- super.setState(PercentType.ZERO);
- } else if (state == UpDownType.DOWN) {
- super.setState(PercentType.HUNDRED);
- } else {
- super.setState(state);
- }
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (typeClass == UpDownType.class) {
- if (state.equals(PercentType.ZERO)) {
- return UpDownType.UP;
- } else if (state.equals(PercentType.HUNDRED)) {
- return UpDownType.DOWN;
- } else {
- return UnDefType.UNDEF;
- }
- } else if (typeClass == DecimalType.class) {
- if (state instanceof PercentType) {
- return new DecimalType(
- ((PercentType) state).toBigDecimal().divide(new BigDecimal(100), 8, RoundingMode.UP));
- }
- }
- return super.getStateAs(typeClass);
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/StringItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/StringItem.java
deleted file mode 100644
index 3f7843f17..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/StringItem.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DateTimeType;
-import org.openhab.core.library.types.StringType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.TypeParser;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A StringItem can be used for any kind of string to either send or receive
- * from a device.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class StringItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(StringType.class);
- acceptedDataTypes.add((DateTimeType.class));
- acceptedDataTypes.add(UnDefType.class);
-
- acceptedCommandTypes.add(StringType.class);
- }
-
- public StringItem(String name) {
- super(name);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- List> list = new ArrayList<>();
- list.add(typeClass);
- State convertedState = TypeParser.parseState(list, state.toString());
- if (convertedState != null) {
- return convertedState;
- } else {
- return super.getStateAs(typeClass);
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/SwitchItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/SwitchItem.java
deleted file mode 100644
index 26ab0701f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/items/SwitchItem.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.items;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openhab.core.items.GenericItem;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.OnOffType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * A SwitchItem represents a normal switch that can be ON or OFF.
- * Useful for normal lights, presence detection etc.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class SwitchItem extends GenericItem {
-
- private static List> acceptedDataTypes = new ArrayList<>();
- private static List> acceptedCommandTypes = new ArrayList<>();
-
- static {
- acceptedDataTypes.add(OnOffType.class);
- acceptedDataTypes.add(UnDefType.class);
-
- acceptedCommandTypes.add(OnOffType.class);
- }
-
- public SwitchItem(String name) {
- super(name);
- }
-
- public void send(OnOffType command) {
- internalSend(command);
- }
-
- @Override
- public List> getAcceptedDataTypes() {
- return acceptedDataTypes;
- }
-
- @Override
- public List> getAcceptedCommandTypes() {
- return acceptedCommandTypes;
- }
-
- @Override
- public State getStateAs(Class extends State> typeClass) {
- if (typeClass == DecimalType.class) {
- return state == OnOffType.ON ? new DecimalType(1) : DecimalType.ZERO;
- } else if (typeClass == PercentType.class) {
- return state == OnOffType.ON ? PercentType.HUNDRED : PercentType.ZERO;
- } else {
- return super.getStateAs(typeClass);
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/ArithmeticGroupFunction.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/ArithmeticGroupFunction.java
deleted file mode 100644
index ebbdc51d9..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/ArithmeticGroupFunction.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.List;
-
-import org.openhab.core.items.GroupFunction;
-import org.openhab.core.items.Item;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-
-/**
- * This interface is only a container for functions that require the core type library
- * for its calculations.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ArithmeticGroupFunction extends GroupFunction {
-
- /**
- * This does a logical 'and' operation. Only if all items are of 'activeState' this
- * is returned, otherwise the 'passiveState' is returned.
- *
- * Through the getStateAs() method, it can be determined, how many
- * items actually are not in the 'activeState'.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class And implements GroupFunction {
-
- protected final State activeState;
- protected final State passiveState;
-
- public And(State activeValue, State passiveValue) {
- if (activeValue == null || passiveValue == null) {
- throw new IllegalArgumentException("Parameters must not be null!");
- }
- this.activeState = activeValue;
- this.passiveState = passiveValue;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- if (items != null && !items.isEmpty()) {
- for (Item item : items) {
- if (!activeState.equals(item.getStateAs(activeState.getClass()))) {
- return passiveState;
- }
- }
- return activeState;
- } else {
- // if we do not have any items, we return the passive state
- return passiveState;
- }
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- if (stateClass == DecimalType.class) {
- if (items != null) {
- return new DecimalType(items.size() - count(items, activeState));
- } else {
- return DecimalType.ZERO;
- }
- } else {
- return null;
- }
- }
- }
-
- private int count(List
- items, State state) {
- int count = 0;
- if (items != null && state != null) {
- for (Item item : items) {
- if (state.equals(item.getStateAs(state.getClass()))) {
- count++;
- }
- }
- }
- return count;
-
- }
- }
-
- /**
- * This does a logical 'or' operation. If at least one item is of 'activeState' this
- * is returned, otherwise the 'passiveState' is returned.
- *
- * Through the getStateAs() method, it can be determined, how many
- * items actually are in the 'activeState'.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class Or implements GroupFunction {
-
- protected final State activeState;
- protected final State passiveState;
-
- public Or(State activeValue, State passiveValue) {
- if (activeValue == null || passiveValue == null) {
- throw new IllegalArgumentException("Parameters must not be null!");
- }
- this.activeState = activeValue;
- this.passiveState = passiveValue;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- if (items != null) {
- for (Item item : items) {
- if (activeState.equals(item.getStateAs(activeState.getClass()))) {
- return activeState;
- }
- }
- }
- return passiveState;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- if (stateClass == DecimalType.class) {
- return new DecimalType(count(items, activeState));
- } else {
- return null;
- }
- }
- }
-
- private int count(List
- items, State state) {
- int count = 0;
- if (items != null && state != null) {
- for (Item item : items) {
- if (state.equals(item.getStateAs(state.getClass()))) {
- count++;
- }
- }
- }
- return count;
- }
- }
-
- /**
- * This does a logical 'nand' operation. The state is 'calculated' by
- * the normal 'and' operation and than negated by returning the opposite
- * value. E.g. when the 'and' operation calculates the activeValue the
- * passiveValue will be returned and vice versa.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- */
- static class NAnd extends And {
-
- public NAnd(State activeValue, State passiveValue) {
- super(activeValue, passiveValue);
- }
-
- @Override
- public State calculate(List
- items) {
- State result = super.calculate(items);
- State notResult = result.equals(activeState) ? passiveState : activeState;
- return notResult;
- }
-
- }
-
- /**
- * This does a logical 'nor' operation. The state is 'calculated' by
- * the normal 'or' operation and than negated by returning the opposite
- * value. E.g. when the 'or' operation calculates the activeValue the
- * passiveValue will be returned and vice versa.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- */
- static class NOr extends Or {
-
- public NOr(State activeValue, State passiveValue) {
- super(activeValue, passiveValue);
- }
-
- @Override
- public State calculate(List
- items) {
- State result = super.calculate(items);
- State notResult = result.equals(activeState) ? passiveState : activeState;
- return notResult;
- }
-
- }
-
- /**
- * This calculates the numeric average over all item states of decimal type.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class Avg implements GroupFunction {
-
- public Avg() {
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- BigDecimal sum = BigDecimal.ZERO;
- int count = 0;
- if (items != null) {
- for (Item item : items) {
- DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
- if (itemState != null) {
- sum = sum.add(itemState.toBigDecimal());
- count++;
- }
- }
- }
- if (count > 0) {
- return new DecimalType(sum.divide(new BigDecimal(count), RoundingMode.HALF_UP));
- } else {
- return UnDefType.UNDEF;
- }
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
- }
-
- /**
- * This calculates the numeric sum over all item states of decimal type.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- *
- */
- static class Sum implements GroupFunction {
-
- public Sum() {
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- BigDecimal sum = BigDecimal.ZERO;
- if (items != null) {
- for (Item item : items) {
- DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
- if (itemState != null) {
- sum = sum.add(itemState.toBigDecimal());
- }
- }
- }
- return new DecimalType(sum);
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
- }
-
- /**
- * This calculates the minimum value of all item states of decimal type.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class Min implements GroupFunction {
-
- public Min() {
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- if (items != null && !items.isEmpty()) {
- BigDecimal min = null;
- for (Item item : items) {
- DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
- if (itemState != null) {
- if (min == null || min.compareTo(itemState.toBigDecimal()) > 0) {
- min = itemState.toBigDecimal();
- }
- }
- }
- if (min != null) {
- return new DecimalType(min);
- }
- }
- return UnDefType.UNDEF;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
- }
-
- /**
- * This calculates the maximum value of all item states of decimal type.
- *
- * @author Kai Kreuzer - Initial contribution
- *
- */
- static class Max implements GroupFunction {
-
- public Max() {
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State calculate(List
- items) {
- if (items != null && !items.isEmpty()) {
- BigDecimal max = null;
- for (Item item : items) {
- DecimalType itemState = (DecimalType) item.getStateAs(DecimalType.class);
- if (itemState != null) {
- if (max == null || max.compareTo(itemState.toBigDecimal()) < 0) {
- max = itemState.toBigDecimal();
- }
- }
- }
- if (max != null) {
- return new DecimalType(max);
- }
- }
- return UnDefType.UNDEF;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public State getStateAs(List
- items, Class extends State> stateClass) {
- State state = calculate(items);
- if (stateClass.isInstance(state)) {
- return state;
- } else {
- return null;
- }
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DateTimeType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DateTimeType.java
deleted file mode 100644
index 03860740a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DateTimeType.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class DateTimeType implements PrimitiveType, State, Command {
-
- public static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
- public static final String DATE_PATTERN_WITH_TZ = "yyyy-MM-dd'T'HH:mm:ssz";
-
- protected Calendar calendar;
-
- public DateTimeType() {
- this(Calendar.getInstance());
- }
-
- public DateTimeType(Calendar calendar) {
- this.calendar = calendar;
- }
-
- public DateTimeType(String calendarValue) {
- Date date = null;
-
- try {
- try {
- date = new SimpleDateFormat(DATE_PATTERN_WITH_TZ).parse(calendarValue);
- } catch (ParseException fpe2) {
- date = new SimpleDateFormat(DATE_PATTERN).parse(calendarValue);
- }
- } catch (ParseException fpe) {
- throw new IllegalArgumentException(calendarValue + " is not in a valid format.", fpe);
- }
-
- if (date != null) {
- calendar = Calendar.getInstance();
- calendar.setTime(date);
- }
- }
-
- public Calendar getCalendar() {
- return calendar;
- }
-
- public static DateTimeType valueOf(String value) {
- return new DateTimeType(value);
- }
-
- @Override
- public String format(String pattern) {
- try {
- return String.format(pattern, calendar);
- } catch (NullPointerException npe) {
- return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime());
- }
- }
-
- public String format(Locale locale, String pattern) {
- return String.format(locale, pattern, calendar);
- }
-
- @Override
- public String toString() {
- return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime());
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((calendar == null) ? 0 : calendar.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- DateTimeType other = (DateTimeType) obj;
- if (calendar == null) {
- if (other.calendar != null) {
- return false;
- }
- } else if (!calendar.equals(other.calendar)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DecimalType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DecimalType.java
deleted file mode 100644
index abc16614f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/DecimalType.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.math.BigDecimal;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- * The decimal type uses a BigDecimal internally and thus can be used for
- * integers, longs and floating point numbers alike.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class DecimalType extends Number implements PrimitiveType, State, Command, Comparable {
-
- private static final long serialVersionUID = 4226845847123464690L;
-
- public static final DecimalType ZERO = new DecimalType(0);
-
- protected BigDecimal value;
-
- public DecimalType() {
- this.value = BigDecimal.ZERO;
- }
-
- public DecimalType(BigDecimal value) {
- this.value = value;
- }
-
- public DecimalType(long value) {
- this.value = BigDecimal.valueOf(value);
- }
-
- public DecimalType(double value) {
- this.value = BigDecimal.valueOf(value);
- }
-
- public DecimalType(String value) {
- this.value = new BigDecimal(value);
- }
-
- @Override
- public String toString() {
- return value.toPlainString();
- }
-
- public static DecimalType valueOf(String value) {
- return new DecimalType(value);
- }
-
- @Override
- public String format(String pattern) {
- if (pattern.contains("%d")) {
- return String.format(pattern, value.toBigInteger());
- } else {
- return String.format(pattern, value);
- }
- }
-
- public BigDecimal toBigDecimal() {
- return value;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof DecimalType)) {
- return false;
- }
- DecimalType other = (DecimalType) obj;
- if (value == null) {
- if (other.value != null) {
- return false;
- }
- } else if (value.compareTo(other.value) != 0) {
- return false;
- }
- return true;
- }
-
- @Override
- public int compareTo(DecimalType o) {
- return value.compareTo(o.toBigDecimal());
- }
-
- @Override
- public double doubleValue() {
- return value.doubleValue();
- }
-
- @Override
- public float floatValue() {
- return value.floatValue();
- }
-
- @Override
- public int intValue() {
- return value.intValue();
- }
-
- @Override
- public long longValue() {
- return value.longValue();
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/HSBType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/HSBType.java
deleted file mode 100644
index b3ff393ce..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/HSBType.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.awt.Color;
-import java.math.BigDecimal;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.ComplexType;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- * The HSBType is a complex type with constituents for hue, saturation and
- * brightness and can be used for color items.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class HSBType extends PercentType implements ComplexType, State, Command {
-
- private static final long serialVersionUID = 322902950356613226L;
-
- // constants for the constituents
- public static final String KEY_HUE = "h";
- public static final String KEY_SATURATION = "s";
- public static final String KEY_BRIGHTNESS = "b";
-
- // constants for colors
- public static final HSBType BLACK = new HSBType(Color.BLACK);
- public static final HSBType WHITE = new HSBType(Color.WHITE);
- public static final HSBType RED = new HSBType(Color.RED);
- public static final HSBType GREEN = new HSBType(Color.GREEN);
- public static final HSBType BLUE = new HSBType(Color.BLUE);
-
- protected BigDecimal hue;
- protected BigDecimal saturation;
-
- // the inherited field "value" of the parent DecimalType corresponds to the
- // "brightness"
-
- public HSBType(Color color) {
- if (color != null) {
- float[] hsbValues = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
- this.hue = BigDecimal.valueOf(hsbValues[0] * 360);
- this.saturation = BigDecimal.valueOf(hsbValues[1] * 100);
- this.value = BigDecimal.valueOf(hsbValues[2] * 100);
- } else {
- throw new IllegalArgumentException("Constructor argument must not be null");
- }
- }
-
- public HSBType(DecimalType h, PercentType s, PercentType b) {
- this.hue = h.toBigDecimal();
- this.saturation = s.toBigDecimal();
- this.value = b.toBigDecimal();
- }
-
- public HSBType(String value) {
- if (value != null) {
- String[] constituents = value.split(",");
- if (constituents.length == 3) {
- this.hue = new BigDecimal(constituents[0]);
- this.saturation = new BigDecimal(constituents[1]);
- this.value = new BigDecimal(constituents[2]);
- } else {
- throw new IllegalArgumentException(value + " is not a valid HSBType syntax");
- }
- } else {
- throw new IllegalArgumentException("Constructor argument must not be null");
- }
- }
-
- public static HSBType valueOf(String value) {
- return new HSBType(value);
- }
-
- @Override
- public SortedMap getConstituents() {
- TreeMap map = new TreeMap<>();
- map.put(KEY_HUE, getHue());
- map.put(KEY_SATURATION, getSaturation());
- map.put(KEY_BRIGHTNESS, getBrightness());
- return map;
- }
-
- public DecimalType getHue() {
- return new DecimalType(hue);
- }
-
- public PercentType getSaturation() {
- return new PercentType(saturation);
- }
-
- public PercentType getBrightness() {
- return new PercentType(value);
- }
-
- public PercentType getRed() {
- return byteToPercentType(toColor().getRed());
- }
-
- public PercentType getGreen() {
- return byteToPercentType(toColor().getGreen());
- }
-
- public PercentType getBlue() {
- return byteToPercentType(toColor().getBlue());
- }
-
- private PercentType byteToPercentType(int byteValue) {
- BigDecimal percentValue = new BigDecimal(byteValue).multiply(BigDecimal.valueOf(100))
- .divide(BigDecimal.valueOf(255), 2, BigDecimal.ROUND_HALF_UP);
- return new PercentType(percentValue);
- }
-
- public Color toColor() {
- return Color.getHSBColor(hue.floatValue() / 360, saturation.floatValue() / 100, value.floatValue() / 100);
- }
-
- @Override
- public String toString() {
- return getHue() + "," + getSaturation() + "," + getBrightness();
- }
-
- @Override
- public int hashCode() {
- int tmp = 10000 * (getHue() == null ? 0 : getHue().hashCode());
- tmp += 100 * (getSaturation() == null ? 0 : getSaturation().hashCode());
- tmp += (getBrightness() == null ? 0 : getBrightness().hashCode());
- return tmp;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof HSBType)) {
- return false;
- }
- HSBType other = (HSBType) obj;
- if ((getHue() != null && other.getHue() == null) || (getHue() == null && other.getHue() != null)
- || (getSaturation() != null && other.getSaturation() == null)
- || (getSaturation() == null && other.getSaturation() != null)
- || (getBrightness() != null && other.getBrightness() == null)
- || (getBrightness() == null && other.getBrightness() != null)) {
- return false;
- }
- if (!getHue().equals(other.getHue()) || !getSaturation().equals(other.getSaturation())
- || !getBrightness().equals(other.getBrightness())) {
- return false;
- }
- return true;
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/IncreaseDecreaseType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/IncreaseDecreaseType.java
deleted file mode 100644
index 009c19777..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/IncreaseDecreaseType.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum IncreaseDecreaseType implements PrimitiveType, Command {
- INCREASE,
- DECREASE;
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OnOffType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OnOffType.java
deleted file mode 100644
index 1467feb6b..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OnOffType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum OnOffType implements PrimitiveType, State, Command {
- ON,
- OFF;
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OpenClosedType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OpenClosedType.java
deleted file mode 100644
index 38cd56d19..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/OpenClosedType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum OpenClosedType implements PrimitiveType, State, Command {
- OPEN,
- CLOSED;
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PercentType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PercentType.java
deleted file mode 100644
index c8dda9a9a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PercentType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.math.BigDecimal;
-
-/**
- * The PercentType extends the {@link DecimalType} by putting constraints for its value on top (0-100).
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class PercentType extends DecimalType {
-
- private static final long serialVersionUID = -9066279845951780879L;
-
- public static final PercentType ZERO = new PercentType(0);
- public static final PercentType HUNDRED = new PercentType(100);
-
- public PercentType() {
- super();
- }
-
- public PercentType(int value) {
- super(value);
- validateValue(this.value);
- }
-
- public PercentType(String value) {
- super(value);
- validateValue(this.value);
- }
-
- public PercentType(BigDecimal value) {
- super(value);
- validateValue(this.value);
- }
-
- private void validateValue(BigDecimal value) {
- if (BigDecimal.ZERO.compareTo(value) > 0 || new BigDecimal(100).compareTo(value) < 0) {
- throw new IllegalArgumentException("Value must be between 0 and 100");
- }
- }
-
- public static PercentType valueOf(String value) {
- return new PercentType(value);
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PointType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PointType.java
deleted file mode 100644
index f02f76124..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/PointType.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import java.math.BigDecimal;
-import java.util.Formatter;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.commons.lang.StringUtils;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.ComplexType;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- * This type can be used for items that are dealing with GPS functionality.
- *
- * @author Gaël L'hopital - Initial contribution
- */
-public class PointType implements ComplexType, Command, State {
-
- public static final double EARTH_GRAVITATIONAL_CONSTANT = 3.986004418e14;
- public static final double WGS84_A = 6378137; // The equatorial radius of
- // WGS84 ellipsoid (6378137
- // m).
- private BigDecimal latitude = BigDecimal.ZERO; // in decimal degrees
- private BigDecimal longitude = BigDecimal.ZERO; // in decimal degrees
- private BigDecimal altitude = BigDecimal.ZERO; // in decimal meters
- // constants for the constituents
- public static final String KEY_LATITUDE = "lat";
- public static final String KEY_LONGITUDE = "long";
- public static final String KEY_ALTITUDE = "alt";
- private static final BigDecimal CIRCLE = new BigDecimal(360);
- private static final BigDecimal FLAT = new BigDecimal(180);
- private static final BigDecimal RIGHT = new BigDecimal(90);
- public static final PointType EMPTY = new PointType(new DecimalType(0), new DecimalType(0));
-
- /**
- * Default constructor creates a point at sea level where the equator
- * (0° latitude) and the prime meridian (0° longitude) intersect. (A
- * nullary constructor is needed by
- * {@link org.openhab.core.internal.items.ItemUpdater#receiveUpdate})
- */
- @SuppressWarnings("restriction")
- public PointType() {
- }
-
- public PointType(DecimalType latitude, DecimalType longitude) {
- canonicalize(latitude, longitude);
- }
-
- public PointType(DecimalType latitude, DecimalType longitude, DecimalType altitude) {
- this(latitude, longitude);
- setAltitude(altitude);
- }
-
- public PointType(StringType latitude, StringType longitude) {
- this(new DecimalType(latitude.toString()), new DecimalType(longitude.toString()));
- }
-
- public PointType(StringType latitude, StringType longitude, StringType altitude) {
- this(new DecimalType(latitude.toString()), new DecimalType(longitude.toString()),
- new DecimalType(altitude.toString()));
- }
-
- public PointType(String value) {
- if (StringUtils.isNotBlank(value)) {
- String[] elements = value.split(",");
- if (elements.length >= 2) {
- canonicalize(new DecimalType(elements[0]), new DecimalType(elements[1]));
- if (elements.length == 3) {
- setAltitude(new DecimalType(elements[2]));
- }
- } else {
- throw new IllegalArgumentException(value + " is not a valid PointType syntax");
- }
- } else {
- throw new IllegalArgumentException("Constructor argument must not be blank");
- }
- }
-
- public DecimalType getLatitude() {
- return new DecimalType(latitude);
- }
-
- public DecimalType getLongitude() {
- return new DecimalType(longitude);
- }
-
- public DecimalType getAltitude() {
- return new DecimalType(altitude);
- }
-
- public void setAltitude(DecimalType altitude) {
- this.altitude = altitude.toBigDecimal();
- }
-
- public DecimalType getGravity() {
- double latRad = Math.toRadians(latitude.doubleValue());
- double deltaG = -2000.0 * (altitude.doubleValue() / 1000) * EARTH_GRAVITATIONAL_CONSTANT
- / (Math.pow(WGS84_A, 3.0));
- double sin2lat = Math.sin(latRad) * Math.sin(latRad);
- double sin22lat = Math.sin(2.0 * latRad) * Math.sin(2.0 * latRad);
- double result = (9.780327 * (1.0 + 5.3024e-3 * sin2lat - 5.8e-6 * sin22lat) + deltaG);
- return new DecimalType(result);
- }
-
- /**
- * Return the distance in meters from otherPoint, ignoring altitude. This algorithm also
- * ignores the oblate spheroid shape of Earth and assumes a perfect sphere, so results
- * are inexact.
- *
- * @param otherPoint
- * @return distance in meters
- * @see Haversine formula
- */
- public DecimalType distanceFrom(PointType otherPoint) {
- double dLat = Math.toRadians(otherPoint.latitude.doubleValue() - this.latitude.doubleValue());
- double dLong = Math.toRadians(otherPoint.longitude.doubleValue() - this.longitude.doubleValue());
- double a = Math.pow(Math.sin(dLat / 2D), 2D) + Math.cos(Math.toRadians(this.latitude.doubleValue()))
- * Math.cos(Math.toRadians(otherPoint.latitude.doubleValue())) * Math.pow(Math.sin(dLong / 2D), 2D);
- double c = 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a));
- return new DecimalType(WGS84_A * c);
- }
-
- /**
- *
- * Formats the value of this type according to a pattern (@see
- * {@link Formatter}). One single value of this type can be referenced by
- * the pattern using an index. The item order is defined by the natural
- * (alphabetical) order of their keys.
- *
- *
- * @param pattern the pattern to use containing indexes to reference the single
- * elements of this type.
- */
- @Override
- public String format(String pattern) {
- return String.format(pattern, getConstituents().values().toArray());
- }
-
- public static PointType valueOf(String value) {
- return new PointType(value);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(latitude.toPlainString());
- sb.append(',');
- sb.append(longitude.toPlainString());
- if (!altitude.equals(BigDecimal.ZERO)) {
- sb.append(',');
- sb.append(altitude.toPlainString());
- }
- return sb.toString();
- }
-
- @Override
- public SortedMap getConstituents() {
- SortedMap result = new TreeMap<>();
- result.put(KEY_LATITUDE, getLatitude());
- result.put(KEY_LONGITUDE, getLongitude());
- result.put(KEY_ALTITUDE, getAltitude());
- return result;
- }
-
- /**
- * Canonicalize the current latitude and longitude values such that:
- *
- *
- * -90 <= latitude <= +90 - 180 < longitude <= +180
- *
- */
- private void canonicalize(DecimalType aLat, DecimalType aLon) {
- latitude = FLAT.add(aLat.toBigDecimal()).remainder(CIRCLE);
- longitude = aLon.toBigDecimal();
- if (latitude.compareTo(BigDecimal.ZERO) == -1) {
- latitude.add(CIRCLE);
- }
- latitude = latitude.subtract(FLAT);
- if (latitude.compareTo(RIGHT) == 1) {
- latitude = FLAT.subtract(latitude);
- longitude = longitude.add(FLAT);
- } else if (latitude.compareTo(RIGHT.negate()) == -1) {
- latitude = FLAT.negate().subtract(latitude);
- longitude = longitude.add(FLAT);
- }
- longitude = FLAT.add(longitude).remainder(CIRCLE);
- if (longitude.compareTo(BigDecimal.ZERO) <= 0) {
- longitude = longitude.add(CIRCLE);
- }
- longitude = longitude.subtract(FLAT);
- }
-
- @Override
- public int hashCode() {
- int tmp = 10000 * (getLatitude() == null ? 0 : getLatitude().hashCode());
- tmp += 100 * (getLongitude() == null ? 0 : getLongitude().hashCode());
- tmp += (getAltitude() == null ? 0 : getAltitude().hashCode());
- return tmp;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof PointType)) {
- return false;
- }
- PointType other = (PointType) obj;
- if ((getLatitude() != null && other.getLatitude() == null)
- || (getLatitude() == null && other.getLatitude() != null)
- || (getLongitude() != null && other.getLongitude() == null)
- || (getLongitude() == null && other.getLongitude() != null)
- || (getAltitude() != null && other.getAltitude() == null)
- || (getAltitude() == null && other.getAltitude() != null)) {
- return false;
- }
- if (!getLatitude().equals(other.getLatitude()) || !getLongitude().equals(other.getLongitude())
- || !getAltitude().equals(other.getAltitude())) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StopMoveType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StopMoveType.java
deleted file mode 100644
index 956d9efd6..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StopMoveType.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum StopMoveType implements PrimitiveType, Command {
- STOP,
- MOVE;
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StringType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StringType.java
deleted file mode 100644
index 5d9d17d07..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/StringType.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class StringType implements PrimitiveType, State, Command {
-
- public static final StringType EMPTY = new StringType("");
-
- private final String value;
-
- public StringType(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return value;
- }
-
- public static StringType valueOf(String value) {
- return new StringType(value);
- }
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, value);
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (obj instanceof String) {
- return obj.equals(value);
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- StringType other = (StringType) obj;
- if (!value.equals(other.value)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/UpDownType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/UpDownType.java
deleted file mode 100644
index d28fa588f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/library/types/UpDownType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.library.types;
-
-import org.openhab.core.types.Command;
-import org.openhab.core.types.PrimitiveType;
-import org.openhab.core.types.State;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum UpDownType implements PrimitiveType, State, Command {
- UP,
- DOWN;
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/FilterCriteria.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/FilterCriteria.java
deleted file mode 100644
index 392501a0a..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/FilterCriteria.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence;
-
-import java.util.Date;
-
-import org.openhab.core.types.State;
-
-/**
- * This class is used to define a filter for queries to a {@link PersistenceService}.
- *
- *
- * It is designed as a Java bean, for which the different properties are constraints
- * on the query result. These properties include the item name, begin and end date and
- * the item state. A compare operator can be defined to compare not only state equality,
- * but also its decimal value (<,>).
- *
- *
- * Additionally, the filter criteria supports ordering and paging of the result, so the
- * caller can ask to only return chunks of the result of a certain size (=pageSize) from a
- * starting index (pageNumber*pageSize).
- *
- *
- * All setter methods return the filter criteria instance, so that the methods can be
- * easily chained in order to define a filter.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class FilterCriteria {
-
- /** Enumeration with all possible compare options */
- public enum Operator {
- EQ("="),
- NEQ("!="),
- GT(">"),
- LT("<"),
- GTE(">="),
- LTE("<=");
-
- private final String symbol;
-
- Operator(String symbol) {
- this.symbol = symbol;
- }
-
- String getSymbol() {
- return symbol;
- }
- }
-
- /** Enumeration with all ordering options */
- public enum Ordering {
- ASCENDING,
- DESCENDING
- }
-
- /** filter result to only contain entries for the given item */
- private String itemName;
-
- /** filter result to only contain entries that are newer than the given date */
- private Date beginDate;
-
- /** filter result to only contain entries that are older than the given date */
- private Date endDate;
-
- /** return the result list from starting index pageNumber*pageSize only */
- private int pageNumber = 0;
-
- /** return at most this many results */
- private int pageSize = Integer.MAX_VALUE;
-
- /** use this operator to compare the item state */
- private Operator operator = Operator.EQ;
-
- /** how to sort the result list by date */
- private Ordering ordering = Ordering.DESCENDING;
-
- /** filter result to only contain entries that evaluate to true with the given operator and state */
- private State state;
-
- public String getItemName() {
- return itemName;
- }
-
- public Date getBeginDate() {
- return beginDate;
- }
-
- public Date getEndDate() {
- return endDate;
- }
-
- public int getPageNumber() {
- return pageNumber;
- }
-
- public int getPageSize() {
- return pageSize;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public Ordering getOrdering() {
- return ordering;
- }
-
- public State getState() {
- return state;
- }
-
- public FilterCriteria setItemName(String itemName) {
- this.itemName = itemName;
- return this;
- }
-
- public FilterCriteria setBeginDate(Date beginDate) {
- this.beginDate = beginDate;
- return this;
- }
-
- public FilterCriteria setEndDate(Date endDate) {
- this.endDate = endDate;
- return this;
- }
-
- public FilterCriteria setPageNumber(int pageNumber) {
- this.pageNumber = pageNumber;
- return this;
- }
-
- public FilterCriteria setPageSize(int pageSize) {
- this.pageSize = pageSize;
- return this;
- }
-
- public FilterCriteria setOperator(Operator operator) {
- this.operator = operator;
- return this;
- }
-
- public FilterCriteria setOrdering(Ordering ordering) {
- this.ordering = ordering;
- return this;
- }
-
- public FilterCriteria setState(State state) {
- this.state = state;
- return this;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/HistoricItem.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/HistoricItem.java
deleted file mode 100644
index cadb1ad6b..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/HistoricItem.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence;
-
-import java.util.Date;
-
-import org.openhab.core.types.State;
-
-/**
- * This interface is used by persistence services to represent an item
- * with a certain state at a given point in time.
- *
- *
- * Note that this interface does not extend {@link Item} as the persistence
- * services could not provide an implementation that correctly implement
- * getAcceptedXTypes() and getGroupNames().
- *
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface HistoricItem {
-
- /**
- * returns the timestamp of the persisted item
- *
- * @return the timestamp of the item
- */
- Date getTimestamp();
-
- /**
- * returns the current state of the item
- *
- * @return the current state
- */
- public State getState();
-
- /**
- * returns the name of the item
- *
- * @return the name of the item
- */
- public String getName();
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/PersistenceService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/PersistenceService.java
deleted file mode 100644
index 6efc77645..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/PersistenceService.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence;
-
-import org.openhab.core.items.Item;
-
-/**
- * A persistence service which can be used to store data from openHAB.
- * This must not necessarily be a local database, a persistence service
- * can also be cloud-based or a simply data-export facility (e.g.
- * for sending data to an IoT (Internet of Things) service.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface PersistenceService {
-
- /**
- * Returns the name of this {@link PersistenceService}.
- * This name is used to uniquely identify the {@link PersistenceService}.
- *
- * @return the name to uniquely identify the {@link PersistenceService}.
- */
- String getName();
-
- /**
- * Stores the current value of the given item.
- *
- * Implementors should keep in mind that all registered
- * {@link PersistenceService}s are called synchronously. Hence long running
- * operations should be processed asynchronously. E.g. store
- * adds things to a queue which is processed by some asynchronous workers
- * (Quartz Job, Thread, etc.).
- *
- *
- * @param item the item which state should be persisted.
- */
- void store(Item item);
-
- /**
- *
- * Stores the current value of the given item under a specified alias.
- *
- *
- * Implementors should keep in mind that all registered
- * {@link PersistenceService}s are called synchronously. Hence long running
- * operations should be processed asynchronously. E.g. store
- * adds things to a queue which is processed by some asynchronous workers
- * (Quartz Job, Thread, etc.).
- *
- *
- * @param item the item which state should be persisted.
- * @param alias the alias under which the item should be persisted.
- */
- void store(Item item, String alias);
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java
deleted file mode 100644
index 66c6840f8..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence;
-
-/**
- * A queryable persistence service which can be used to store and retrieve
- * data from openHAB. This is most likely some kind of database system.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface QueryablePersistenceService extends PersistenceService {
-
- /**
- * Queries the {@link PersistenceService} for data with a given filter criteria
- *
- * @param filter the filter to apply to the query
- * @return a time series of items
- */
- Iterable query(FilterCriteria filter);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceDelegate.java
deleted file mode 100644
index db9c5ffe7..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceDelegate.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence.internal;
-
-import java.util.Locale;
-
-import org.eclipse.smarthome.core.items.Item;
-import org.eclipse.smarthome.core.persistence.PersistenceService;
-import org.openhab.core.compat1x.internal.ItemMapper;
-
-/**
- * This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
- * namespace for the persistence service. It wraps an instance with the old interface
- * into a class with the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- * @author Chris Jackson - updated API to support getId/getLabel
- */
-public class PersistenceServiceDelegate implements PersistenceService {
-
- protected org.openhab.core.persistence.PersistenceService service;
-
- public PersistenceServiceDelegate(org.openhab.core.persistence.PersistenceService service) {
- this.service = service;
- }
-
- @Override
- public String getId() {
- return service.getName();
- }
-
- @Override
- public String getLabel(Locale locale) {
- return service.getName();
- }
-
- @Override
- public void store(Item item) {
- org.openhab.core.items.Item ohItem = ItemMapper.mapToOpenHABItem(item);
- if (ohItem != null) {
- service.store(ohItem);
- }
- }
-
- @Override
- public void store(Item item, String alias) {
- org.openhab.core.items.Item ohItem = ItemMapper.mapToOpenHABItem(item);
- if (ohItem != null) {
- service.store(ohItem, alias);
- }
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java
deleted file mode 100644
index d87eb6694..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/PersistenceServiceFactory.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence.internal;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import org.openhab.core.persistence.PersistenceService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-
-/**
- * This class listens for services that implement the old persistence service interface and registers
- * an according service for each under the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component(immediate = true)
-public class PersistenceServiceFactory {
-
- private Map> delegates = new HashMap<>();
- private BundleContext context;
-
- private Set persistenceServices = new HashSet<>();
-
- @Activate
- public void activate(BundleContext context) {
- this.context = context;
- for (PersistenceService service : persistenceServices) {
- registerDelegateService(service);
- }
- }
-
- @Deactivate
- public void deactivate() {
- for (ServiceRegistration serviceReg : delegates
- .values()) {
- serviceReg.unregister();
- }
- delegates.clear();
- this.context = null;
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void addPersistenceService(PersistenceService service) {
- if (context != null) {
- registerDelegateService(service);
- } else {
- persistenceServices.add(service);
- }
- }
-
- public void removePersistenceService(PersistenceService service) {
- if (context != null) {
- unregisterDelegateService(service);
- }
- }
-
- private void registerDelegateService(PersistenceService persistenceService) {
- if (!delegates.containsKey(persistenceService.getName())) {
- org.eclipse.smarthome.core.persistence.PersistenceService service = (persistenceService instanceof org.openhab.core.persistence.QueryablePersistenceService)
- ? new QueryablePersistenceServiceDelegate(persistenceService)
- : new PersistenceServiceDelegate(persistenceService);
- Dictionary props = new Hashtable<>();
- ServiceRegistration serviceReg = context
- .registerService(org.eclipse.smarthome.core.persistence.PersistenceService.class, service, props);
- delegates.put(persistenceService.getName(), serviceReg);
- }
- }
-
- private void unregisterDelegateService(PersistenceService service) {
- if (delegates.containsKey(service.getName())) {
- ServiceRegistration serviceReg = delegates
- .get(service.getName());
- delegates.remove(service.getName());
- serviceReg.unregister();
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/QueryablePersistenceServiceDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/QueryablePersistenceServiceDelegate.java
deleted file mode 100644
index 07ae8b7f3..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/persistence/internal/QueryablePersistenceServiceDelegate.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.persistence.internal;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.smarthome.core.persistence.FilterCriteria;
-import org.eclipse.smarthome.core.persistence.HistoricItem;
-import org.eclipse.smarthome.core.persistence.PersistenceItemInfo;
-import org.eclipse.smarthome.core.persistence.QueryablePersistenceService;
-import org.eclipse.smarthome.core.types.State;
-import org.openhab.core.compat1x.internal.TypeMapper;
-import org.openhab.core.persistence.FilterCriteria.Operator;
-import org.openhab.core.persistence.FilterCriteria.Ordering;
-
-/**
- * This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
- * namespace for the queryable persistence service. It wraps an instance with the old interface
- * into a class with the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class QueryablePersistenceServiceDelegate extends PersistenceServiceDelegate
- implements QueryablePersistenceService {
-
- public QueryablePersistenceServiceDelegate(org.openhab.core.persistence.PersistenceService persistenceService) {
- super(persistenceService);
- }
-
- @Override
- public Iterable query(FilterCriteria filter) {
- org.openhab.core.persistence.FilterCriteria mappedFilter = new org.openhab.core.persistence.FilterCriteria()
- .setBeginDate(filter.getBeginDate()).setEndDate(filter.getEndDate()).setItemName(filter.getItemName())
- .setOperator(mapOperator(filter.getOperator())).setOrdering(mapOrdering(filter.getOrdering()))
- .setPageNumber(filter.getPageNumber()).setPageSize(filter.getPageSize())
- .setState(mapState(filter.getState()));
- org.openhab.core.persistence.QueryablePersistenceService pService = (org.openhab.core.persistence.QueryablePersistenceService) service;
- Iterable historicItems = pService.query(mappedFilter);
- List result = new ArrayList<>();
- if (historicItems != null) {
- for (final org.openhab.core.persistence.HistoricItem item : historicItems) {
- result.add(new HistoricItem() {
- @Override
- public Date getTimestamp() {
- return item.getTimestamp();
- }
-
- @Override
- public State getState() {
- return (State) TypeMapper.mapToESHType(item.getState());
- }
-
- @Override
- public String getName() {
- return item.getName();
- }
- });
- }
- }
- return result;
- }
-
- private org.openhab.core.types.State mapState(State state) {
- return (org.openhab.core.types.State) TypeMapper.mapToOpenHABType(state);
- }
-
- private Ordering mapOrdering(FilterCriteria.Ordering ordering) {
- if (ordering == null) {
- return null;
- }
-
- return org.openhab.core.persistence.FilterCriteria.Ordering.valueOf(ordering.toString());
- }
-
- private Operator mapOperator(FilterCriteria.Operator operator) {
- if (operator == null) {
- return null;
- }
- return org.openhab.core.persistence.FilterCriteria.Operator.valueOf(operator.toString());
- }
-
- @Override
- public Set getItemInfo() {
- return Collections.emptySet();
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionDoc.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionDoc.java
deleted file mode 100644
index 90bcc6b9e..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionDoc.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.scriptengine.action;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Target(ElementType.METHOD)
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ActionDoc {
- String text();
-
- String returns() default "";
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionService.java
deleted file mode 100644
index 1edad0407..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ActionService.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.scriptengine.action;
-
-/**
- * This interface must be implemented by services that want to contribute script actions.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ActionService {
-
- /**
- * returns the FQCN of the action class.
- *
- * @return the FQCN of the action class
- */
- String getActionClassName();
-
- /**
- * Returns the action class itself
- *
- * @return the action class
- */
- Class> getActionClass();
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ParamDoc.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ParamDoc.java
deleted file mode 100644
index a1bd3e495..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/ParamDoc.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.scriptengine.action;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Target(ElementType.PARAMETER)
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ParamDoc {
- String name();
-
- String text() default "";
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceDelegate.java
deleted file mode 100644
index 19cd2a964..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceDelegate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.scriptengine.action.internal;
-
-import org.eclipse.smarthome.model.script.engine.action.ActionService;
-
-/**
- * This class serves as a mapping from the "old" org.openhab namespace to the new org.eclipse.smarthome
- * namespace for the action service. It wraps an instance with the old interface
- * into a class with the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ActionServiceDelegate implements ActionService {
-
- private org.openhab.core.scriptengine.action.ActionService service;
-
- public ActionServiceDelegate(org.openhab.core.scriptengine.action.ActionService service) {
- this.service = service;
- }
-
- @Override
- public String getActionClassName() {
- return service.getActionClassName();
- }
-
- @Override
- public Class> getActionClass() {
- return service.getActionClass();
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceFactory.java
deleted file mode 100644
index 04ae7b10f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/scriptengine/action/internal/ActionServiceFactory.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.scriptengine.action.internal;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import org.openhab.core.scriptengine.action.ActionService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-
-/**
- * This class listens for services that implement the old action service interface and registers
- * an according service for each under the new interface.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-@Component
-public class ActionServiceFactory {
-
- private Map> delegates = new HashMap<>();
- private BundleContext context;
-
- private Set actionServices = new HashSet<>();
-
- @Activate
- public void activate(BundleContext context) {
- this.context = context;
- for (ActionService service : actionServices) {
- registerDelegateService(service);
- }
- }
-
- @Deactivate
- public void deactivate() {
- for (ServiceRegistration serviceReg : delegates
- .values()) {
- serviceReg.unregister();
- }
- delegates.clear();
- this.context = null;
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void addActionService(ActionService service) {
- if (context != null) {
- registerDelegateService(service);
- } else {
- actionServices.add(service);
- }
- }
-
- public void removeActionService(ActionService service) {
- if (context != null) {
- unregisterDelegateService(service);
- }
- }
-
- private void registerDelegateService(ActionService actionService) {
- if (!delegates.containsKey(actionService.getActionClassName())) {
- ActionServiceDelegate service = new ActionServiceDelegate(actionService);
- Dictionary props = new Hashtable<>();
- ServiceRegistration serviceReg = context
- .registerService(org.eclipse.smarthome.model.script.engine.action.ActionService.class, service,
- props);
- delegates.put(actionService.getActionClassName(), serviceReg);
- }
- }
-
- private void unregisterDelegateService(ActionService service) {
- if (delegates.containsKey(service.getActionClassName())) {
- ServiceRegistration serviceReg = delegates
- .get(service.getActionClassName());
- delegates.remove(service.getActionClassName());
- serviceReg.unregister();
- }
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/service/AbstractActiveService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/service/AbstractActiveService.java
deleted file mode 100644
index a34c3ba0f..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/service/AbstractActiveService.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.service;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Base class for services that frequently run some action in a separate thread in the
- * background.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public abstract class AbstractActiveService {
-
- private final Logger logger = LoggerFactory.getLogger(AbstractActiveService.class);
-
- /** true
if this binding is configured properly which means that all necessary data is available */
- private boolean properlyConfigured = false;
-
- /**
- * indicates that the background thread will shutdown after the current
- * execution cycle.
- */
- protected boolean shutdown = false;
-
- /**
- * holds the instance of the refresh thread or is null
if
- * there is no thread active at the moment
- */
- private Thread refreshThread;
-
- public AbstractActiveService() {
- super();
- }
-
- public void activate() {
- start();
- }
-
- public void deactivate() {
- shutdown();
- }
-
- /**
- * Takes care about starting the refresh thread. It creates a new
- * RefreshThread if no instance exists.
- */
- protected void start() {
- if (!isProperlyConfigured()) {
- logger.trace("{} won't be started because it isn't yet properly configured.", getName());
- return;
- }
-
- shutdown = false;
- if (!isRunning()) {
- this.refreshThread = new RefreshThread(getName(), getRefreshInterval());
- this.refreshThread.start();
- } else {
- logger.trace("{} is already started > calling start() changed nothing.", getName());
- }
- }
-
- /**
- * Gracefully shuts down the refresh background thread. It will shuts down
- * after the current execution cycle.
- */
- public void shutdown() {
- this.shutdown = true;
- }
-
- /**
- * Interrupts the refresh thread immediately.
- */
- public void interrupt() {
- if (isRunning()) {
- this.refreshThread.interrupt();
- logger.trace("{} has been interrupted.", getName());
- }
- }
-
- public boolean isRunning() {
- if (this.refreshThread != null) {
- return this.refreshThread.isAlive();
- }
- return false;
- }
-
- /**
- * @return true
if this binding is configured properly which means
- * that all necessary data is available
- */
- public final boolean isProperlyConfigured() {
- return properlyConfigured;
- }
-
- /**
- * Used to define whether this binding is fully configured so that it can be
- * activated and used.
- * Note that the implementation will automatically start the active service if
- * true
is passed as a parameter.
- *
- * @param properlyConfigured
- */
- public void setProperlyConfigured(boolean properlyConfigured) {
- this.properlyConfigured = properlyConfigured;
- if (properlyConfigured && !isRunning()) {
- start();
- } else if (!properlyConfigured && isRunning()) {
- shutdown();
- }
- }
-
- /**
- * The working method which is called by the refresh thread frequently.
- * Developers should put their binding code here.
- */
- protected abstract void execute();
-
- /**
- * Returns the refresh interval to be used by the RefreshThread between to
- * calls of the execute method.
- *
- * @return the refresh interval
- */
- protected abstract long getRefreshInterval();
-
- /**
- * Returns the name of the Refresh thread.
- *
- * @return the name of the refresh thread.
- */
- protected abstract String getName();
-
- /**
- * Worker thread which calls the execute method frequently.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- */
- class RefreshThread extends Thread {
-
- private long refreshInterval;
-
- public RefreshThread(String name, long refreshInterval) {
- super(name);
- this.setDaemon(true);
- this.refreshInterval = refreshInterval;
-
- // reset 'interrupted' after stopping this refresh thread ...
- shutdown = false;
- }
-
- @Override
- public void run() {
- logger.info("{} has been started", getName());
-
- while (!shutdown) {
- try {
- execute();
- } catch (RuntimeException e) {
- logger.error("Error while executing background thread {}", getName(), e);
- }
- pause(refreshInterval);
- }
-
- refreshThread = null;
- logger.info("{} has been shut down", getName());
- }
-
- /**
- * Pause polling for the given refreshInterval
. Possible
- * {@link InterruptedException} is logged with no further action.
- *
- * @param refreshInterval
- */
- protected void pause(long refreshInterval) {
- try {
- Thread.sleep(refreshInterval);
- } catch (InterruptedException e) {
- logger.debug("pausing thread {} interrupted", super.getName());
- }
- }
-
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationException.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationException.java
deleted file mode 100644
index dfba48cb6..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.transform;
-
-/**
- * A TransformationException is thrown when any step of a transformation went
- * wrong. The originating exception should be attached to increase traceability.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- */
-public class TransformationException extends Exception {
-
- /** generated serial Version UID */
- private static final long serialVersionUID = -535237375844795145L;
-
- public TransformationException(String message) {
- super(message);
- }
-
- public TransformationException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationHelper.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationHelper.java
deleted file mode 100644
index e05414967..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationHelper.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.transform;
-
-import java.util.Collection;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class TransformationHelper {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(TransformationHelper.class);
-
- /**
- * Queries the OSGi service registry for a service that provides a transformation service of
- * a given transformation type (e.g. REGEX, XSLT, etc.)
- *
- * @param transformationType the desired transformation type
- * @return a service instance or null, if none could be found
- */
- public static TransformationService getTransformationService(BundleContext context, String transformationType) {
- if (context != null) {
- String filter = "(smarthome.transform=" + transformationType + ")";
- try {
- Collection> refs = context
- .getServiceReferences(org.eclipse.smarthome.core.transform.TransformationService.class, filter);
- if (refs != null && !refs.isEmpty()) {
- return new TransformationServiceDelegate(context.getService(refs.iterator().next()));
- } else {
- LOGGER.warn("Cannot get service reference for transformation service of type {}",
- transformationType);
- }
- } catch (InvalidSyntaxException e) {
- LOGGER.warn("Cannot get service reference for transformation service of type {}", transformationType,
- e);
- }
- }
- return null;
- }
-
- private static class TransformationServiceDelegate implements TransformationService {
-
- org.eclipse.smarthome.core.transform.TransformationService delegate;
-
- public TransformationServiceDelegate(org.eclipse.smarthome.core.transform.TransformationService delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public String transform(String function, String source) throws TransformationException {
- try {
- return delegate.transform(function, source);
- } catch (org.eclipse.smarthome.core.transform.TransformationException e) {
- throw new TransformationException(e.getMessage());
- }
- }
-
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationService.java
deleted file mode 100644
index a0fadaa97..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/TransformationService.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.transform;
-
-/**
- * A TransformationProcessor transforms a given input and returns the transformed
- * result. Transformations could make sense in various situations, for example:
- *
- * - extract certain informations from a weather forecast website
- * - extract the status of your TV which provides it's status on a webpage
- * - postprocess the output from a serial device to be human readable
- *
- * One could provide his own processors by providing a new implementation of this
- * Interface.
- *
- * @author Thomas Eichstaedt-Engelen - Initial contribution
- * @author Kai Kreuzer - Initial contribution
- */
-public interface TransformationService {
-
- /**
- * Transforms the input source
by means of the given function
- * and returns the transformed output. If the transformation couldn't be completed
- * for any reason, one should return the unchanged source
. This
- * method should never return null
. In case of any error an
- * {@link TransformationException} should be thrown.
- *
- * @param function the function to be used to transform the input
- * @param source the input to be transformed
- * @return the transformed result or the unchanged source
if the
- * transformation couldn't be completed for any reason.
- * @throws TransformationException if any error occurs
- */
- String transform(String function, String source) throws TransformationException;
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/actions/Transformation.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/actions/Transformation.java
deleted file mode 100644
index 8024d2621..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/transform/actions/Transformation.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.transform.actions;
-
-import org.openhab.core.compat1x.internal.CompatibilityActivator;
-import org.openhab.core.transform.TransformationException;
-import org.openhab.core.transform.TransformationHelper;
-import org.openhab.core.transform.TransformationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class holds static "action" methods that can be used from within rules to execute
- * transformations.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class Transformation {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(Transformation.class);
-
- /**
- * Applies a transformation of a given type with some function to a value.
- *
- * @param type the transformation type, e.g. REGEX or MAP
- * @param function the function to call, this value depends on the transformation type
- * @param value the value to apply the transformation to
- * @return the transformed value or the original one, if there was no service registered for the
- * given type or a transformation exception occurred.
- */
- public static String transform(String type, String function, String value) {
- String result;
- TransformationService service = TransformationHelper
- .getTransformationService(CompatibilityActivator.getContext(), type);
- if (service != null) {
- try {
- result = service.transform(function, value);
- } catch (TransformationException e) {
- LOGGER.error("Error executing the transformation '{}': {}", type, e.getMessage());
- result = value;
- }
- } else {
- LOGGER.warn("No transformation service '{}' could be found.", type);
- result = value;
- }
- return result;
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Command.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Command.java
deleted file mode 100644
index 06b7a6295..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Command.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-/**
- * This is a marker interface for all command types.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface Command extends Type {
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/ComplexType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/ComplexType.java
deleted file mode 100644
index ae2fff917..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/ComplexType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-import java.util.SortedMap;
-
-/**
- * A complex type consists out of a sorted list of primitive constituents.
- * Each constituent can be referred to by a unique name.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface ComplexType extends Type {
-
- /**
- * Returns all constituents with their names as a sorted map
- *
- * @return all constituents with their names
- */
- public SortedMap getConstituents();
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/EventType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/EventType.java
deleted file mode 100644
index 589b76a56..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/EventType.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-/**
- * Due to the duality of some types (which can be states and commands at the
- * same time), we need to be able to differentiate what the meaning of a
- * message on the bus is - does "item ON" mean that its state has changed to
- * ON or that it should turn itself ON? To decide this, we send the event
- * type as an additional information on the event bus for each message.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum EventType {
- COMMAND,
- UPDATE;
-
- @Override
- public String toString() {
- switch (this) {
- case COMMAND:
- return "command";
- case UPDATE:
- return "update";
- }
- return "";
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/PrimitiveType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/PrimitiveType.java
deleted file mode 100644
index 4f4b2a4e0..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/PrimitiveType.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-/**
- * A primitive type consists of a single value like a string, a number, etc.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface PrimitiveType extends Type {
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/State.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/State.java
deleted file mode 100644
index ef96d48c8..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/State.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-/**
- * This is a marker interface for all state types.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface State extends Type {
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Type.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Type.java
deleted file mode 100644
index 4eb973feb..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/Type.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-import java.util.Formatter;
-
-/**
- * This is a parent interface for all states and commands.
- * It was introduced as many states can be commands at the same time and
- * vice versa. E.g a light can have the state ON or OFF and one can
- * also send ON and OFF as commands to the device. This duality is
- * captured by this marker interface and allows implementing classes
- * to be both state and command at the same time.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface Type {
-
- /**
- * Formats the value of this type according to a pattern (see {@link Formatter}).
- *
- * @param pattern the pattern to use
- * @return the formatted string
- */
- public String format(String pattern);
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/TypeParser.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/TypeParser.java
deleted file mode 100644
index 576a93c39..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/TypeParser.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/**
- * This is a helper class that helps parsing a string into an openHAB type (state or command).
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class TypeParser {
-
- /**
- *
- * Determines a state from a string. Possible state types are passed as a parameter.
- * Note that the order matters here; the first type that accepts the string as a valid
- * value, will be used for the state.
- *
- *
- * Example: The type list is OnOffType.class,StringType.class. The string "ON" is now
- * accepted by the OnOffType and thus OnOffType.ON will be returned (and not a StringType
- * with value "ON").
- *
- *
- * @param types possible types of the state to consider
- * @param s the string to parse
- * @return the corresponding State instance or null
- */
- public static State parseState(List> types, String s) {
- for (Class extends Type> type : types) {
- try {
- Method valueOf = type.getMethod("valueOf", String.class);
- State state = (State) valueOf.invoke(type, s);
- if (state != null) {
- return state;
- }
- } catch (NoSuchMethodException e) {
- } catch (IllegalArgumentException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- }
- }
- return null;
- }
-
- /**
- *
- * Determines a command from a string. Possible command types are passed as a parameter.
- * Note that the order matters here; the first type that accepts the string as a valid
- * value, will be used for the command.
- *
- *
- * Example: The type list is OnOffType.class,StringType.class. The string "ON" is now
- * accepted by the OnOffType and thus OnOffType.ON will be returned (and not a StringType
- * with value "ON").
- *
- *
- * @param types possible types of the command to consider
- * @param s the string to parse
- * @return the corresponding Command instance or null
- */
- public static Command parseCommand(List> types, String s) {
- if (s != null) {
- for (Class extends Command> type : types) {
- try {
- Method valueOf = type.getMethod("valueOf", String.class);
- Command value = (Command) valueOf.invoke(type, s);
- if (value != null) {
- return value;
- }
- } catch (NoSuchMethodException e) {
- } catch (IllegalArgumentException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- }
- }
- }
- return null;
- }
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/UnDefType.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/UnDefType.java
deleted file mode 100644
index 3684bcea0..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/core/types/UnDefType.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.core.types;
-
-/**
- * There are situations when item states do not have any defined value.
- * This might be because they have not been initialized yet (never
- * received an state update so far) or because their state is ambiguous
- * (e.g. a dimmed light that is treated as a switch (ON/OFF) will have
- * an undefined state if it is dimmed to 50%).
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public enum UnDefType implements PrimitiveType, State {
- UNDEF,
- NULL;
-
- @Override
- public String toString() {
- switch (this) {
- case UNDEF:
- return "Undefined";
- case NULL:
- return "Uninitialized";
- }
- return "";
- }
-
- @Override
- public String format(String pattern) {
- return String.format(pattern, this.toString());
- }
-
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/Console.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/Console.java
deleted file mode 100644
index f48a57112..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/Console.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.io.console;
-
-/**
- * This interface must be implemented by consoles which want to use the
- * {@link ConsoleInterpreter}.
- * It allows basic output commands.
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public interface Console {
-
- public void print(String s);
-
- public void println(String s);
-
- /**
- * usage output is treated differently from other output as it might
- * differ between different kinds of consoles
- *
- * @param s the main usage string (console independent)
- */
- public void printUsage(String s);
-}
diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/ConsoleInterpreter.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/ConsoleInterpreter.java
deleted file mode 100644
index 1003fafd3..000000000
--- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/console/ConsoleInterpreter.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright (c) 2010-2019 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.io.console;
-
-/**
- * This class provides generic methods for handling console input (i.e. pure strings).
- *
- * NOTE: This class is only kept for backward compatibility so that openHAB 1 Add-ons still compile.
- * It must not be used productively!
- *
- * @author Kai Kreuzer - Initial contribution
- */
-public class ConsoleInterpreter {
-
- /**
- * This method simply takes a list of arguments, where the first one is treated
- * as the console command (such as "update", "send" etc.). The following entries
- * are then the arguments for this command.
- * If the command is unknown, the complete usage is printed to the console.
- *
- * @param args array which contains the console command and all its arguments
- * @param console the console for printing messages for the user
- */
- public static void handleRequest(String[] args, Console console) {
- }
-
- /**
- * This method handles an update command.
- *
- * @param args array which contains the arguments for the update command
- * @param console the console for printing messages for the user
- */
- public static void handleUpdate(String[] args, Console console) {
- }
-
- /**
- * This method handles a send command.
- *
- * @param args array which contains the arguments for the send command
- * @param console the console for printing messages for the user
- */
- public static void handleSend(String[] args, Console console) {
- }
-
- /**
- * This method handles an items command.
- *
- * @param args array which contains the arguments for the items command
- * @param console the console for printing messages for the user
- */
- public static void handleItems(String[] args, Console console) {
- }
-
- /**
- * This method handles a status command.
- *
- * @param args array which contains the arguments for the status command
- * @param console the console for printing messages for the user
- */
- public static void handleStatus(String[] args, Console console) {
- }
-
- /**
- * This method handles a say command.
- *
- * @param args array which contains the arguments for the status command
- * @param console the console for printing messages for the user
- */
- public static void handleSay(String[] args, Console console) {
- }
-
- public static void handleScript(String[] args, Console console) {
- }
-
- /** returns a CR-separated list of usage texts for all available commands */
- private static String getUsage() {
- StringBuilder sb = new StringBuilder();
- for (String usage : ConsoleInterpreter.getUsages()) {
- sb.append(usage + "\n");
- }
- return sb.toString();
- }
-
- /** returns an array of the usage texts for all available commands */
- public static String[] getUsages() {
- return new String[] { getUpdateUsage(), getCommandUsage(), getStatusUsage(), getItemsUsage(), getSayUsage(),
- getScriptUsage() };
- }
-
- public static String getUpdateUsage() {
- return "update - - sends a status update for an item";
- }
-
- public static String getCommandUsage() {
- return "send
- - sends a command for an item";
- }
-
- public static String getStatusUsage() {
- return "status
- - shows the current status of an item";
- }
-
- public static String getItemsUsage() {
- return "items [] - lists names and types of all items matching the pattern";
- }
-
- public static String getSayUsage() {
- return "say - Says a message through TTS on the host machine";
- }
-
- public static String getScriptUsage() {
- return ">