X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fmapping%2FAbstractNetconfOperation.java;h=25e0f7926574c3168bc013cff865ec2f6a8a33db;hp=6b12a1999270608264053c7edbf9ab1cc5bc6b55;hb=80aa861b74f7b0b3574f0962cdb45740ff71946c;hpb=e27d63bdcfbfb0c1078a9c3e5aabf59ae7e2315f diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperation.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperation.java index 6b12a19992..25e0f79265 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperation.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperation.java @@ -8,22 +8,27 @@ package org.opendaylight.controller.netconf.util.mapping; +import java.util.Map; + import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import java.util.Map; +import com.google.common.base.Optional; public abstract class AbstractNetconfOperation implements NetconfOperation { private final String netconfSessionIdForReporting; + private static final Logger logger = LoggerFactory.getLogger(AbstractNetconfOperation.class); protected AbstractNetconfOperation(String netconfSessionIdForReporting) { this.netconfSessionIdForReporting = netconfSessionIdForReporting; @@ -34,18 +39,20 @@ public abstract class AbstractNetconfOperation implements NetconfOperation { } @Override - public HandlingPriority canHandle(Document message) { - OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message); + public HandlingPriority canHandle(Document message) throws NetconfDocumentedException { + OperationNameAndNamespace operationNameAndNamespace = null; + operationNameAndNamespace = new OperationNameAndNamespace(message); return canHandle(operationNameAndNamespace.getOperationName(), operationNameAndNamespace.getNamespace()); } - public static class OperationNameAndNamespace { + public static final class OperationNameAndNamespace { private final String operationName, namespace; + private final XmlElement operationElement; - public OperationNameAndNamespace(Document message) { - XmlElement requestElement = getRequestElementWithCheck(message); - - XmlElement operationElement = requestElement.getOnlyChildElement(); + public OperationNameAndNamespace(Document message) throws NetconfDocumentedException { + XmlElement requestElement = null; + requestElement = getRequestElementWithCheck(message); + operationElement = requestElement.getOnlyChildElement(); operationName = operationElement.getName(); namespace = operationElement.getNamespace(); } @@ -57,9 +64,13 @@ public abstract class AbstractNetconfOperation implements NetconfOperation { public String getNamespace() { return namespace; } + + public XmlElement getOperationElement() { + return operationElement; + } } - protected static XmlElement getRequestElementWithCheck(Document message) { + protected static XmlElement getRequestElementWithCheck(Document message) throws NetconfDocumentedException { return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); } @@ -92,13 +103,12 @@ public abstract class AbstractNetconfOperation implements NetconfOperation { Map attributes = requestElement.getAttributes(); Element response = handle(document, operationElement, subsequentOperation); - Element rpcReply = document.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, - XmlNetconfConstants.RPC_REPLY_KEY); + Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); if(XmlElement.fromDomElement(response).hasNamespace()) { rpcReply.appendChild(response); } else { - Element responseNS = document.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, response.getNodeName()); + Element responseNS = XmlUtil.createElement(document, response.getNodeName(), Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); NodeList list = response.getChildNodes(); while(list.getLength()!=0) { responseNS.appendChild(list.item(0));