Search in sources :

Example 1 with NodeValue

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

the class ChannelXmlResult method toChannelDefinition.

protected ChannelDefinition toChannelDefinition(String bindingId) throws ConversionException {
    String id = getId();
    String typeId = getTypeId();
    String typeUID = getTypeUID(bindingId, typeId);
    // Convert the channel properties into a map
    Map<String, String> propertiesMap = new HashMap<>();
    for (NodeValue property : getProperties()) {
        propertiesMap.put(property.getAttributes().get("name"), (String) property.getValue());
    }
    ChannelDefinition channelDefinition = new ChannelDefinition(id, new ChannelTypeUID(typeUID), propertiesMap, getLabel(), getDescription());
    return channelDefinition;
}
Also used : NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) HashMap(java.util.HashMap) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition)

Example 2 with NodeValue

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

the class ConfigDescriptionParameterConverter method readParameterOptions.

private List<ParameterOption> readParameterOptions(Object rawNodeValueList) {
    if (rawNodeValueList instanceof List<?>) {
        List<?> list = (List<?>) rawNodeValueList;
        List<ParameterOption> result = new ArrayList<>();
        for (Object object : list) {
            if (object instanceof NodeValue) {
                NodeValue nodeValue = (NodeValue) object;
                String value = nodeValue.getAttributes().get("value");
                String label = nodeValue.getValue().toString();
                result.add(new ParameterOption(value, label));
            }
        }
        return result;
    }
    return null;
}
Also used : NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with NodeValue

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

the class ChannelTypeConverter method readTags.

private Set<String> readTags(NodeIterator nodeIterator) throws ConversionException {
    Set<String> tags = null;
    List<?> tagsNode = nodeIterator.nextList("tags", false);
    if (tagsNode != null) {
        tags = new HashSet<>(tagsNode.size());
        for (Object tagNodeObject : tagsNode) {
            NodeValue tagNode = (NodeValue) tagNodeObject;
            if ("tag".equals(tagNode.getNodeName())) {
                String tag = (String) tagNode.getValue();
                if (tag != null) {
                    tags.add(tag);
                }
            } else {
                throw new ConversionException("The 'tags' node must only contain 'tag' nodes!");
            }
        }
    }
    return tags;
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue)

Aggregations

NodeValue (org.eclipse.smarthome.config.xml.util.NodeValue)3 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)1 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1