- private XmlElement getConfigElement(final XmlElement operationElement) throws NetconfDocumentedException{
- final Optional<XmlElement> configChildNode = operationElement.getOnlyChildElementOptionally(CONFIG_KEY);
- if (!configChildNode.isPresent()) {
- throw new NetconfDocumentedException("Can't get child element with name: " + CONFIG_KEY,
- ErrorType.application,
- ErrorTag.unknown_element,
+ private Datastore extractTargetParameter(final XmlElement operationElement) throws NetconfDocumentedException {
+ final XmlElement targetChildNode;
+ try {
+ final XmlElement targetElement = operationElement.getOnlyChildElementWithSameNamespace(TARGET_KEY);
+ targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
+ } catch (final MissingNameSpaceException | UnexpectedNamespaceException e) {
+ LOG.trace("Can't get only child element with same namespace", e);
+ throw NetconfDocumentedException.wrap(e);
+ }
+
+ return Datastore.valueOf(targetChildNode.getName());
+ }
+
+ private ModifyAction getDefaultOperation(final XmlElement operationElement) throws NetconfDocumentedException{
+ try {
+ return ModifyAction.fromXmlValue(getElement(operationElement, DEFAULT_OPERATION_KEY).getTextContent());
+ } catch (NetconfDocumentedException e) {
+ if (e.getErrorType() == ErrorType.protocol
+ && e.getErrorSeverity() == ErrorSeverity.error
+ && e.getErrorTag() == ErrorTag.missing_element) {
+ return ModifyAction.MERGE;
+ }
+ else {
+ throw e;
+ }
+ }
+ }
+
+ private XmlElement getElement(final XmlElement operationElement, String elementName) throws NetconfDocumentedException {
+ final Optional<XmlElement> childNode = operationElement.getOnlyChildElementOptionally(elementName);
+ if (!childNode.isPresent()) {
+ throw new NetconfDocumentedException(elementName + " element is missing",
+ ErrorType.protocol,
+ ErrorTag.missing_element,