Merge "Added threadpool config tests."
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultCloseSession.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
9 package org.opendaylight.controller.netconf.impl.mapping.operations;
10
11 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
12 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
13 import org.opendaylight.controller.netconf.api.NetconfSession;
14 import org.opendaylight.controller.netconf.mapping.api.DefaultNetconfOperation;
15 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
16 import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation;
17 import org.opendaylight.controller.netconf.util.xml.XmlElement;
18 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Element;
21
22 public class DefaultCloseSession extends AbstractNetconfOperation implements DefaultNetconfOperation {
23     public static final String CLOSE_SESSION = "close-session";
24     private NetconfSession netconfSession;
25
26     public DefaultCloseSession(String netconfSessionIdForReporting) {
27         super(netconfSessionIdForReporting);
28     }
29
30     @Override
31     protected HandlingPriority canHandle(String operationName, String netconfOperationNamespace) {
32         if (operationName.equals(CLOSE_SESSION) == false)
33             return HandlingPriority.CANNOT_HANDLE;
34         if (netconfOperationNamespace.equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0) == false)
35             return HandlingPriority.CANNOT_HANDLE;
36
37         return HandlingPriority.HANDLE_WITH_MAX_PRIORITY;
38     }
39
40     /**
41      * Close netconf operation router associated to this session, which in turn
42      * closes NetconfOperationServiceSnapshot with all NetconfOperationService
43      * instances
44      */
45     @Override
46     protected Element handle(Document document, XmlElement operationElement, NetconfOperationRouter opRouter)
47             throws NetconfDocumentedException {
48         opRouter.close();
49         return document.createElement(XmlNetconfConstants.OK);
50     }
51
52     @Override
53     public void setNetconfSession(NetconfSession s) {
54         this.netconfSession = s;
55     }
56
57     public NetconfSession getNetconfSession() {
58         return netconfSession;
59     }
60 }