Search in sources :

Example 1 with ConverterValueMap

use of org.eclipse.smarthome.config.xml.util.ConverterValueMap in project smarthome by eclipse.

the class ConfigDescriptionParameterConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    ConfigDescriptionParameter configDescriptionParam = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String name = attributes.get("name");
    Type type = toType(attributes.get("type"));
    BigDecimal min = toNumber(attributes.get("min"));
    BigDecimal max = toNumber(attributes.get("max"));
    BigDecimal step = toNumber(attributes.get("step"));
    String patternString = attributes.get("pattern");
    Boolean required = toBoolean(attributes.get("required"));
    Boolean readOnly = falseIfNull(toBoolean(attributes.get("readOnly")));
    Boolean multiple = falseIfNull(toBoolean(attributes.get("multiple")));
    String groupName = attributes.get("groupName");
    String unit = attributes.get("unit");
    // read values
    ConverterValueMap valueMap = new ConverterValueMap(reader, context);
    String parameterContext = valueMap.getString("context");
    if (required == null) {
        // fallback to deprecated "required" element
        required = valueMap.getBoolean("required", false);
    }
    String defaultValue = valueMap.getString("default");
    String label = valueMap.getString("label");
    String description = valueMap.getString("description");
    Boolean advanced = valueMap.getBoolean("advanced", false);
    Boolean verify = valueMap.getBoolean("verify", false);
    Boolean limitToOptions = valueMap.getBoolean("limitToOptions", true);
    Integer multipleLimit = valueMap.getInteger("multipleLimit");
    String unitLabel = null;
    if (unit == null) {
        unitLabel = valueMap.getString("unitLabel");
    }
    // read options and filter criteria
    List<ParameterOption> options = readParameterOptions(valueMap.getObject("options"));
    @SuppressWarnings("unchecked") List<FilterCriteria> filterCriteria = (List<FilterCriteria>) valueMap.getObject("filter");
    // create object
    configDescriptionParam = ConfigDescriptionParameterBuilder.create(name, type).withMinimum(min).withMaximum(max).withStepSize(step).withPattern(patternString).withRequired(required).withReadOnly(readOnly).withMultiple(multiple).withContext(parameterContext).withDefault(defaultValue).withLabel(label).withDescription(description).withOptions(options).withFilterCriteria(filterCriteria).withGroupName(groupName).withAdvanced(advanced).withVerify(verify).withLimitToOptions(limitToOptions).withMultipleLimit(multipleLimit).withUnit(unit).withUnitLabel(unitLabel).build();
    return configDescriptionParam;
}
Also used : FilterCriteria(org.eclipse.smarthome.config.core.FilterCriteria) BigDecimal(java.math.BigDecimal) ConverterValueMap(org.eclipse.smarthome.config.xml.util.ConverterValueMap) Type(org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) List(java.util.List) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 2 with ConverterValueMap

use of org.eclipse.smarthome.config.xml.util.ConverterValueMap in project smarthome by eclipse.

the class ConfigDescriptionParameterGroupConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext marshallingContext) {
    String name = reader.getAttribute("name");
    // Read values
    ConverterValueMap valueMap = new ConverterValueMap(reader, marshallingContext);
    String context = valueMap.getString("context");
    String description = valueMap.getString("description");
    String label = valueMap.getString("label");
    Boolean advanced = valueMap.getBoolean("advanced", false);
    return new ConfigDescriptionParameterGroup(name, context, advanced, label, description);
}
Also used : ConfigDescriptionParameterGroup(org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup) ConverterValueMap(org.eclipse.smarthome.config.xml.util.ConverterValueMap)

Aggregations

ConverterValueMap (org.eclipse.smarthome.config.xml.util.ConverterValueMap)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)1 Type (org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type)1 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)1 FilterCriteria (org.eclipse.smarthome.config.core.FilterCriteria)1 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)1