Initial implementation of netconf monitoring module according to http://tools.ietf...
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultStopExi.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.netconf.impl.mapping.operations;\r
9 \r
10 import org.opendaylight.controller.netconf.api.NetconfSession;\r
11 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;\r
12 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;\r
13 import org.opendaylight.controller.netconf.impl.mapping.ExiDecoderHandler;\r
14 import org.opendaylight.controller.netconf.impl.mapping.ExiEncoderHandler;\r
15 import org.opendaylight.controller.netconf.mapping.api.DefaultNetconfOperation;\r
16 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;\r
17 import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation;\r
18 import org.opendaylight.controller.netconf.util.xml.XmlElement;\r
19 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;\r
20 import org.opendaylight.controller.netconf.util.xml.XmlUtil;\r
21 import org.slf4j.Logger;\r
22 import org.slf4j.LoggerFactory;\r
23 import org.w3c.dom.Document;\r
24 import org.w3c.dom.Element;\r
25 \r
26 public class DefaultStopExi extends AbstractNetconfOperation implements DefaultNetconfOperation {\r
27 \r
28     public static final String STOP_EXI = "stop-exi";\r
29     private NetconfSession netconfSession;\r
30 \r
31     private static final Logger logger = LoggerFactory\r
32             .getLogger(DefaultStartExi.class);\r
33 \r
34     public DefaultStopExi(String netconfSessionIdForReporting) {\r
35         super(netconfSessionIdForReporting);\r
36     }\r
37 \r
38     @Override\r
39     protected HandlingPriority canHandle(String operationName,\r
40             String netconfOperationNamespace) {\r
41         if (operationName.equals(STOP_EXI) == false)\r
42             return HandlingPriority.CANNOT_HANDLE;\r
43         if (netconfOperationNamespace\r
44                 .equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0) == false)\r
45             return HandlingPriority.CANNOT_HANDLE;\r
46 \r
47         return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;\r
48     }\r
49 \r
50     @Override\r
51     protected Element handle(Document document, XmlElement operationElement,\r
52             NetconfOperationRouter opRouter) throws NetconfDocumentedException {\r
53 \r
54         netconfSession.remove(ExiDecoderHandler.class);\r
55         netconfSession.removeAfterMessageSent(ExiEncoderHandler.HANDLER_NAME);\r
56 \r
57         Element getSchemaResult = document.createElement(XmlNetconfConstants.OK);\r
58         XmlUtil.addNamespaceAttr(getSchemaResult,\r
59                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
60         logger.info("{} operation successful", STOP_EXI);\r
61         logger.debug("received stop-exi message {} ", XmlUtil.toString(document));\r
62         return getSchemaResult;\r
63     }\r
64 \r
65     @Override\r
66     public void setNetconfSession(NetconfSession s) {\r
67         this.netconfSession = s;\r
68     }\r
69 \r
70     public NetconfSession getNetconfSession() {\r
71         return netconfSession;\r
72     }\r
73 }