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