[automation] Added nullness annotations (#910)

* Added nullness annotations

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/913/head
Christoph Weitkamp 2019-07-08 10:53:25 +02:00 committed by Markus Rathgeb
parent 7bad7f6e3f
commit abab07dfb9
27 changed files with 169 additions and 113 deletions

View File

@ -17,18 +17,16 @@ import java.util.Map;
import org.eclipse.smarthome.core.audio.AudioException; import org.eclipse.smarthome.core.audio.AudioException;
import org.eclipse.smarthome.core.audio.AudioManager; import org.eclipse.smarthome.core.audio.AudioManager;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* This is an ModuleHandler implementation for Actions that play a sound file from the file system. * This is an ModuleHandler implementation for Actions that play a sound file from the file system.
* *
* @author Kai Kreuzer - Initial contribution and API * @author Kai Kreuzer - Initial contribution
*
*/ */
public class PlayActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class PlayActionHandler extends BaseActionModuleHandler {
public static final String TYPE_ID = "media.PlayAction"; public static final String TYPE_ID = "media.PlayAction";
public static final String PARAM_SOUND = "sound"; public static final String PARAM_SOUND = "sound";

View File

@ -16,16 +16,14 @@ import java.util.Map;
import org.eclipse.smarthome.core.voice.VoiceManager; import org.eclipse.smarthome.core.voice.VoiceManager;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
/** /**
* This is an ModuleHandler implementation for Actions that trigger a TTS output through "say". * This is an ModuleHandler implementation for Actions that trigger a TTS output through "say".
* *
* @author Kai Kreuzer - Initial contribution and API * @author Kai Kreuzer - Initial contribution
*
*/ */
public class SayActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class SayActionHandler extends BaseActionModuleHandler {
public static final String TYPE_ID = "media.SayAction"; public static final String TYPE_ID = "media.SayAction";
public static final String PARAM_TEXT = "text"; public static final String PARAM_TEXT = "text";

View File

@ -18,16 +18,15 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler; import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler;
/** /**
* The SimpleActionHandlerDelegate allows the registration of {@link SimpleActionHandler}s to the RuleManager. * The SimpleActionHandlerDelegate allows the registration of {@link SimpleActionHandler}s to the RuleManager.
* *
* @author Simon Merschjohann * @author Simon Merschjohann - Initial contribution
*/ */
public class SimpleActionHandlerDelegate extends BaseModuleHandler<Action> implements ActionHandler { public class SimpleActionHandlerDelegate extends BaseActionModuleHandler {
private org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler actionHandler; private org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler actionHandler;

View File

@ -15,17 +15,15 @@ package org.openhab.core.automation.module.script.rulesupport.internal.delegates
import java.util.Map; import java.util.Map;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleConditionHandler; import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleConditionHandler;
/** /**
* The SimpleConditionHandlerDelegate allows the registration of {@link SimpleConditionHandler}s to the RuleManager. * The SimpleConditionHandlerDelegate allows the registration of {@link SimpleConditionHandler}s to the RuleManager.
* *
* @author Simon Merschjohann * @author Simon Merschjohann - Initial contribution
*
*/ */
public class SimpleConditionHandlerDelegate extends BaseModuleHandler<Condition> implements ConditionHandler { public class SimpleConditionHandlerDelegate extends BaseConditionModuleHandler {
private SimpleConditionHandler conditionHandler; private SimpleConditionHandler conditionHandler;

View File

@ -14,16 +14,16 @@ package org.openhab.core.automation.module.script.rulesupport.internal.delegates
import org.openhab.core.automation.ModuleHandlerCallback; import org.openhab.core.automation.ModuleHandlerCallback;
import org.openhab.core.automation.Trigger; import org.openhab.core.automation.Trigger;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
import org.openhab.core.automation.handler.TriggerHandler;
import org.openhab.core.automation.handler.TriggerHandlerCallback; import org.openhab.core.automation.handler.TriggerHandlerCallback;
/** /**
* The {@link SimpleTriggerHandlerDelegate} allows to define triggers in a script language in different ways. * The {@link SimpleTriggerHandlerDelegate} allows to define triggers in a script language in different ways.
* *
* @author Simon Merschjohann * @author Simon Merschjohann - Initial contribution
*/ */
public class SimpleTriggerHandlerDelegate extends BaseModuleHandler<Trigger> implements TriggerHandler { public class SimpleTriggerHandlerDelegate extends BaseTriggerModuleHandler {
private final org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleTriggerHandler triggerHandler; private final org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleTriggerHandler triggerHandler;
public SimpleTriggerHandlerDelegate(Trigger module, public SimpleTriggerHandlerDelegate(Trigger module,

View File

@ -21,6 +21,8 @@ import java.util.UUID;
import javax.script.ScriptContext; import javax.script.ScriptContext;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.config.core.Configuration;
import org.openhab.core.automation.Module; import org.openhab.core.automation.Module;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseModuleHandler;
import org.openhab.core.automation.module.script.ScriptEngineContainer; import org.openhab.core.automation.module.script.ScriptEngineContainer;
@ -36,7 +38,9 @@ import org.slf4j.LoggerFactory;
* *
* @param <T> the type of module the concrete handler can handle * @param <T> the type of module the concrete handler can handle
*/ */
@NonNullByDefault
public abstract class AbstractScriptModuleHandler<T extends Module> extends BaseModuleHandler<T> { public abstract class AbstractScriptModuleHandler<T extends Module> extends BaseModuleHandler<T> {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
/** Constant defining the configuration parameter of modules that specifies the mime type of a script */ /** Constant defining the configuration parameter of modules that specifies the mime type of a script */
@ -45,13 +49,13 @@ public abstract class AbstractScriptModuleHandler<T extends Module> extends Base
/** Constant defining the configuration parameter of modules that specifies the script itself */ /** Constant defining the configuration parameter of modules that specifies the script itself */
protected static final String SCRIPT = "script"; protected static final String SCRIPT = "script";
protected ScriptEngineManager scriptEngineManager; protected final ScriptEngineManager scriptEngineManager;
private final String engineIdentifier; private final String engineIdentifier;
private Optional<ScriptEngine> scriptEngine = Optional.empty(); private Optional<ScriptEngine> scriptEngine = Optional.empty();
private String type; private final String type;
protected String script; protected final String script;
private final String ruleUID; private final String ruleUID;
@ -59,16 +63,25 @@ public abstract class AbstractScriptModuleHandler<T extends Module> extends Base
super(module); super(module);
this.scriptEngineManager = scriptEngineManager; this.scriptEngineManager = scriptEngineManager;
this.ruleUID = ruleUID; this.ruleUID = ruleUID;
engineIdentifier = UUID.randomUUID().toString(); this.engineIdentifier = UUID.randomUUID().toString();
loadConfig(); this.type = getValidConfigParameter(SCRIPT_TYPE, module.getConfiguration(), module.getId());
this.script = getValidConfigParameter(SCRIPT, module.getConfiguration(), module.getId());
}
private static String getValidConfigParameter(String parameter, Configuration config, String moduleId) {
Object value = config.get(parameter);
if (value != null && value instanceof String && !((String) value).trim().isEmpty()) {
return (String) value;
} else {
throw new IllegalStateException(String.format(
"Config parameter '%s' is missing in the configuration of module '%s'.", parameter, moduleId));
}
} }
@Override @Override
public void dispose() { public void dispose() {
if (scriptEngine != null) { scriptEngineManager.removeEngine(engineIdentifier);
scriptEngineManager.removeEngine(engineIdentifier);
}
} }
protected Optional<ScriptEngine> getScriptEngine() { protected Optional<ScriptEngine> getScriptEngine() {
@ -87,23 +100,6 @@ public abstract class AbstractScriptModuleHandler<T extends Module> extends Base
} }
} }
private void loadConfig() {
Object type = module.getConfiguration().get(SCRIPT_TYPE);
Object script = module.getConfiguration().get(SCRIPT);
if (!isValid(type)) {
throw new IllegalStateException(String.format("Type is missing in the configuration of module '%s'.", module.getId()));
} else if (!isValid(script)) {
throw new IllegalStateException(String.format("Script is missing in the configuration of module '%s'.", module.getId()));
} else {
this.type = (String) type;
this.script = (String) script;
}
}
private boolean isValid(Object parameter) {
return parameter != null && parameter instanceof String && !((String) parameter).trim().isEmpty();
}
/** /**
* Adds the passed context variables of the rule engine to the context scope of the ScriptEngine, this should be * Adds the passed context variables of the rule engine to the context scope of the ScriptEngine, this should be
* updated each time the module is executed * updated each time the module is executed

View File

@ -17,6 +17,8 @@ import java.util.Map;
import javax.script.ScriptException; import javax.script.ScriptException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.ActionHandler;
import org.openhab.core.automation.module.script.ScriptEngineManager; import org.openhab.core.automation.module.script.ScriptEngineManager;
@ -28,8 +30,8 @@ import org.slf4j.LoggerFactory;
* *
* @author Kai Kreuzer - Initial contribution * @author Kai Kreuzer - Initial contribution
* @author Simon Merschjohann * @author Simon Merschjohann
*
*/ */
@NonNullByDefault
public class ScriptActionHandler extends AbstractScriptModuleHandler<Action> implements ActionHandler { public class ScriptActionHandler extends AbstractScriptModuleHandler<Action> implements ActionHandler {
public static final String TYPE_ID = "script.ScriptAction"; public static final String TYPE_ID = "script.ScriptAction";
@ -51,8 +53,8 @@ public class ScriptActionHandler extends AbstractScriptModuleHandler<Action> imp
} }
@Override @Override
public Map<String, Object> execute(final Map<String, Object> context) { public @Nullable Map<String, Object> execute(final Map<String, Object> context) {
HashMap<String, Object> resultMap = new HashMap<String, Object>(); HashMap<String, Object> resultMap = new HashMap<>();
getScriptEngine().ifPresent(scriptEngine -> { getScriptEngine().ifPresent(scriptEngine -> {
setExecutionContext(scriptEngine, context); setExecutionContext(scriptEngine, context);

View File

@ -18,6 +18,7 @@ import java.util.Optional;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptException; import javax.script.ScriptException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.ConditionHandler; import org.openhab.core.automation.handler.ConditionHandler;
import org.openhab.core.automation.module.script.ScriptEngineManager; import org.openhab.core.automation.module.script.ScriptEngineManager;
@ -29,8 +30,8 @@ import org.slf4j.LoggerFactory;
* *
* @author Kai Kreuzer - Initial contribution * @author Kai Kreuzer - Initial contribution
* @author Simon Merschjohann * @author Simon Merschjohann
*
*/ */
@NonNullByDefault
public class ScriptConditionHandler extends AbstractScriptModuleHandler<Condition> implements ConditionHandler { public class ScriptConditionHandler extends AbstractScriptModuleHandler<Condition> implements ConditionHandler {
public static final String TYPE_ID = "script.ScriptCondition"; public static final String TYPE_ID = "script.ScriptCondition";
@ -63,5 +64,4 @@ public class ScriptConditionHandler extends AbstractScriptModuleHandler<Conditio
return result; return result;
} }
} }

View File

@ -12,6 +12,7 @@
*/ */
package org.openhab.core.automation; package org.openhab.core.automation;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.config.core.ConfigDescriptionParameter; import org.eclipse.smarthome.config.core.ConfigDescriptionParameter;
import org.openhab.core.automation.type.Input; import org.openhab.core.automation.type.Input;
import org.openhab.core.automation.type.Output; import org.openhab.core.automation.type.Output;
@ -34,8 +35,9 @@ import org.openhab.core.automation.type.TriggerType;
* Trigger modules are placed in <b>triggers</b> section of the {@link Rule} definition. * Trigger modules are placed in <b>triggers</b> section of the {@link Rule} definition.
* *
* @see Module * @see Module
* @author Yordan Mihaylov - Initial Contribution * @author Yordan Mihaylov - Initial contribution
*/ */
@NonNullByDefault
public interface Trigger extends Module { public interface Trigger extends Module {
} }

View File

@ -24,9 +24,10 @@ import org.openhab.core.automation.Trigger;
* This interface should be implemented by external modules which provide functionality for processing {@link Action} * This interface should be implemented by external modules which provide functionality for processing {@link Action}
* modules. This functionality is called to execute the {@link Action}s of the {@link Rule} when it is needed. * modules. This functionality is called to execute the {@link Action}s of the {@link Rule} when it is needed.
* *
* @author Yordan Mihaylov - Initial Contribution * @author Yordan Mihaylov - Initial contribution
* @author Ana Dimova - Initial Contribution * @author Ana Dimova - Initial contribution
* @author Vasil Ilchev - Initial Contribution * @author Vasil Ilchev - Initial ontribution
* @see ModuleHandler
*/ */
@NonNullByDefault @NonNullByDefault
public interface ActionHandler extends ModuleHandler { public interface ActionHandler extends ModuleHandler {
@ -35,7 +36,7 @@ public interface ActionHandler extends ModuleHandler {
* Called to execute an {@link Action} of the {@link Rule} when it is needed. * Called to execute an {@link Action} of the {@link Rule} when it is needed.
* *
* @param context an unmodifiable map containing the outputs of the {@link Trigger} that triggered the {@link Rule}, * @param context an unmodifiable map containing the outputs of the {@link Trigger} that triggered the {@link Rule},
* the outputs of all preceding {@link Action}s, and the inputs for this {@link Action}. * the outputs of all preceding {@link Action}s, and the inputs for this {@link Action}.
* *
* @return a map with the {@code outputs} which are the result of the {@link Action}'s execution (may be null). * @return a map with the {@code outputs} which are the result of the {@link Action}'s execution (may be null).
*/ */

View File

@ -0,0 +1,30 @@
/**
* 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.automation.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.Action;
/**
* This is a base class that can be used by ActionModuleHandler implementations
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public abstract class BaseActionModuleHandler extends BaseModuleHandler<Action> implements ActionHandler {
public BaseActionModuleHandler(Action module) {
super(module);
}
}

View File

@ -0,0 +1,30 @@
/**
* 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.automation.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.Condition;
/**
* This is a base class that can be used by ConditionModuleHandler implementations
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public abstract class BaseConditionModuleHandler extends BaseModuleHandler<Condition> implements ConditionHandler {
public BaseConditionModuleHandler(Condition module) {
super(module);
}
}

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.core.automation.handler; package org.openhab.core.automation.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Module; import org.openhab.core.automation.Module;
import org.openhab.core.automation.ModuleHandlerCallback; import org.openhab.core.automation.ModuleHandlerCallback;
@ -20,10 +22,11 @@ import org.openhab.core.automation.ModuleHandlerCallback;
* *
* @author Kai Kreuzer - Initial Contribution * @author Kai Kreuzer - Initial Contribution
*/ */
@NonNullByDefault
public class BaseModuleHandler<T extends Module> implements ModuleHandler { public class BaseModuleHandler<T extends Module> implements ModuleHandler {
protected T module; protected T module;
protected ModuleHandlerCallback callback; protected @Nullable ModuleHandlerCallback callback;
public BaseModuleHandler(T module) { public BaseModuleHandler(T module) {
this.module = module; this.module = module;

View File

@ -12,6 +12,7 @@
*/ */
package org.openhab.core.automation.handler; package org.openhab.core.automation.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.Trigger; import org.openhab.core.automation.Trigger;
/** /**
@ -19,6 +20,7 @@ import org.openhab.core.automation.Trigger;
* *
* @author Vasil Ilchev - Initial contribution * @author Vasil Ilchev - Initial contribution
*/ */
@NonNullByDefault
public class BaseTriggerModuleHandler extends BaseModuleHandler<Trigger> implements TriggerHandler { public class BaseTriggerModuleHandler extends BaseModuleHandler<Trigger> implements TriggerHandler {
public BaseTriggerModuleHandler(Trigger module) { public BaseTriggerModuleHandler(Trigger module) {

View File

@ -14,6 +14,7 @@ package org.openhab.core.automation.handler;
import java.util.Map; import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.Rule; import org.openhab.core.automation.Rule;
import org.openhab.core.automation.Trigger; import org.openhab.core.automation.Trigger;
@ -21,18 +22,19 @@ import org.openhab.core.automation.Trigger;
/** /**
* This interface provides common functionality for processing {@link Condition} modules. * This interface provides common functionality for processing {@link Condition} modules.
* *
* @author Yordan Mihaylov - Initial contribution
* @author Ana Dimova - Initial contribution
* @author Vasil Ilchev - Initial contribution
* @see ModuleHandler * @see ModuleHandler
* @author Yordan Mihaylov - Initial Contribution
* @author Ana Dimova - Initial Contribution
* @author Vasil Ilchev - Initial Contribution
*/ */
@NonNullByDefault
public interface ConditionHandler extends ModuleHandler { public interface ConditionHandler extends ModuleHandler {
/** /**
* Checks if the Condition is satisfied in the given {@code context}. * Checks if the Condition is satisfied in the given {@code context}.
* *
* @param context an unmodifiable map containing the outputs of the {@link Trigger} that triggered the {@link Rule} * @param context an unmodifiable map containing the outputs of the {@link Trigger} that triggered the {@link Rule}
* and the inputs of the {@link Condition}. * and the inputs of the {@link Condition}.
* @return {@code true} if {@link Condition} is satisfied, {@code false} otherwise. * @return {@code true} if {@link Condition} is satisfied, {@code false} otherwise.
*/ */
public boolean isSatisfied(Map<String, Object> context); public boolean isSatisfied(Map<String, Object> context);

View File

@ -19,7 +19,7 @@ import org.openhab.core.automation.ModuleHandlerCallback;
* A common interface for all module Handler interfaces. The Handler interfaces are * A common interface for all module Handler interfaces. The Handler interfaces are
* bridge between RuleManager and external modules used by the RuleManager. * bridge between RuleManager and external modules used by the RuleManager.
* *
* @author Yordan Mihaylov - Initial Contribution * @author Yordan Mihaylov - Initial contribution
* @see ModuleHandlerFactory * @see ModuleHandlerFactory
*/ */
@NonNullByDefault @NonNullByDefault

View File

@ -12,14 +12,19 @@
*/ */
package org.openhab.core.automation.handler; package org.openhab.core.automation.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* This Handler interface is used by the RuleManager to set a callback interface to * This Handler interface is used by the RuleManager to set a callback interface to
* itself. The callback has to implemented {@link TriggerHandlerCallback} interface * itself. The callback has to implemented {@link TriggerHandlerCallback} interface
* and it is used to notify the RuleManager when {@link TriggerHandler} was triggered * and it is used to notify the RuleManager when {@link TriggerHandler} was triggered
* *
* @author Yordan Mihaylov - Initial Contribution * @author Yordan Mihaylov - Initial contribution
* @author Ana Dimova - Initial Contribution * @author Ana Dimova - Initial contribution
* @author Vasil Ilchev - Initial Contribution * @author Vasil Ilchev - Initial contribution
* @see ModuleHandler
*/ */
@NonNullByDefault
public interface TriggerHandler extends ModuleHandler { public interface TriggerHandler extends ModuleHandler {
} }

View File

@ -23,8 +23,7 @@ import java.util.Map.Entry;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.openhab.core.automation.type.ActionType; import org.openhab.core.automation.type.ActionType;
import org.openhab.core.automation.type.Input; import org.openhab.core.automation.type.Input;
import org.openhab.core.automation.type.Output; import org.openhab.core.automation.type.Output;
@ -34,10 +33,9 @@ import org.slf4j.LoggerFactory;
/** /**
* ActionHandler which is dynamically created upon annotation on services * ActionHandler which is dynamically created upon annotation on services
* *
* @author Stefan Triller - initial contribution * @author Stefan Triller - Initial contribution
*
*/ */
public class AnnotationActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class AnnotationActionHandler extends BaseActionModuleHandler {
private static final String MODULE_RESULT = "result"; private static final String MODULE_RESULT = "result";

View File

@ -21,8 +21,7 @@ import java.util.Map;
import org.eclipse.smarthome.core.types.State; import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.TypeParser; import org.eclipse.smarthome.core.types.TypeParser;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.openhab.core.automation.internal.module.exception.UncomparableException; import org.openhab.core.automation.internal.module.exception.UncomparableException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,7 +32,7 @@ import org.slf4j.LoggerFactory;
* @author Benedikt Niehues - Initial contribution and API * @author Benedikt Niehues - Initial contribution and API
* *
*/ */
public class CompareConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler { public class CompareConditionHandler extends BaseConditionModuleHandler {
public final Logger logger = LoggerFactory.getLogger(CompareConditionHandler.class); public final Logger logger = LoggerFactory.getLogger(CompareConditionHandler.class);
@ -56,7 +55,8 @@ public class CompareConditionHandler extends BaseModuleHandler<Condition> implem
String rightOperandString = (rightObj != null && rightObj instanceof String) ? (String) rightObj : null; String rightOperandString = (rightObj != null && rightObj instanceof String) ? (String) rightObj : null;
Object leftObjFieldNameObj = this.module.getConfiguration().get(INPUT_LEFT_FIELD); Object leftObjFieldNameObj = this.module.getConfiguration().get(INPUT_LEFT_FIELD);
String leftObjectFieldName = (leftObjFieldNameObj != null && leftObjFieldNameObj instanceof String) String leftObjectFieldName = (leftObjFieldNameObj != null && leftObjFieldNameObj instanceof String)
? (String) leftObjFieldNameObj : null; ? (String) leftObjFieldNameObj
: null;
if (rightOperandString == null || operator == null) { if (rightOperandString == null || operator == null) {
return false; return false;
} else { } else {

View File

@ -18,18 +18,16 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* This is a ConditionHandler implementation, which checks the current day of the week against a specified list. * This is a ConditionHandler implementation, which checks the current day of the week against a specified list.
* *
* @author Kai Kreuzer - Initial Contribution * @author Kai Kreuzer - Initial contribution
*
*/ */
public class DayOfWeekConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler { public class DayOfWeekConditionHandler extends BaseConditionModuleHandler {
private final Logger logger = LoggerFactory.getLogger(DayOfWeekConditionHandler.class); private final Logger logger = LoggerFactory.getLogger(DayOfWeekConditionHandler.class);

View File

@ -16,19 +16,18 @@ import java.util.Map;
import org.eclipse.smarthome.core.events.Event; import org.eclipse.smarthome.core.events.Event;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* This is the implementation of a event condition which checks if inputs matches configured values. * This is the implementation of a event condition which checks if inputs matches configured values.
* *
* @author Benedikt Niehues - Initial contribution and API * @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - refactored and simplified customized module handling * @author Kai Kreuzer - refactored and simplified customized module handling
*
*/ */
public class GenericEventConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler { public class GenericEventConditionHandler extends BaseConditionModuleHandler {
public final Logger logger = LoggerFactory.getLogger(GenericEventConditionHandler.class); public final Logger logger = LoggerFactory.getLogger(GenericEventConditionHandler.class);
public static final String MODULETYPE_ID = "core.GenericEventCondition"; public static final String MODULETYPE_ID = "core.GenericEventCondition";

View File

@ -23,20 +23,18 @@ import org.eclipse.smarthome.core.items.events.ItemEventFactory;
import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.TypeParser; import org.eclipse.smarthome.core.types.TypeParser;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* This is an implementation of an ActionHandler. It sends commands for items. * This is an implementation of an ActionHandler. It sends commands for items.
* *
* @author Benedikt Niehues - Initial contribution and API * @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - refactored and simplified customized module handling * @author Kai Kreuzer - refactored and simplified customized module handling
* @author Stefan Triller - use command from input first and if not set, use command from configuration * @author Stefan Triller - use command from input first and if not set, use command from configuration
*
*/ */
public class ItemCommandActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class ItemCommandActionHandler extends BaseActionModuleHandler {
private final Logger logger = LoggerFactory.getLogger(ItemCommandActionHandler.class); private final Logger logger = LoggerFactory.getLogger(ItemCommandActionHandler.class);

View File

@ -21,19 +21,17 @@ import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.types.State; import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.TypeParser; import org.eclipse.smarthome.core.types.TypeParser;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* ConditionHandler implementation to check item state * ConditionHandler implementation to check item state
* *
* @author Benedikt Niehues - Initial contribution and API * @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - refactored and simplified customized module handling * @author Kai Kreuzer - refactored and simplified customized module handling
*
*/ */
public class ItemStateConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler { public class ItemStateConditionHandler extends BaseConditionModuleHandler {
private final Logger logger = LoggerFactory.getLogger(ItemStateConditionHandler.class); private final Logger logger = LoggerFactory.getLogger(ItemStateConditionHandler.class);

View File

@ -18,8 +18,7 @@ import java.util.Map;
import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.config.core.Configuration;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.RuleRegistry; import org.openhab.core.automation.RuleRegistry;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,11 +38,10 @@ import org.slf4j.LoggerFactory;
* } * }
* </pre> * </pre>
* *
* @author Plamen Peev - Initial contribution and API * @author Plamen Peev - Initial contribution
* @author Kai Kreuzer - use rule engine instead of registry * @author Kai Kreuzer - use rule engine instead of registry
*
*/ */
public class RuleEnablementActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class RuleEnablementActionHandler extends BaseActionModuleHandler {
/** /**
* This filed contains the type of this handler so it can be recognized from the factory. * This filed contains the type of this handler so it can be recognized from the factory.

View File

@ -17,8 +17,7 @@ import java.util.Map;
import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.config.core.Configuration;
import org.openhab.core.automation.Action; import org.openhab.core.automation.Action;
import org.openhab.core.automation.handler.ActionHandler; import org.openhab.core.automation.handler.BaseActionModuleHandler;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,9 +38,8 @@ import org.slf4j.LoggerFactory;
* *
* @author Benedikt Niehues - Initial contribution * @author Benedikt Niehues - Initial contribution
* @author Kai Kreuzer - use rule engine instead of registry * @author Kai Kreuzer - use rule engine instead of registry
*
*/ */
public class RunRuleActionHandler extends BaseModuleHandler<Action> implements ActionHandler { public class RunRuleActionHandler extends BaseActionModuleHandler {
/** /**
* The UID for this handler for identification in the factory. * The UID for this handler for identification in the factory.

View File

@ -18,18 +18,16 @@ import java.util.Map;
import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.config.core.Configuration;
import org.openhab.core.automation.Condition; import org.openhab.core.automation.Condition;
import org.openhab.core.automation.handler.BaseModuleHandler; import org.openhab.core.automation.handler.BaseConditionModuleHandler;
import org.openhab.core.automation.handler.ConditionHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* ConditionHandler implementation for time based conditions. * ConditionHandler implementation for time based conditions.
* *
* @author Dominik Schlierf - initial contribution * @author Dominik Schlierf - Initial contribution
*
*/ */
public class TimeOfDayConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler { public class TimeOfDayConditionHandler extends BaseConditionModuleHandler {
private final Logger logger = LoggerFactory.getLogger(TimeOfDayConditionHandler.class); private final Logger logger = LoggerFactory.getLogger(TimeOfDayConditionHandler.class);

View File

@ -12,19 +12,24 @@
*/ */
package org.eclipse.smarthome.core.events; package org.eclipse.smarthome.core.events;
import org.eclipse.jdt.annotation.NonNullByDefault;
/** /**
* An {@link EventFilter} can be provided by an {@link EventSubscriber} in order * An {@link EventFilter} can be provided by an {@link EventSubscriber} in order
* to receive specific {@link Event}s by an {@link EventPublisher} if the filter applies. * to receive specific {@link Event}s by an {@link EventPublisher} if the filter applies.
* *
* @author Stefan Bußweiler - Initial contribution * @author Stefan Bußweiler - Initial contribution
*/ */
@NonNullByDefault
public interface EventFilter { public interface EventFilter {
/** /**
* Apply the filter on an event. <p> This method is called for each subscribed {@link Event} of an * Apply the filter on an event.
* <p>
* This method is called for each subscribed {@link Event} of an
* {@link EventSubscriber}. If the filter applies, the event will be dispatched to the * {@link EventSubscriber}. If the filter applies, the event will be dispatched to the
* {@link EventSubscriber#receive(Event)} method. * {@link EventSubscriber#receive(Event)} method.
* *
* @param event the event (not null) * @param event the event (not null)
* @return true if the filter criterion applies * @return true if the filter criterion applies
*/ */