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 org.opendaylight.mdsal.dom.api.DOMMountPointService;
12 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
13 import com.google.common.base.Optional;
14 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
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;
21 final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> implements ListenerRegistration<T>, MountProvisionListener {
23 private final T listener;
24 private final ListenerRegistration<MountProvisionListener> registration;
25 private final BindingToNormalizedNodeCodec codec;
27 public BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec, final DOMMountPointService mountService) {
28 this.listener = listener;
30 this.registration = mountService.registerProvisionListener(this);
34 public T getInstance() {
44 public void onMountPointCreated(final YangInstanceIdentifier path) {
46 final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
47 listener.onMountPointCreated(bindingPath);
48 } catch (final DeserializationException e) {
49 BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Omitting event.",path,e);
54 private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path) throws DeserializationException {
55 final Optional<InstanceIdentifier<? extends DataObject>> instanceIdentifierOptional = codec.toBinding(path);
56 if(instanceIdentifierOptional.isPresent()) {
57 return instanceIdentifierOptional.get();
59 throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
64 public void onMountPointRemoved(final YangInstanceIdentifier path) {
66 final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
67 listener.onMountPointRemoved(bindingPath);
68 } catch (final DeserializationException e) {
69 BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Omitting event.",path,e);