From: Robert Varga Date: Sun, 18 May 2014 10:10:21 +0000 (+0200) Subject: BUG-1027: rework lookup for clarity X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~69^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c697dfa3b909ca25b73757c914d20e51886a11de BUG-1027: rework lookup for clarity 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 --- diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java index 846f949375..3f9d5c7854 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java @@ -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. builder().addAll(normalized.getPath()).add(new NodeIdentifier(child)) .build()); try { - if (!isNotRepresentable(childPath)) { - InstanceIdentifier potentialPath = shortenToLastAugment(toBindingImpl( - childPath).get()); - int potentialAugmentCount = getAugmentationCount(potentialPath); - if(potentialAugmentCount == normalizedCount) { - return Optional.> 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> baId = toBindingImpl(childPath); + if (!baId.isPresent()) { + LOG.debug("No binding-aware identifier found for path {}, skipping it", childPath); + continue; + } + + InstanceIdentifier potentialPath = shortenToLastAugment(baId.get()); + int potentialAugmentCount = getAugmentationCount(potentialPath); + if (potentialAugmentCount == normalizedCount) { + LOG.trace("Found matching path {}", potentialPath); + return Optional.> 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() { - - @SuppressWarnings("rawtypes") @Override - public Class call() throws Exception { + public Class call() { Type listResult = ClassLoaderUtils.getFirstGenericParameter(method .getGenericReturnType()); if (listResult instanceof Class