Integrate MRI projects for Neon
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMMountPointListenerAdapter.java
index 5698156934e398624b71838dcb990fff39db6c87..ef80c78fb49b7a65342f15918da6c712589b7942 100644 (file)
@@ -7,22 +7,28 @@
  */
 package org.opendaylight.controller.md.sal.binding.impl;
 
+import java.util.Optional;
 import org.opendaylight.controller.md.sal.binding.api.MountPointService.MountPointListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
+import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> implements ListenerRegistration<T>, MountProvisionListener {
+final class BindingDOMMountPointListenerAdapter<T extends MountPointListener>
+        implements ListenerRegistration<T>, DOMMountPointListener {
+    private static final Logger LOG = LoggerFactory.getLogger(BindingDOMMountPointListenerAdapter.class);
 
     private final T listener;
-    private final ListenerRegistration<MountProvisionListener> registration;
+    private final ListenerRegistration<DOMMountPointListener> registration;
     private final BindingToNormalizedNodeCodec codec;
 
-    public BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec, final DOMMountPointService mountService) {
+    BindingDOMMountPointListenerAdapter(final T listener, final BindingToNormalizedNodeCodec codec,
+            final DOMMountPointService mountService) {
         this.listener = listener;
         this.codec = codec;
         this.registration = mountService.registerProvisionListener(this);
@@ -41,21 +47,31 @@ final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> im
     @Override
     public void onMountPointCreated(final YangInstanceIdentifier path) {
         try {
-            final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
+            final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
             listener.onMountPointCreated(bindingPath);
         } catch (final DeserializationException e) {
-            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
+            LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
         }
 
     }
 
+    private InstanceIdentifier<? extends DataObject> toBinding(final YangInstanceIdentifier path)
+            throws DeserializationException {
+        final Optional<InstanceIdentifier<? extends DataObject>> instanceIdentifierOptional = codec.toBinding(path);
+        if (instanceIdentifierOptional.isPresent()) {
+            return instanceIdentifierOptional.get();
+        } else {
+            throw new DeserializationException("Deserialization unsuccessful, " + instanceIdentifierOptional);
+        }
+    }
+
     @Override
     public void onMountPointRemoved(final YangInstanceIdentifier path) {
         try {
-            final InstanceIdentifier<? extends DataObject> bindingPath = codec.toBinding(path).get();
+            final InstanceIdentifier<? extends DataObject> bindingPath = toBinding(path);
             listener.onMountPointRemoved(bindingPath);
         } catch (final DeserializationException e) {
-            BindingDOMMountPointServiceAdapter.LOG.error("Unable to translate mountPoint path {}. Ommiting event.",path,e);
+            LOG.error("Unable to translate mountPoint path {}. Omitting event.", path, e);
         }
     }
-}
\ No newline at end of file
+}