Merge "Implement basic ShardTransactionChain#CloseTransactionChain"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultStartExi.java
index 8f08688f59dbcf456e7b4580bfbd8f1ea661235c..cccb1a3ac362e35c6f0efcd5836b3c5a51e1a320 100644 (file)
@@ -8,85 +8,64 @@
 package org.opendaylight.controller.netconf.impl.mapping.operations;\r
 \r
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;\r
-import org.opendaylight.controller.netconf.api.NetconfOperationRouter;\r
-import org.opendaylight.controller.netconf.api.NetconfSession;\r
-import org.opendaylight.controller.netconf.impl.mapping.ExiDecoderHandler;\r
-import org.opendaylight.controller.netconf.impl.mapping.ExiEncoderHandler;\r
-import org.opendaylight.controller.netconf.mapping.api.DefaultNetconfOperation;\r
-import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;\r
-import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation;\r
-import org.opendaylight.controller.netconf.util.xml.ExiParameters;\r
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;\r
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;\r
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;\r
+import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;\r
+import org.opendaylight.controller.netconf.api.NetconfMessage;\r
+import org.opendaylight.controller.netconf.impl.NetconfServerSession;\r
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;\r
+import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;\r
 import org.opendaylight.controller.netconf.util.xml.XmlElement;\r
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;\r
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
-\r
-import com.siemens.ct.exi.exceptions.EXIException;\r
-\r
-public class DefaultStartExi extends AbstractNetconfOperation implements DefaultNetconfOperation {\r
-\r
+public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {\r
     public static final String START_EXI = "start-exi";\r
 \r
-    private static NetconfSession netconfSession;\r
-\r
     private static final Logger logger = LoggerFactory.getLogger(DefaultStartExi.class);\r
+    private NetconfServerSession netconfSession;\r
 \r
     public DefaultStartExi(String netconfSessionIdForReporting) {\r
         super(netconfSessionIdForReporting);\r
     }\r
 \r
     @Override\r
-    protected HandlingPriority canHandle(String operationName,\r
-            String netconfOperationNamespace) {\r
-        if (operationName.equals(START_EXI) == false)\r
-            return HandlingPriority.CANNOT_HANDLE;\r
-        if (netconfOperationNamespace\r
-                .equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0) == false)\r
-            return HandlingPriority.CANNOT_HANDLE;\r
-\r
-        return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;\r
-    }\r
-\r
-    @Override\r
-    protected Element handle(Document document, XmlElement operationElement,\r
-            NetconfOperationRouter opRouter) throws NetconfDocumentedException {\r
-\r
-\r
-        Element getSchemaResult = document\r
-                .createElement(XmlNetconfConstants.OK);\r
-        XmlUtil.addNamespaceAttr(getSchemaResult,\r
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
-\r
+    public Document handle(Document message,\r
+                           NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {\r
+        logger.debug("Received start-exi message {} ", XmlUtil.toString(message));\r
 \r
         try {\r
-            ExiParameters exiParams = new ExiParameters();\r
-            exiParams.setParametersFromXmlElement(operationElement);\r
-\r
-            netconfSession.addExiDecoder(ExiDecoderHandler.HANDLER_NAME, new ExiDecoderHandler(exiParams));\r
-            netconfSession.addExiEncoderAfterMessageSent(ExiEncoderHandler.HANDLER_NAME,new ExiEncoderHandler(exiParams));\r
-\r
-        } catch (EXIException e) {\r
-            getSchemaResult = document\r
-                    .createElement(XmlNetconfConstants.RPC_ERROR);\r
+            netconfSession.startExiCommunication(new NetconfMessage(message));\r
+        } catch (IllegalArgumentException e) {\r
+            throw new NetconfDocumentedException("Failed to parse EXI parameters", ErrorType.protocol,\r
+                    ErrorTag.operation_failed, ErrorSeverity.error);\r
         }\r
 \r
-        logger.info("{} operation successful", START_EXI);\r
-        logger.debug("received start-exi message {} ", XmlUtil.toString(document));\r
-        return getSchemaResult;\r
-\r
+        return super.handle(message, subsequentOperation);\r
     }\r
 \r
     @Override\r
-    public void setNetconfSession(NetconfSession s) {\r
-        netconfSession = s;\r
+    protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException {\r
+        Element getSchemaResult = document.createElementNS( XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);\r
+        logger.trace("{} operation successful", START_EXI);\r
+        return getSchemaResult;\r
     }\r
 \r
-    public NetconfSession getNetconfSession() {\r
-        return netconfSession;\r
+    @Override\r
+    protected String getOperationName() {\r
+        return START_EXI;\r
     }\r
 \r
+    @Override\r
+    protected String getOperationNamespace() {\r
+        return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;\r
+    }\r
 \r
+    @Override\r
+    public void setNetconfSession(NetconfServerSession s) {\r
+        netconfSession = s;\r
+    }\r
 }\r