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.mdsal.binding.dom.adapter;
10 import static java.util.Objects.requireNonNull;
12 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
13 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
14 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> implements
24 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 AdapterContext adapterContext;
31 BindingDOMMountPointListenerAdapter(final T listener, final AdapterContext adapterContext,
32 final DOMMountPointService mountService) {
33 this.listener = requireNonNull(listener);
34 this.adapterContext = requireNonNull(adapterContext);
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 public void onMountPointRemoved(final YangInstanceIdentifier path) {
61 final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
62 listener.onMountPointRemoved(bindingPath);
63 } catch (final DeserializationException e) {
64 LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
68 private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path)
69 throws DeserializationException {
70 final InstanceIdentifier<?> binding;
72 binding = adapterContext.currentSerializer().fromYangInstanceIdentifier(path);
73 } catch (IllegalArgumentException e) {
74 throw new DeserializationException("Deserialization unsuccessful, " + path, e);
76 if (binding == null) {
77 throw new DeserializationException("Deserialization unsuccessful, " + path);