Search in sources :

Example 11 with XmlElement

use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.

the class ArrayAttributeReadingStrategy method readElementHook.

@Override
AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
    List<Object> innerList = Lists.newArrayList();
    EditStrategyType innerEditStrategy = null;
    for (XmlElement configNode : configNodes) {
        final AttributeConfigElement attributeConfigElement = innerStrategy.readElement(Lists.newArrayList(configNode));
        if (attributeConfigElement.getEditStrategy().isPresent()) {
            // TODO this sets the last operation for the entire array
            innerEditStrategy = attributeConfigElement.getEditStrategy().get();
        }
        innerList.add(attributeConfigElement.getValue());
    }
    return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) : AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy);
}
Also used : XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) EditStrategyType(org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType)

Example 12 with XmlElement

use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.

the class RpcFacade method sortAttributes.

private Map<String, AttributeConfigElement> sortAttributes(final Map<String, AttributeConfigElement> attributes, final XmlElement xml) {
    final Map<String, AttributeConfigElement> sorted = new LinkedHashMap<>();
    for (XmlElement xmlElement : xml.getChildElements()) {
        final String name = xmlElement.getName();
        if (!CONTEXT_INSTANCE.equals(name)) {
            // skip context
            // instance child node
            // because it
            // specifies
            // ObjectName
            final AttributeConfigElement value = attributes.get(name);
            if (value == null) {
                throw new IllegalArgumentException("Cannot find yang mapping for node " + xmlElement);
            }
            sorted.put(name, value);
        }
    }
    return sorted;
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with XmlElement

use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.

the class InstanceConfig method fromXml.

public InstanceConfigElementResolved fromXml(XmlElement moduleElement, final ServiceRegistryWrapper services, final String moduleNamespace, final EditStrategyType defaultStrategy, final Map<String, Map<Optional<Revision>, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
    Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
    Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap);
    List<XmlElement> recognisedChildren = Lists.newArrayList();
    XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
    XmlElement nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.NAME_KEY);
    List<XmlElement> typeAndNameElements = Lists.newArrayList(typeElement, nameElement);
    // if dummy container was defined in yang, set moduleElement to its content
    if (nullableDummyContainerName != null) {
        int size = moduleElement.getChildElements().size();
        int expectedChildNodes = 1 + typeAndNameElements.size();
        if (size > expectedChildNodes) {
            throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - Expected " + expectedChildNodes + " child nodes, " + "one of them with name " + nullableDummyContainerName + ", got " + size + " elements.");
        }
        if (size == expectedChildNodes) {
            try {
                moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace);
            } catch (final DocumentedException e) {
                throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName + "." + e.getMessage(), e);
            }
        }
    // else 2 elements, no need to descend
    }
    for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
        List<XmlElement> configNodes = getConfigNodes(moduleElement, moduleNamespace, readStratEntry.getKey(), recognisedChildren, typeAndNameElements);
        AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
        retVal.put(readStratEntry.getKey(), readElement);
    }
    recognisedChildren.addAll(typeAndNameElements);
    try {
        moduleElement.checkUnrecognisedElements(recognisedChildren);
    } catch (final DocumentedException e) {
        throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - " + e.getMessage(), e, e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo());
    }
    // TODO: add check for conflicts between global and local edit strategy
    String perInstanceEditStrategy = moduleElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
    InstanceConfigElementResolved instanceConfigElementResolved = perInstanceEditStrategy.equals("") ? new InstanceConfigElementResolved(retVal, defaultStrategy) : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy);
    resolveConfiguration(instanceConfigElementResolved, services, enumResolver);
    return instanceConfigElementResolved;
}
Also used : AttributeReadingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) ObjectXmlReader(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Example 14 with XmlElement

use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.

the class InstanceRuntimeRpc method fromXml.

public Map<String, AttributeConfigElement> fromXml(final XmlElement configRootNode) throws DocumentedException {
    Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
    // FIXME add identity map to runtime data
    Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, Collections.<String, Map<Optional<Revision>, IdentityMapping>>emptyMap());
    for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
        List<XmlElement> configNodes = configRootNode.getChildElements(readStratEntry.getKey());
        AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
        retVal.put(readStratEntry.getKey(), readElement);
    }
    resolveConfiguration(retVal);
    return retVal;
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) AttributeReadingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy) Optional(com.google.common.base.Optional) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) ObjectXmlReader(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Aggregations

XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)14 AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)5 Map (java.util.Map)4 Optional (com.google.common.base.Optional)3 ObjectName (javax.management.ObjectName)3 IdentityMapping (org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping)3 EditStrategyType (org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType)3 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)3 Element (org.w3c.dom.Element)3 Preconditions (com.google.common.base.Preconditions)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Multimap (com.google.common.collect.Multimap)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2