- @SuppressWarnings("checkstyle:IllegalCatch")
- private NormalizedNode<?, ?> parseIntoNormalizedNode(final DataSchemaNode schemaNode, final XmlElement element,
- final DataTreeChangeTracker changeTracker) throws DocumentedException {
- if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) {
- //this should never happen since edit-config on any other node type should not be possible nor makes sense
- LOG.debug("DataNode from module is not ContainerSchemaNode nor ListSchemaNode, aborting..");
- throw new UnsupportedOperationException("implement exception if parse fails");
- }
-
- final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
- final NormalizedNodeStreamWriter writer = new EditOperationNormalizedNodeStreamWriter(resultHolder,
- changeTracker);
- final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext.getCurrentContext(), schemaNode);
- try {
- xmlParser.traverse(new DOMSource(element.getDomElement()));
- } catch (final Exception ex) {
- throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
- }
-
- return resultHolder.getResult();
- }
-
- private Optional<DataSchemaNode> getSchemaNodeFromNamespace(final String namespace, final XmlElement element)
- throws DocumentedException {
- Optional<DataSchemaNode> dataSchemaNode = Optional.absent();
- try {
- // returns module with newest revision since findModuleByNamespace returns a set of modules and we only
- // need the newest one
- final Module module =
- schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(namespace), null);
- if (module == null) {
- // no module is present with this namespace
- throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace,
- ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
- }
- final DataSchemaNode schemaNode =
- module.getDataChildByName(QName.create(module.getQNameModule(), element.getName()));
- if (schemaNode != null) {
- dataSchemaNode = Optional.of(schemaNode);
- } else {
- throw new DocumentedException(
- "Unable to find node with namespace: " + namespace + "in module: " + module.toString(),
- ErrorType.APPLICATION,
- ErrorTag.UNKNOWN_NAMESPACE,
- ErrorSeverity.ERROR);
- }
- } catch (final URISyntaxException e) {
- LOG.debug("Unable to create URI for namespace : {}", namespace);
- }
-
- return dataSchemaNode;
- }
-
- private static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
- final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY);
- // Direct lookup instead of using XmlElement class due to performance
- if (elementsByTagName.getLength() == 0) {
- final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element",
- OPERATION_NAME);
- throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
- ErrorSeverity.ERROR, errorInfo);
- } else if (elementsByTagName.getLength() > 1) {
- throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
- ErrorSeverity.ERROR);
- } else {
- final XmlElement targetChildNode =
- XmlElement.fromDomElement((Element) elementsByTagName.item(0)).getOnlyChildElement();
- return Datastore.valueOf(targetChildNode.getName());
- }
- }
-