use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.
the class RuleEngine method setModuleHandlers.
/**
* This method links modules to corresponding module handlers.
*
* @param rUID id of rule containing these modules
* @param modules list of modules
* @return null when all modules are connected or list of RuleErrors for missing handlers.
*/
private <T extends Module> String setModuleHandlers(String rUID, List<T> modules) {
StringBuffer sb = null;
if (modules != null) {
for (T m : modules) {
try {
ModuleHandler moduleHandler = getModuleHandler(m, rUID);
if (moduleHandler != null) {
if (m instanceof RuntimeAction) {
((RuntimeAction) m).setModuleHandler((ActionHandler) moduleHandler);
} else if (m instanceof RuntimeCondition) {
((RuntimeCondition) m).setModuleHandler((ConditionHandler) moduleHandler);
} else if (m instanceof RuntimeTrigger) {
((RuntimeTrigger) m).setModuleHandler((TriggerHandler) moduleHandler);
}
} else {
if (sb == null) {
sb = new StringBuffer();
}
String message = "Missing handler '" + m.getTypeUID() + "' for module '" + m.getId() + "'";
sb.append(message).append("\n");
logger.trace(message);
}
} catch (Throwable t) {
if (sb == null) {
sb = new StringBuffer();
}
String message = "Getting handler '" + m.getTypeUID() + "' for module '" + m.getId() + "' failed: " + t.getMessage();
sb.append(message).append("\n");
logger.trace(message);
}
}
}
return sb != null ? sb.toString() : null;
}
use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.
the class AbstractCompositeModuleHandler method dispose.
@Override
public void dispose() {
List<M> children = getChildren();
for (M child : children) {
ModuleHandler childHandler = moduleHandlerMap.remove(child);
if (childHandler != null) {
childHandler.dispose();
}
}
moduleHandlerMap = null;
}
use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.
the class ScriptedPrivateModuleHandlerFactory method internalCreate.
@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler moduleHandler = null;
ScriptedHandler scriptedHandler = null;
try {
scriptedHandler = privateTypes.get(module.getConfiguration().get(PRIV_ID));
} catch (Exception e) {
logger.warn("ScriptedHandler {} for ruleUID {} not found", module.getConfiguration().get(PRIV_ID), ruleUID);
}
if (scriptedHandler != null) {
moduleHandler = getModuleHandler(module, scriptedHandler);
}
return moduleHandler;
}
use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.
the class SampleHandlerFactory method internalCreate.
@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler moduleHandler = null;
if (SUPPORTED_TRIGGER.equals(module.getTypeUID())) {
moduleHandler = new SampleTriggerHandler((Trigger) module, ruleUID);
createdTriggerHandler.add((TriggerHandler) moduleHandler);
} else if (SUPPORTED_CONDITION.equals(module.getTypeUID())) {
moduleHandler = new SampleConditionHandler((Condition) module);
} else if (SUPPORTED_ACTION.equals(module.getTypeUID())) {
moduleHandler = new SampleActionHandler((Action) module);
} else {
logger.error(MODULE_HANDLER_FACTORY_NAME + "Not supported moduleHandler: {}", module.getTypeUID());
}
return moduleHandler;
}
use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.
the class CompositeModuleHandlerFactory method internalCreate.
@Override
public ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler handler = null;
if (module != null) {
String moduleType = module.getTypeUID();
ModuleType mt = mtRegistry.get(moduleType);
if (mt instanceof CompositeTriggerType) {
List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
LinkedHashMap<Trigger, TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeConditionType) {
List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
LinkedHashMap<Condition, ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeActionType) {
List<Action> childModules = ((CompositeActionType) mt).getChildren();
LinkedHashMap<Action, ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler, ruleUID);
}
}
if (handler != null) {
logger.debug("Set module handler: {} -> {} of rule {}.", module.getId(), handler.getClass().getSimpleName() + "(" + moduleType + ")", ruleUID);
} else {
logger.debug("Not found module handler {} for moduleType {} of rule {}.", module.getId(), moduleType, ruleUID);
}
}
return handler;
}
Aggregations