Merge "Bug 1029: Remove dead code: p2site"
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / mapping / AbstractNetconfOperation.java
index b7bbd3c6a70199cac0915d412568aae7d796d594..b7ebc51b70712a5ebabc322018c5707636113d13 100644 (file)
@@ -8,26 +8,24 @@
 
 package org.opendaylight.controller.netconf.util.mapping;
 
+import com.google.common.base.Optional;
 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.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import com.google.common.base.Optional;
-
 public abstract class AbstractNetconfOperation implements NetconfOperation {
     private final String netconfSessionIdForReporting;
 
-    protected AbstractNetconfOperation(String netconfSessionIdForReporting) {
+    protected AbstractNetconfOperation(final String netconfSessionIdForReporting) {
         this.netconfSessionIdForReporting = netconfSessionIdForReporting;
     }
 
@@ -36,18 +34,20 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
     }
 
     @Override
-    public HandlingPriority canHandle(Document message) {
-        OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message);
+    public HandlingPriority canHandle(final Document message) throws NetconfDocumentedException {
+        OperationNameAndNamespace operationNameAndNamespace = null;
+        operationNameAndNamespace = new OperationNameAndNamespace(message);
         return canHandle(operationNameAndNamespace.getOperationName(), operationNameAndNamespace.getNamespace());
     }
 
     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(final Document message) throws NetconfDocumentedException {
+            XmlElement requestElement = null;
+            requestElement = getRequestElementWithCheck(message);
+            operationElement = requestElement.getOnlyChildElement();
             operationName = operationElement.getName();
             namespace = operationElement.getNamespace();
         }
@@ -59,14 +59,18 @@ 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(final Document message) throws NetconfDocumentedException {
         return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY,
                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
 
-    protected HandlingPriority canHandle(String operationName, String operationNamespace) {
+    protected HandlingPriority canHandle(final String operationName, final String operationNamespace) {
         return operationName.equals(getOperationName()) && operationNamespace.equals(getOperationNamespace())
                 ? getHandlingPriority()
                 : HandlingPriority.CANNOT_HANDLE;
@@ -83,8 +87,8 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
     protected abstract String getOperationName();
 
     @Override
-    public Document handle(Document requestMessage,
-            NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
+    public Document handle(final Document requestMessage,
+            final NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
 
         XmlElement requestElement = getRequestElementWithCheck(requestMessage);
 
@@ -107,8 +111,8 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
             rpcReply.appendChild(responseNS);
         }
 
-        for (String attrName : attributes.keySet()) {
-            rpcReply.setAttributeNode((Attr) document.importNode(attributes.get(attrName), true));
+        for (Attr attribute : attributes.values()) {
+            rpcReply.setAttributeNode((Attr) document.importNode(attribute, true));
         }
         document.appendChild(rpcReply);
         return document;