X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmdsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmdsal%2Fconnector%2Fops%2FAbstractEdit.java;h=acf55aab5bcf1bea52adda1c480120b216932d8b;hb=98a820a6085dc303a39b0c1d9098abfde963416a;hp=125f6b91cee00fcf88bad85b5d432cec64bba0d0;hpb=b0c464d8baf7df7f2765f6fc5abad7965b01039a;p=netconf.git diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java index 125f6b91ce..acf55aab5b 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java @@ -5,25 +5,24 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.mdsal.connector.ops; -import com.google.common.base.Optional; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Map; +import java.util.Optional; +import javax.xml.stream.XMLStreamException; import javax.xml.transform.dom.DOMSource; -import org.opendaylight.controller.config.util.xml.DocumentedException; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType; -import org.opendaylight.controller.config.util.xml.XmlElement; +import org.opendaylight.netconf.api.DocumentedException; +import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity; +import org.opendaylight.netconf.api.DocumentedException.ErrorTag; +import org.opendaylight.netconf.api.DocumentedException.ErrorType; import org.opendaylight.netconf.api.NetconfDocumentedException; +import org.opendaylight.netconf.api.xml.XmlElement; import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext; -import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream; @@ -35,8 +34,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; -abstract class AbstractEdit extends AbstractSingletonNetconfOperation { +abstract class AbstractEdit extends AbstractConfigOperation { private static final Logger LOG = LoggerFactory.getLogger(AbstractEdit.class); private static final String TARGET_KEY = "target"; @@ -47,7 +47,6 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { this.schemaContext = schemaContext; } - @SuppressWarnings("checkstyle:IllegalCatch") protected void parseIntoNormalizedNode(final DataSchemaNode schemaNode, final XmlElement element, final NormalizedNodeStreamWriter writer) throws DocumentedException { if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) { @@ -60,7 +59,7 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext.getCurrentContext(), schemaNode); try { xmlParser.traverse(new DOMSource(element.getDomElement())); - } catch (final Exception ex) { + } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) { throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR); } @@ -68,7 +67,7 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { protected DataSchemaNode getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws DocumentedException { - final Iterator it; + final Iterator it; try { // Returns module with newest revision since findModuleByNamespace returns a set of modules and we only // need the newest one @@ -85,11 +84,13 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { } final Module module = it.next(); - final java.util.Optional schemaNode = - module.findDataChildByName(QName.create(module.getQNameModule(), element.getName())); - if (!schemaNode.isPresent()) { + final String elementName = element.getName(); + final Optional schemaNode = module.findDataChildByName(QName.create(module.getQNameModule(), + element.getName())); + if (schemaNode.isEmpty()) { throw new DocumentedException( - "Unable to find node with namespace: " + namespace + "in module: " + module.toString(), + "Unable to find node " + elementName + " with namespace: " + namespace + "in module: " + + module.toString(), ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR); @@ -98,7 +99,7 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { return schemaNode.get(); } - protected static Datastore extractTargetParameter(final XmlElement operationElement, final String operationName) + protected static XmlElement extractTargetElement(final XmlElement operationElement, final String operationName) throws DocumentedException { final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY); // Direct lookup instead of using XmlElement class due to performance @@ -111,36 +112,7 @@ abstract class AbstractEdit extends AbstractSingletonNetconfOperation { 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()); + return XmlElement.fromDomElement((Element) elementsByTagName.item(0)).getOnlyChildElement(); } } - - protected static XmlElement getElement(final XmlElement parent, final String elementName) - throws DocumentedException { - final Optional childNode = parent.getOnlyChildElementOptionally(elementName); - if (!childNode.isPresent()) { - throw new DocumentedException(elementName + " element is missing", - ErrorType.PROTOCOL, - ErrorTag.MISSING_ELEMENT, - ErrorSeverity.ERROR); - } - - return childNode.get(); - } - - protected static NodeList getElementsByTagName(final XmlElement parent, final String key) throws - DocumentedException { - final Element domParent = parent.getDomElement(); - final NodeList elementsByTagName; - - if (Strings.isNullOrEmpty(domParent.getPrefix())) { - elementsByTagName = domParent.getElementsByTagName(key); - } else { - elementsByTagName = domParent.getElementsByTagNameNS(parent.getNamespace(), key); - } - - return elementsByTagName; - } }