BUG-1027: rework lookup for clarity 53/7153/1
authorRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 10:10:21 +0000 (12:10 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 10:19:56 +0000 (12:19 +0200)
This patch gets rid of the nasty 'catch Exception', making the lookup
fail as soon as a DeserializationException is thrown. We account for
most of the checked exceptions, so this should not be a problem.

Change-Id: I3d0440933ebc30ba32a06690ebe326e18addf613
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java

index 846f949..3f9d5c7 100644 (file)
@@ -149,23 +149,38 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
         // to augmentation class
         // if child is referenced - so we will reference child and then shorten
         // path.
+        LOG.trace("Looking for candidates to match {}", normalized);
         for (QName child : lastArgument.getPossibleChildNames()) {
             org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier(
                     ImmutableList.<PathArgument> builder().addAll(normalized.getPath()).add(new NodeIdentifier(child))
                             .build());
             try {
-                if (!isNotRepresentable(childPath)) {
-                    InstanceIdentifier<? extends DataObject> potentialPath = shortenToLastAugment(toBindingImpl(
-                            childPath).get());
-                    int potentialAugmentCount = getAugmentationCount(potentialPath);
-                    if(potentialAugmentCount == normalizedCount) {
-                        return Optional.<InstanceIdentifier<? extends DataObject>> of(potentialPath);
-                    }
+                if (isNotRepresentable(childPath)) {
+                    LOG.trace("Path {} is not BI-representable, skipping it", childPath);
+                    continue;
                 }
-            } catch (Exception e) {
-                LOG.trace("Unable to deserialize aug. child path for {}", childPath, e);
+            } catch (DataNormalizationException e) {
+                LOG.warn("Failed to denormalize path {}, skipping it", childPath, e);
+                continue;
+            }
+
+            Optional<InstanceIdentifier<? extends DataObject>> baId = toBindingImpl(childPath);
+            if (!baId.isPresent()) {
+                LOG.debug("No binding-aware identifier found for path {}, skipping it", childPath);
+                continue;
+            }
+
+            InstanceIdentifier<? extends DataObject> potentialPath = shortenToLastAugment(baId.get());
+            int potentialAugmentCount = getAugmentationCount(potentialPath);
+            if (potentialAugmentCount == normalizedCount) {
+                LOG.trace("Found matching path {}", potentialPath);
+                return Optional.<InstanceIdentifier<? extends DataObject>> of(potentialPath);
             }
+
+            LOG.trace("Skipping mis-matched potential path {}", potentialPath);
         }
+
+        LOG.trace("Failed to find augmentation matching {}", normalized);
         return Optional.absent();
     }
 
@@ -350,10 +365,8 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener {
             try {
                 return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(),
                         new Callable<Class>() {
-
-                            @SuppressWarnings("rawtypes")
                             @Override
-                            public Class call() throws Exception {
+                            public Class call() {
                                 Type listResult = ClassLoaderUtils.getFirstGenericParameter(method
                                         .getGenericReturnType());
                                 if (listResult instanceof Class