X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fmdsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fmdsal%2Fconnector%2Fops%2FEditConfig.java;h=a2aa0e20679473951cacd1191097f1368e76bac6;hp=fbefb5c56d818ffd3e039cea449202530a113e42;hb=9beb3e67d845dc479afcbee4d290d7a6e3c4c1fc;hpb=8eaba1eb027b02f8b36480721055dc99c6700e85 diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/EditConfig.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/EditConfig.java index fbefb5c56d..a2aa0e2067 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/EditConfig.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/EditConfig.java @@ -23,8 +23,6 @@ import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorT import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.mdsal.connector.CurrentSchemaContext; import org.opendaylight.controller.netconf.mdsal.connector.TransactionProvider; -import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException; -import org.opendaylight.controller.netconf.util.exception.UnexpectedNamespaceException; import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlUtil; @@ -47,6 +45,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; public class EditConfig extends AbstractSingletonNetconfOperation { @@ -182,35 +181,32 @@ public class EditConfig extends AbstractSingletonNetconfOperation { LOG.debug("DataNode from module is not ContainerSchemaNode nor ListSchemaNode, aborting.."); return Optional.absent(); } - } 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); + final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY); + // Direct lookup instead of using XmlElement class due to performance + if (elementsByTagName.getLength() == 0) { + throw new NetconfDocumentedException("Missing target element", ErrorType.rpc, ErrorTag.missing_attribute, ErrorSeverity.error); + } else if (elementsByTagName.getLength() > 1) { + throw new NetconfDocumentedException("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()); } - - 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 ModifyAction getDefaultOperation(final XmlElement operationElement) throws NetconfDocumentedException { + final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(DEFAULT_OPERATION_KEY); + if(elementsByTagName.getLength() == 0) { + return ModifyAction.MERGE; + } else if(elementsByTagName.getLength() > 1) { + throw new NetconfDocumentedException("Multiple " + DEFAULT_OPERATION_KEY + " elements", + ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error); + } else { + return ModifyAction.fromXmlValue(elementsByTagName.item(0).getTextContent()); } + } private XmlElement getElement(final XmlElement operationElement, String elementName) throws NetconfDocumentedException {