Bug 591: Minimize the use of Xtend in sal-binding-broker-impl
[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 java.util.Collections;
12
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
14 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
15 import org.opendaylight.controller.netconf.util.xml.XmlElement;
16 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public class DefaultCloseSession extends AbstractSingletonNetconfOperation {
21     public static final String CLOSE_SESSION = "close-session";
22     private final AutoCloseable sessionResources;
23
24     public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) {
25         super(netconfSessionIdForReporting);
26         this.sessionResources = sessionResources;
27     }
28
29     @Override
30     protected String getOperationName() {
31         return CLOSE_SESSION;
32     }
33
34     /**
35      * Close netconf operation router associated to this session, which in turn
36      * closes NetconfOperationServiceSnapshot with all NetconfOperationService
37      * instances
38      */
39     @Override
40     protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
41             throws NetconfDocumentedException {
42         try {
43             sessionResources.close();
44         } catch (Exception e) {
45             throw new NetconfDocumentedException("Unable to properly close session "
46                     + getNetconfSessionIdForReporting(), NetconfDocumentedException.ErrorType.application,
47                     NetconfDocumentedException.ErrorTag.operation_failed,
48                     NetconfDocumentedException.ErrorSeverity.error, Collections.singletonMap(
49                     NetconfDocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
50         }
51         return document.createElement(XmlNetconfConstants.OK);
52     }
53 }

©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.