Merge "creating a default subnet"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultStartExi.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.NetconfDocumentedException;\r
11 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;\r
12 import org.opendaylight.controller.netconf.api.NetconfSession;\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.ExiParameters;\r
19 import org.opendaylight.controller.netconf.util.xml.XmlElement;\r
20 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;\r
21 import org.opendaylight.controller.netconf.util.xml.XmlUtil;\r
22 import org.slf4j.Logger;\r
23 import org.slf4j.LoggerFactory;\r
24 import org.w3c.dom.Document;\r
25 import org.w3c.dom.Element;\r
26 \r
27 import com.siemens.ct.exi.exceptions.EXIException;\r
28 \r
29 public class DefaultStartExi extends AbstractNetconfOperation implements DefaultNetconfOperation {\r
30 \r
31     public static final String START_EXI = "start-exi";\r
32 \r
33     private static NetconfSession netconfSession;\r
34 \r
35     private static final Logger logger = LoggerFactory.getLogger(DefaultStartExi.class);\r
36 \r
37     public DefaultStartExi(String netconfSessionIdForReporting) {\r
38         super(netconfSessionIdForReporting);\r
39     }\r
40 \r
41     @Override\r
42     protected HandlingPriority canHandle(String operationName,\r
43             String netconfOperationNamespace) {\r
44         if (operationName.equals(START_EXI) == false)\r
45             return HandlingPriority.CANNOT_HANDLE;\r
46         if (netconfOperationNamespace\r
47                 .equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0) == false)\r
48             return HandlingPriority.CANNOT_HANDLE;\r
49 \r
50         return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;\r
51     }\r
52 \r
53     @Override\r
54     protected Element handle(Document document, XmlElement operationElement,\r
55             NetconfOperationRouter opRouter) throws NetconfDocumentedException {\r
56 \r
57 \r
58         Element getSchemaResult = document\r
59                 .createElement(XmlNetconfConstants.OK);\r
60         XmlUtil.addNamespaceAttr(getSchemaResult,\r
61                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
62 \r
63 \r
64         try {\r
65             ExiParameters exiParams = new ExiParameters();\r
66             exiParams.setParametersFromXmlElement(operationElement);\r
67 \r
68             netconfSession.addExiDecoder(ExiDecoderHandler.HANDLER_NAME, new ExiDecoderHandler(exiParams));\r
69             netconfSession.addExiEncoderAfterMessageSent(ExiEncoderHandler.HANDLER_NAME,new ExiEncoderHandler(exiParams));\r
70 \r
71         } catch (EXIException e) {\r
72             getSchemaResult = document\r
73                     .createElement(XmlNetconfConstants.RPC_ERROR);\r
74         }\r
75 \r
76         logger.info("{} operation successful", START_EXI);\r
77         logger.debug("received start-exi message {} ", XmlUtil.toString(document));\r
78         return getSchemaResult;\r
79 \r
80     }\r
81 \r
82     @Override\r
83     public void setNetconfSession(NetconfSession s) {\r
84         netconfSession = s;\r
85     }\r
86 \r
87     public NetconfSession getNetconfSession() {\r
88         return netconfSession;\r
89     }\r
90 \r
91 \r
92 }\r