fix ServiceHandler SpotBugs false positives
[transportpce.git] / tests / honeynode / 1.2.1 / netconf-impl / src / main / java / org / opendaylight / netconf / impl / mapping / operations / DefaultStartExi.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.impl.mapping.operations;
9
10 import org.opendaylight.netconf.api.DocumentedException;
11 import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
12 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
13 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
14 import org.opendaylight.netconf.api.NetconfMessage;
15 import org.opendaylight.netconf.api.xml.XmlElement;
16 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
17 import org.opendaylight.netconf.api.xml.XmlUtil;
18 import org.opendaylight.netconf.impl.NetconfServerSession;
19 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
20 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25
26 public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {
27     public static final String START_EXI = "start-exi";
28
29     private static final Logger LOG = LoggerFactory.getLogger(DefaultStartExi.class);
30     private NetconfServerSession netconfSession;
31
32     public DefaultStartExi(final String netconfSessionIdForReporting) {
33         super(netconfSessionIdForReporting);
34     }
35
36     @Override
37     public Document handle(final Document message,
38                            final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
39         if (LOG.isDebugEnabled()) {
40             LOG.debug("Received start-exi message {} ", XmlUtil.toString(message));
41         }
42
43         try {
44             netconfSession.startExiCommunication(new NetconfMessage(message));
45         } catch (final IllegalArgumentException e) {
46             throw new DocumentedException("Failed to parse EXI parameters", e, ErrorType.PROTOCOL,
47                     ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
48         }
49
50         return super.handle(message, subsequentOperation);
51     }
52
53     @Override
54     protected Element handleWithNoSubsequentOperations(final Document document,
55                                                        final XmlElement operationElement) {
56         final Element getSchemaResult = document.createElementNS(
57                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
58         LOG.trace("{} operation successful", START_EXI);
59         return getSchemaResult;
60     }
61
62     @Override
63     protected String getOperationName() {
64         return START_EXI;
65     }
66
67     @Override
68     protected String getOperationNamespace() {
69         return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;
70     }
71
72     @Override
73     public void setNetconfSession(final NetconfServerSession netconfServerSession) {
74         netconfSession = netconfServerSession;
75     }
76 }