use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader 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;
}
use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader 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;
}
Aggregations