use of org.openhab.core.automation.internal.ruleengine.WrappedModule in project openhab-core by openhab.
the class RuleEngineImpl 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.
*/
@Nullable
private <T extends WrappedModule<?, ?>> String setModuleHandlers(String rUID, List<T> modules) {
StringBuilder sb = null;
for (T mm : modules) {
final Module m = mm.unwrap();
try {
ModuleHandler moduleHandler = getModuleHandler(m, rUID);
if (moduleHandler != null) {
if (mm instanceof WrappedAction) {
((WrappedAction) mm).setModuleHandler((ActionHandler) moduleHandler);
} else if (mm instanceof WrappedCondition) {
((WrappedCondition) mm).setModuleHandler((ConditionHandler) moduleHandler);
} else if (mm instanceof WrappedTrigger) {
((WrappedTrigger) mm).setModuleHandler((TriggerHandler) moduleHandler);
}
} else {
if (sb == null) {
sb = new StringBuilder();
}
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 StringBuilder();
}
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.openhab.core.automation.internal.ruleengine.WrappedModule in project openhab-core by openhab.
the class RuleEngineImpl method validateModuleIDs.
/**
* Validates IDs of modules. The module ids must be alphanumeric with only underscores and dashes.
*
* @param rule the rule to validate
* @throws IllegalArgumentException when a module id contains illegal characters
*/
private void validateModuleIDs(WrappedRule rule) {
for (final WrappedModule<?, ?> mm : rule.getModules()) {
final Module m = mm.unwrap();
String mId = m.getId();
if (!mId.matches("[A-Za-z0-9_-]*")) {
rule.setStatusInfo(new RuleStatusInfo(RuleStatus.UNINITIALIZED, RuleStatusDetail.INVALID_RULE, "It is null or not fit to the pattern: [A-Za-z0-9_-]*"));
throw new IllegalArgumentException("Invalid module uid: " + mId + ". It is null or not fit to the pattern: [A-Za-z0-9_-]*");
}
}
}
use of org.openhab.core.automation.internal.ruleengine.WrappedModule in project openhab-core by openhab.
the class RuleEngineImpl method removeModuleHandlers.
/**
* Unlink module handlers from their modules. The method is called when the rule containing these modules goes into
* {@link RuleStatus#UNINITIALIZED} state.
*
* @param modules list of modules which should be disconnected.
*/
private <T extends WrappedModule<?, ?>> void removeModuleHandlers(List<T> modules, String ruleUID) {
for (T mm : modules) {
final Module m = mm.unwrap();
ModuleHandler handler = mm.getModuleHandler();
if (handler != null) {
ModuleHandlerFactory factory = getModuleHandlerFactory(m.getTypeUID());
if (factory != null) {
factory.ungetHandler(m, ruleUID, handler);
}
mm.setModuleHandler(null);
}
}
}
Aggregations