Search in sources :

Example 1 with ObjectXmlWriter

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter in project controller by opendaylight.

the class RpcFacade method toXml.

public Element toXml(final Document doc, final Object result, final OperationExecution execution) throws DocumentedException {
    AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper().prepareStrategy(execution.getReturnType());
    Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
    Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, execution.getReturnType().getOpenType());
    // FIXME: multiple return values defined as leaf-list and list in yang should
    // not be wrapped in output xml element,
    // they need to be appended directly under rpc-reply element
    // 
    // Either allow List of Elements to be returned from NetconfOperation or
    // pass reference to parent output xml element for netconf operations to
    // append result(s) on their own
    Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
    new ObjectXmlWriter().prepareWritingStrategy(execution.getReturnType().getAttributeYangName(), execution.getReturnType(), doc).writeElement(tempParent, execution.getNamespace(), mappedAttributeOpt.get());
    XmlElement xmlElement = XmlElement.fromDomElement(tempParent);
    return xmlElement.getChildElements().size() > 1 ? tempParent : xmlElement.getOnlyChildElement().getDomElement();
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectXmlWriter(org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter) ObjectMapper(org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.ObjectMapper)

Example 2 with ObjectXmlWriter

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter in project controller by opendaylight.

the class InstanceConfig method toXml.

@SuppressWarnings("IllegalCatch")
public Element toXml(final ObjectName on, final String namespace, final Document document, final Element rootElement, final EnumResolver enumResolver) {
    Map<String, AttributeWritingStrategy> strats = new ObjectXmlWriter().prepareWriting(yangToAttrConfig, document);
    Map<String, Object> mappedConfig = getMappedConfiguration(on, enumResolver);
    Element parentElement;
    if (nullableDummyContainerName != null) {
        Element dummyElement = XmlUtil.createElement(document, nullableDummyContainerName, Optional.of(namespace));
        rootElement.appendChild(dummyElement);
        parentElement = dummyElement;
    } else {
        parentElement = rootElement;
    }
    for (Entry<String, ?> mappingEntry : mappedConfig.entrySet()) {
        try {
            strats.get(mappingEntry.getKey()).writeElement(parentElement, namespace, mappingEntry.getValue());
        } catch (final RuntimeException e) {
            throw new IllegalStateException("Unable to write value " + mappingEntry.getValue() + " for attribute " + mappingEntry.getValue(), e);
        }
    }
    return rootElement;
}
Also used : AttributeWritingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.AttributeWritingStrategy) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectXmlWriter(org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter)

Aggregations

AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)2 ObjectXmlWriter (org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter)2 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)2 Element (org.w3c.dom.Element)2 ObjectMapper (org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.ObjectMapper)1 AttributeWritingStrategy (org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.AttributeWritingStrategy)1