Bug 509: Fixed incorrect merging of Data Store Writes / Events
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / AbstractNetconfClientNotifySessionListener.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.client;
10
11 import org.opendaylight.controller.netconf.api.NetconfMessage;
12 import org.opendaylight.controller.netconf.util.xml.XmlElement;
13 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
14
15 /**
16  * Class extending {@link NetconfClientSessionListener} to provide notification capability.
17  */
18 public abstract class AbstractNetconfClientNotifySessionListener extends SimpleNetconfClientSessionListener {
19     /*
20      * Maybe some capabilities could be expressed as internal NetconfClientSessionListener handlers.
21      * It would enable NetconfClient functionality to be extended by using namespace handlers.
22      * So far let just enable notification capability by extending and let parent class intact.
23      */
24
25     /**
26      * As class purpose is to provide notification capability to session listener
27      * onMessage method is not allowed to be further overridden.
28      * {@see #onNotification(NetconfClientSession, NetconfMessage)}
29      *
30      * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)}
31      * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)}
32      */
33     @Override
34     public final void onMessage(NetconfClientSession session, NetconfMessage message) {
35         if (isNotification(message)) {
36             onNotification(session, message);
37         } else {
38             super.onMessage(session, message);
39         }
40     }
41
42     /**
43      * Method intended to customize notification processing.
44      *
45      * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)}
46      * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)}
47      */
48     public abstract void onNotification(NetconfClientSession session, NetconfMessage message);
49
50     private boolean isNotification(NetconfMessage message) {
51         XmlElement xmle = XmlElement.fromDomDocument(message.getDocument());
52         return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName()) ;
53     }
54 }