X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-common-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fcommon%2Fimpl%2Futil%2Fcompat%2FDataNormalizer.java;h=e1fc3c3cdb200b3c79a2e72b4d96abd03ca0572c;hb=6932c15f119da55b17ce4ad39236566bfed96ab3;hp=28b2bde26d31e4558b5f716666147983446811cc;hpb=f9a5557ea91bc6c877453583e17adf1606b58290;p=controller.git diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java index 28b2bde26d..e1fc3c3cdb 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.md.sal.common.impl.util.compat; import static com.google.common.base.Preconditions.checkArgument; @@ -7,6 +14,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier; @@ -44,18 +52,24 @@ public class DataNormalizer { DataNormalizationOperation currentOp = operation; Iterator arguments = legacy.getPath().iterator(); - while ( arguments.hasNext() ) { - PathArgument legacyArg = arguments.next(); - currentOp = currentOp.getChild(legacyArg); - checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build()); - while (currentOp.isMixin()) { - normalizedArgs.add(currentOp.getIdentifier()); - currentOp = currentOp.getChild(legacyArg.getNodeType()); - } - if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) { - normalizedArgs.add(legacyArg); + + try { + while ( arguments.hasNext() ) { + PathArgument legacyArg = arguments.next(); + currentOp = currentOp.getChild(legacyArg); + checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build()); + while (currentOp.isMixin()) { + normalizedArgs.add(currentOp.getIdentifier()); + currentOp = currentOp.getChild(legacyArg.getNodeType()); + } + if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) { + normalizedArgs.add(legacyArg); + } } + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e); } + return new InstanceIdentifier(normalizedArgs.build()); } @@ -69,12 +83,24 @@ public class DataNormalizer { DataNormalizationOperation currentOp = operation; for (PathArgument arg : normalizedPath.getPath()) { - currentOp = currentOp.getChild(arg); + try { + currentOp = currentOp.getChild(arg); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to validate normalized path %s", normalizedPath), e); + } } - // Write Augmentaiton data resolution + + // Write Augmentation data resolution if (legacyData.getChildren().size() == 1) { - DataNormalizationOperation potentialOp = currentOp.getChild(legacyData.getChildren().get(0) - .getNodeType()); + final DataNormalizationOperation potentialOp; + + try { + final QName childType = legacyData.getChildren().get(0).getNodeType(); + potentialOp = currentOp.getChild(childType); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to get child operation for %s", legacyData), e); + } + if(potentialOp.getIdentifier() instanceof AugmentationIdentifier) { currentOp = potentialOp; ArrayList reworkedArgs = new ArrayList<>(normalizedPath.getPath());