Search in sources :

Example 1 with CompositeConditionType

use of org.eclipse.smarthome.automation.type.CompositeConditionType in project smarthome by eclipse.

the class ModuleTypeRegistryImpl method createCopy.

private ModuleType createCopy(ModuleType mType) {
    if (mType == null) {
        return null;
    }
    ModuleType result;
    if (mType instanceof CompositeTriggerType) {
        CompositeTriggerType m = (CompositeTriggerType) mType;
        result = new CompositeTriggerType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getOutputs(), copyTriggers(m.getChildren()));
    } else if (mType instanceof TriggerType) {
        TriggerType m = (TriggerType) mType;
        result = new TriggerType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getOutputs());
    } else if (mType instanceof CompositeConditionType) {
        CompositeConditionType m = (CompositeConditionType) mType;
        result = new CompositeConditionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), copyConditions(m.getChildren()));
    } else if (mType instanceof ConditionType) {
        ConditionType m = (ConditionType) mType;
        result = new ConditionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs());
    } else if (mType instanceof CompositeActionType) {
        CompositeActionType m = (CompositeActionType) mType;
        result = new CompositeActionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), m.getOutputs(), copyActions(m.getChildren()));
    } else if (mType instanceof ActionType) {
        ActionType m = (ActionType) mType;
        result = new ActionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), m.getOutputs());
    } else {
        throw new IllegalArgumentException("Invalid template type:" + mType);
    }
    return result;
}
Also used : CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) TriggerType(org.eclipse.smarthome.automation.type.TriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ActionType(org.eclipse.smarthome.automation.type.ActionType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType)

Example 2 with CompositeConditionType

use of org.eclipse.smarthome.automation.type.CompositeConditionType in project smarthome by eclipse.

the class ModuleTypeResourceBundleProvider method createLocalizedConditionType.

/**
 * Utility method for localization of ConditionTypes.
 *
 * @param ct is a ConditionType for localization.
 * @param bundle the bundle providing localization resources.
 * @param moduleTypeUID is a ConditionType uid.
 * @param locale represents a specific geographical, political, or cultural region.
 * @param lconfigDescriptions are ConditionType localized config descriptions.
 * @param llabel is a ConditionType localized label.
 * @param ldescription is a ConditionType localized description.
 * @return localized ConditionType.
 */
private ConditionType createLocalizedConditionType(ConditionType ct, Bundle bundle, String moduleTypeUID, Locale locale, List<ConfigDescriptionParameter> lconfigDescriptions, String llabel, String ldescription) {
    List<Input> inputs = ModuleTypeI18nUtil.getLocalizedInputs(i18nProvider, ct.getInputs(), bundle, moduleTypeUID, locale);
    ConditionType lct = null;
    if (ct instanceof CompositeConditionType) {
        List<Condition> modules = ModuleI18nUtil.getLocalizedModules(i18nProvider, ((CompositeConditionType) ct).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
        lct = new CompositeConditionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, ct.getTags(), ct.getVisibility(), inputs, modules);
    } else {
        lct = new ConditionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, ct.getTags(), ct.getVisibility(), inputs);
    }
    return lct;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Input(org.eclipse.smarthome.automation.type.Input) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Example 3 with CompositeConditionType

use of org.eclipse.smarthome.automation.type.CompositeConditionType 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;
}
Also used : Action(org.eclipse.smarthome.automation.Action) TriggerHandler(org.eclipse.smarthome.automation.handler.TriggerHandler) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) LinkedHashMap(java.util.LinkedHashMap) ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Trigger(org.eclipse.smarthome.automation.Trigger) List(java.util.List) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ActionHandler(org.eclipse.smarthome.automation.handler.ActionHandler)

Aggregations

CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)3 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)2 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)2 ConditionType (org.eclipse.smarthome.automation.type.ConditionType)2 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Action (org.eclipse.smarthome.automation.Action)1 Condition (org.eclipse.smarthome.automation.Condition)1 Trigger (org.eclipse.smarthome.automation.Trigger)1 ActionHandler (org.eclipse.smarthome.automation.handler.ActionHandler)1 ModuleHandler (org.eclipse.smarthome.automation.handler.ModuleHandler)1 TriggerHandler (org.eclipse.smarthome.automation.handler.TriggerHandler)1 ActionType (org.eclipse.smarthome.automation.type.ActionType)1 Input (org.eclipse.smarthome.automation.type.Input)1 TriggerType (org.eclipse.smarthome.automation.type.TriggerType)1