Merge "Bug 615: Removed xtend from Topology Manager"
[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.NetconfDocumentedException.ErrorSeverity;\r
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;\r
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;\r
14 import org.opendaylight.controller.netconf.api.NetconfMessage;\r
15 import org.opendaylight.controller.netconf.impl.NetconfServerSession;\r
16 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;\r
17 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;\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 public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {\r
26     public static final String START_EXI = "start-exi";\r
27 \r
28     private static final Logger logger = LoggerFactory.getLogger(DefaultStartExi.class);\r
29     private NetconfServerSession netconfSession;\r
30 \r
31     public DefaultStartExi(String netconfSessionIdForReporting) {\r
32         super(netconfSessionIdForReporting);\r
33     }\r
34 \r
35     @Override\r
36     public Document handle(Document message,\r
37                            NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {\r
38         logger.debug("Received start-exi message {} ", XmlUtil.toString(message));\r
39 \r
40         try {\r
41             netconfSession.startExiCommunication(new NetconfMessage(message));\r
42         } catch (IllegalArgumentException e) {\r
43             throw new NetconfDocumentedException("Failed to parse EXI parameters", ErrorType.protocol,\r
44                     ErrorTag.operation_failed, ErrorSeverity.error);\r
45         }\r
46 \r
47         return super.handle(message, subsequentOperation);\r
48     }\r
49 \r
50     @Override\r
51     protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException {\r
52         Element getSchemaResult = document.createElementNS( XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);\r
53         logger.trace("{} operation successful", START_EXI);\r
54         return getSchemaResult;\r
55     }\r
56 \r
57     @Override\r
58     protected String getOperationName() {\r
59         return START_EXI;\r
60     }\r
61 \r
62     @Override\r
63     protected String getOperationNamespace() {\r
64         return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;\r
65     }\r
66 \r
67     @Override\r
68     public void setNetconfSession(NetconfServerSession s) {\r
69         netconfSession = s;\r
70     }\r
71 }\r