Bump upstreams
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / 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.server.mapping.operations;
9
10 import org.opendaylight.netconf.api.DocumentedException;
11 import org.opendaylight.netconf.api.NamespaceURN;
12 import org.opendaylight.netconf.api.messages.NetconfMessage;
13 import org.opendaylight.netconf.api.xml.XmlElement;
14 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
15 import org.opendaylight.netconf.api.xml.XmlUtil;
16 import org.opendaylight.netconf.server.NetconfServerSession;
17 import org.opendaylight.netconf.server.api.operations.AbstractSingletonNetconfOperation;
18 import org.opendaylight.netconf.server.api.operations.NetconfOperationChainedExecution;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
20 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
21 import org.opendaylight.yangtools.yang.common.ErrorTag;
22 import org.opendaylight.yangtools.yang.common.ErrorType;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27
28 public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {
29     public static final String START_EXI = "start-exi";
30
31     private static final Logger LOG = LoggerFactory.getLogger(DefaultStartExi.class);
32
33     private NetconfServerSession netconfSession = null;
34
35     public DefaultStartExi(final SessionIdType sessionId) {
36         super(sessionId);
37     }
38
39     @Override
40     public Document handle(final Document message,
41                            final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
42         if (LOG.isDebugEnabled()) {
43             LOG.debug("Received start-exi message {} ", XmlUtil.toString(message));
44         }
45
46         try {
47             netconfSession.startExiCommunication(new NetconfMessage(message));
48         } catch (final IllegalArgumentException e) {
49             throw new DocumentedException("Failed to parse EXI parameters", e, ErrorType.PROTOCOL,
50                     ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
51         }
52
53         return super.handle(message, subsequentOperation);
54     }
55
56     @Override
57     protected Element handleWithNoSubsequentOperations(final Document document,
58                                                        final XmlElement operationElement) {
59         final Element getSchemaResult = document.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.OK);
60         LOG.trace("{} operation successful", START_EXI);
61         return getSchemaResult;
62     }
63
64     @Override
65     protected String getOperationName() {
66         return START_EXI;
67     }
68
69     @Override
70     protected String getOperationNamespace() {
71         return NamespaceURN.EXI;
72     }
73
74     @Override
75     public void setNetconfSession(final NetconfServerSession netconfServerSession) {
76         netconfSession = netconfServerSession;
77     }
78 }