fc0016f32c57020ee789efaf4358b7208dab9fe8
[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 java.util.Optional;
11 import org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener;
12 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
13 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Deprecated
23 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener>
24         implements ListenerRegistration<T>, DOMMountPointListener {
25     private static final Logger LOG = LoggerFactory.getLogger(BindingDOMMountPointListenerAdapter.class);
26
27     private final T listener;
28     private final ListenerRegistration<DOMMountPointListener> registration;
29     private final BindingToNormalizedNodeCodec codec;
30
31     BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec,
32             final DOMMountPointService mountService) {
33         this.listener = listener;
34         this.codec = codec;
35         this.registration = mountService.registerProvisionListener(this);
36     }
37
38     @Override
39     public T getInstance() {
40         return listener;
41     }
42
43     @Override
44     public void close() {
45         registration.close();
46     }
47
48     @Override
49     public void onMountPointCreated(final YangInstanceIdentifier path) {
50         try {
51             final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
52             listener.onMountPointCreated(bindingPath);
53         } catch (final DeserializationException e) {
54             LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
55         }
56
57     }
58
59     private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path)
60             throws DeserializationException {
61         final Optional<InstanceIdentifier<? extends DataObject>> instanceIdentifierOptional = codec.toBinding(path);
62         if (instanceIdentifierOptional.isPresent()) {
63             return instanceIdentifierOptional.get();
64         } else {
65             throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
66         }
67     }
68
69     @Override
70     public void onMountPointRemoved(final YangInstanceIdentifier path) {
71         try {
72             final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
73             listener.onMountPointRemoved(bindingPath);
74         } catch (final DeserializationException e) {
75             LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
76         }
77     }
78 }

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