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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations