Merge "Remove duplicate dependency declaration"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / 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.controller.netconf.impl.mapping.operations;
9
10 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
11 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
14 import org.opendaylight.controller.netconf.api.NetconfMessage;
15 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
16 import org.opendaylight.controller.netconf.impl.NetconfServerSession;
17 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
18 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
19 import org.opendaylight.controller.netconf.util.xml.XmlElement;
20 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25 public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {
26     public static final String START_EXI = "start-exi";
27
28     private static final Logger LOG = LoggerFactory.getLogger(DefaultStartExi.class);
29     private NetconfServerSession netconfSession;
30
31     public DefaultStartExi(final String netconfSessionIdForReporting) {
32         super(netconfSessionIdForReporting);
33     }
34
35     @Override
36     public Document handle(final Document message,
37                            final NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
38         if (LOG.isDebugEnabled()) {
39             LOG.debug("Received start-exi message {} ", XmlUtil.toString(message));
40         }
41
42         try {
43             netconfSession.startExiCommunication(new NetconfMessage(message));
44         } catch (IllegalArgumentException e) {
45             throw new NetconfDocumentedException("Failed to parse EXI parameters", ErrorType.protocol,
46                     ErrorTag.operation_failed, ErrorSeverity.error);
47         }
48
49         return super.handle(message, subsequentOperation);
50     }
51
52     @Override
53     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException {
54         Element getSchemaResult = document.createElementNS( XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
55         LOG.trace("{} operation successful", START_EXI);
56         return getSchemaResult;
57     }
58
59     @Override
60     protected String getOperationName() {
61         return START_EXI;
62     }
63
64     @Override
65     protected String getOperationNamespace() {
66         return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;
67     }
68
69     @Override
70     public void setNetconfSession(final NetconfServerSession s) {
71         netconfSession = s;
72     }
73 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.