Search in sources :

Example 6 with XmlElement

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

the class Config method fromXmlModulesMap.

/**
 * return a map containing namespace -> moduleName -> instanceName map.
 * Attribute parsing is omitted.
 */
public Map<String, Multimap<String, ModuleElementDefinition>> fromXmlModulesMap(final XmlElement xml, final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException {
    Optional<XmlElement> modulesElement = getModulesElement(xml);
    List<XmlElement> moduleElements = getModulesElementList(modulesElement);
    Map<String, Multimap<String, ModuleElementDefinition>> retVal = Maps.newHashMap();
    ResolvingStrategy<ModuleElementDefinition> resolvingStrategy = (moduleMapping, moduleElement, serviceTracker1, instanceName, moduleNamespace, defaultStrategy) -> {
        // 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);
        return new ModuleElementDefinition(instanceName, perInstanceEditStrategy, defaultStrategy);
    };
    for (XmlElement moduleElement : moduleElements) {
        resolveModule(retVal, serviceTracker, moduleElement, defaultEditStrategyType, resolvingStrategy);
    }
    return retVal;
}
Also used : XmlUtil(org.opendaylight.controller.config.util.xml.XmlUtil) Multimap(com.google.common.collect.Multimap) EditStrategyType(org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Optional(com.google.common.base.Optional) Document(org.w3c.dom.Document) Map(java.util.Map) EnumResolver(org.opendaylight.controller.config.facade.xml.osgi.EnumResolver) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Collection(java.util.Collection) Set(java.util.Set) ObjectName(javax.management.ObjectName) Maps(com.google.common.collect.Maps) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Revision(org.opendaylight.yangtools.yang.common.Revision) Element(org.w3c.dom.Element) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectNameUtil(org.opendaylight.controller.config.api.jmx.ObjectNameUtil) Collections(java.util.Collections) XmlMappingConstants(org.opendaylight.controller.config.util.xml.XmlMappingConstants) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Example 7 with XmlElement

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

the class CompositeAttributeReadingStrategy method readElementHook.

@Override
AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
    Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
    XmlElement complexElement = configNodes.get(0);
    Map<String, Object> innerMap = Maps.newHashMap();
    List<XmlElement> recognisedChildren = Lists.newArrayList();
    for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
        List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
        recognisedChildren.addAll(childItem);
        AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);
        Object value = resolvedInner.getValue();
        if (value == null) {
            value = resolvedInner.getDefaultValue();
        }
        innerMap.put(innerAttrEntry.getKey(), value);
    }
    complexElement.checkUnrecognisedElements(recognisedChildren);
    String perInstanceEditStrategy = complexElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
    return Strings.isNullOrEmpty(perInstanceEditStrategy) ? AttributeConfigElement.create(getNullableDefault(), innerMap) : AttributeConfigElement.create(getNullableDefault(), innerMap, EditStrategyType.valueOf(perInstanceEditStrategy));
}
Also used : XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Example 8 with XmlElement

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

the class ObjectNameAttributeReadingStrategy method resolve.

private ObjectNameAttributeMappingStrategy.MappedDependency resolve(final XmlElement firstChild) throws DocumentedException {
    XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
    Map.Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
    String serviceName = checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
    XmlElement nameElement = firstChild.getOnlyChildElementWithSameNamespace(XmlMappingConstants.NAME_KEY);
    String dependencyName = nameElement.getTextContent();
    return new ObjectNameAttributeMappingStrategy.MappedDependency(prefixNamespace.getValue(), serviceName, dependencyName);
}
Also used : XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) Map(java.util.Map)

Example 9 with XmlElement

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

the class ObjectNameAttributeReadingStrategy method readElementHook.

@Override
AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
    XmlElement firstChild = configNodes.get(0);
    Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild + " but was " + configNodes.size());
    Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild);
    return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild));
}
Also used : XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Example 10 with XmlElement

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

the class SimpleAttributeReadingStrategy method readElementHook.

@Override
AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
    XmlElement xmlElement = configNodes.get(0);
    Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement + " but was " + configNodes.size());
    String textContent = readElementContent(xmlElement);
    return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()), postprocessParsedValue(textContent));
}
Also used : 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