Remove netconf from commons/opendaylight pom
[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.config.util.xml.DocumentedException;
11 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity;
12 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag;
13 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType;
14 import org.opendaylight.controller.config.util.xml.XmlElement;
15 import org.opendaylight.controller.config.util.xml.XmlUtil;
16 import org.opendaylight.controller.netconf.api.NetconfMessage;
17 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
18 import org.opendaylight.controller.netconf.impl.NetconfServerSession;
19 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
20 import org.opendaylight.controller.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 (IllegalArgumentException e) {
46             throw new DocumentedException("Failed to parse EXI parameters", 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, final XmlElement operationElement) throws DocumentedException {
55         Element getSchemaResult = document.createElementNS( XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
56         LOG.trace("{} operation successful", START_EXI);
57         return getSchemaResult;
58     }
59
60     @Override
61     protected String getOperationName() {
62         return START_EXI;
63     }
64
65     @Override
66     protected String getOperationNamespace() {
67         return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;
68     }
69
70     @Override
71     public void setNetconfSession(final NetconfServerSession s) {
72         netconfSession = s;
73     }
74 }