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;
23 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener>
24 implements ListenerRegistration<T>, DOMMountPointListener {
25 private static final Logger LOG = LoggerFactory.getLogger(BindingDOMMountPointListenerAdapter.class);
27 private final T listener;
28 private final ListenerRegistration<DOMMountPointListener> registration;
29 private final BindingToNormalizedNodeCodec codec;
31 BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec,
32 final DOMMountPointService mountService) {
33 this.listener = listener;
35 this.registration = mountService.registerProvisionListener(this);
39 public T getInstance() {
49 public void onMountPointCreated(final YangInstanceIdentifier path) {
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);
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();
65 throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
70 public void onMountPointRemoved(final YangInstanceIdentifier path) {
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);