Bug 2364: Migrated Binding MD-SAL to not use composites nodes
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMMountPointListenerAdapter.java
1 /*
2  * Copyright (c) 2015 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.md.sal.binding.impl;
9
10 import org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener;
11 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
12 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
18
19 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> implements ListenerRegistration<T>, MountProvisionListener {
20
21     private final T listener;
22     private final ListenerRegistration<MountProvisionListener> registration;
23     private final BindingToNormalizedNodeCodec codec;
24
25     public BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec, final DOMMountPointService mountService) {
26         this.listener = listener;
27         this.codec = codec;
28         this.registration = mountService.registerProvisionListener(this);
29     }
30
31     @Override
32     public T getInstance() {
33         return listener;
34     }
35
36     @Override
37     public void close() {
38         registration.close();
39     }
40
41     @Override
42     public void onMountPointCreated(final YangInstanceIdentifier path) {
43         try {
44             final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
45             listener.onMountPointCreated(bindingPath);
46         } catch (final DeserializationException e) {
47             BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
48         }
49
50     }
51
52     @Override
53     public void onMountPointRemoved(final YangInstanceIdentifier path) {
54         try {
55             final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
56             listener.onMountPointRemoved(bindingPath);
57         } catch (final DeserializationException e) {
58             BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
59         }
60     }
61 }

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