2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.impl;
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;
22 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener>
23 implements ListenerRegistration<T>, DOMMountPointListener {
24 private static final Logger LOG = LoggerFactory.getLogger(BindingDOMMountPointListenerAdapter.class);
26 private final T listener;
27 private final ListenerRegistration<DOMMountPointListener> registration;
28 private final BindingToNormalizedNodeCodec codec;
30 BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec,
31 final DOMMountPointService mountService) {
32 this.listener = listener;
34 this.registration = mountService.registerProvisionListener(this);
38 public T getInstance() {
48 public void onMountPointCreated(final YangInstanceIdentifier path) {
50 final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
51 listener.onMountPointCreated(bindingPath);
52 } catch (final DeserializationException e) {
53 LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
58 private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path)
59 throws DeserializationException {
60 final Optional<InstanceIdentifier<? extends DataObject>> instanceIdentifierOptional = codec.toBinding(path);
61 if (instanceIdentifierOptional.isPresent()) {
62 return instanceIdentifierOptional.get();
64 throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
69 public void onMountPointRemoved(final YangInstanceIdentifier path) {
71 final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
72 listener.onMountPointRemoved(bindingPath);
73 } catch (final DeserializationException e) {
74 LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);