Search in sources :

Example 1 with NodeIterator

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

the class BindingInfoConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    BindingInfoXmlResult bindingInfoXmlResult = null;
    BindingInfo bindingInfo = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String id = attributes.get("id");
    // set automatically extracted URI for a possible 'config-description' section
    context.put("config-description.uri", "binding:" + id);
    // read values
    List<?> nodes = (List<?>) context.convertAnother(context, List.class);
    NodeIterator nodeIterator = new NodeIterator(nodes);
    String name = (String) nodeIterator.nextValue("name", true);
    String description = (String) nodeIterator.nextValue("description", false);
    String author = (String) nodeIterator.nextValue("author", false);
    String serviceId = (String) nodeIterator.nextValue("service-id", false);
    URI configDescriptionURI = readConfigDescriptionURI(nodeIterator);
    ConfigDescription configDescription = null;
    if (configDescriptionURI == null) {
        configDescription = readConfigDescription(nodeIterator);
        if (configDescription != null) {
            configDescriptionURI = configDescription.getUID();
        }
    }
    nodeIterator.assertEndOfType();
    // create object
    bindingInfo = new BindingInfo(id, name, description, author, serviceId, configDescriptionURI);
    bindingInfoXmlResult = new BindingInfoXmlResult(bindingInfo, configDescription);
    return bindingInfoXmlResult;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) List(java.util.List) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URI(java.net.URI)

Example 2 with NodeIterator

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

the class ConfigDescriptionConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    ConfigDescription configDescription = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String uriText = attributes.get("uri");
    if (uriText == null) {
        // the URI could be overridden by a context field if it could be
        // automatically extracted
        uriText = (String) context.get("config-description.uri");
    }
    URI uri = null;
    try {
        uri = new URI(uriText);
    } catch (NullPointerException | URISyntaxException ex) {
        throw new ConversionException("The URI '" + uriText + "' in node '" + reader.getNodeName() + "' is invalid!", ex);
    }
    // create the lists to hold parameters and groups
    List<ConfigDescriptionParameter> configDescriptionParams = new ArrayList<ConfigDescriptionParameter>();
    List<ConfigDescriptionParameterGroup> configDescriptionGroups = new ArrayList<ConfigDescriptionParameterGroup>();
    // read values
    List<?> nodes = (List<?>) context.convertAnother(context, List.class);
    NodeIterator nodeIterator = new NodeIterator(nodes);
    // respective arrays
    while (nodeIterator.hasNext() == true) {
        Object node = nodeIterator.next();
        if (node instanceof ConfigDescriptionParameter) {
            configDescriptionParams.add((ConfigDescriptionParameter) node);
        }
        if (node instanceof ConfigDescriptionParameterGroup) {
            configDescriptionGroups.add((ConfigDescriptionParameterGroup) node);
        }
    }
    ConverterAssertion.assertEndOfType(reader);
    // create object
    configDescription = new ConfigDescription(uri, configDescriptionParams, configDescriptionGroups);
    return configDescription;
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) ArrayList(java.util.ArrayList) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ConfigDescriptionParameterGroup(org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup) ArrayList(java.util.ArrayList) List(java.util.List) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 3 with NodeIterator

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

the class AbstractDescriptionTypeConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    // set automatically extracted URI for a possible 'config-description' section
    context.put("config-description.uri", this.type + ":" + getUID(attributes, context));
    // read values
    List<?> nodes = (List<?>) context.convertAnother(context, List.class);
    NodeIterator nodeIterator = new NodeIterator(nodes);
    // create object
    Object object = unmarshalType(reader, context, attributes, nodeIterator);
    nodeIterator.assertEndOfType();
    return object;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) List(java.util.List)

Example 4 with NodeIterator

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

the class EventDescriptionConverter method unmarshal.

@Override
public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    List<EventOption> eventOptions = null;
    NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class);
    NodeIterator nodeIterator = new NodeIterator(nodes.getList());
    NodeList optionNodes = (NodeList) nodeIterator.next();
    if (optionNodes != null) {
        eventOptions = toListOfEventOptions(optionNodes);
    }
    nodeIterator.assertEndOfType();
    EventDescription eventDescription = new EventDescription(eventOptions);
    return eventDescription;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) NodeList(org.eclipse.smarthome.config.xml.util.NodeList) EventDescription(org.eclipse.smarthome.core.types.EventDescription) EventOption(org.eclipse.smarthome.core.types.EventOption)

Example 5 with NodeIterator

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

the class StateDescriptionConverter method unmarshal.

@Override
public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    BigDecimal minimum = toBigDecimal(attributes, "min", null);
    BigDecimal maximum = toBigDecimal(attributes, "max", null);
    BigDecimal step = toBigDecimal(attributes, "step", null);
    String pattern = attributes.get("pattern");
    boolean readOnly = toBoolean(attributes, "readOnly", false);
    List<StateOption> channelOptions = null;
    NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class);
    NodeIterator nodeIterator = new NodeIterator(nodes.getList());
    NodeList optionNodes = (NodeList) nodeIterator.next();
    if (optionNodes != null) {
        channelOptions = toListOfChannelState(optionNodes);
    }
    nodeIterator.assertEndOfType();
    StateDescription stateDescription = new StateDescription(minimum, maximum, step, pattern, readOnly, channelOptions);
    return stateDescription;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) NodeList(org.eclipse.smarthome.config.xml.util.NodeList) BigDecimal(java.math.BigDecimal) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Aggregations

NodeIterator (org.eclipse.smarthome.config.xml.util.NodeIterator)6 List (java.util.List)4 URI (java.net.URI)2 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)2 NodeList (org.eclipse.smarthome.config.xml.util.NodeList)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 BigDecimal (java.math.BigDecimal)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)1 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)1 BindingInfo (org.eclipse.smarthome.core.binding.BindingInfo)1 EventDescription (org.eclipse.smarthome.core.types.EventDescription)1 EventOption (org.eclipse.smarthome.core.types.EventOption)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1 StateOption (org.eclipse.smarthome.core.types.StateOption)1