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;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
Iterator<PathArgument> arguments = legacy.getPath().iterator();
try {
- while ( arguments.hasNext() ) {
+ 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());
+ 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);
- }
+ normalizedArgs.add(legacyArg);
}
} catch (DataNormalizationException e) {
throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e);
return new InstanceIdentifier(normalizedArgs.build());
}
- public Map.Entry<InstanceIdentifier,NormalizedNode<?, ?>> toNormalized(final Map.Entry<InstanceIdentifier,CompositeNode> legacy) {
+ public Map.Entry<InstanceIdentifier, NormalizedNode<?, ?>> toNormalized(
+ final Map.Entry<InstanceIdentifier, CompositeNode> legacy) {
return toNormalized(legacy.getKey(), legacy.getValue());
}
- public Map.Entry<InstanceIdentifier,NormalizedNode<?, ?>> toNormalized(final InstanceIdentifier legacyPath, final CompositeNode legacyData) {
+ public Map.Entry<InstanceIdentifier, NormalizedNode<?, ?>> toNormalized(final InstanceIdentifier legacyPath,
+ final CompositeNode legacyData) {
InstanceIdentifier normalizedPath = toNormalized(legacyPath);
try {
currentOp = currentOp.getChild(arg);
} catch (DataNormalizationException e) {
- throw new IllegalArgumentException(String.format("Failed to validate normalized path %s", normalizedPath), e);
+ throw new IllegalArgumentException(String.format("Failed to validate normalized path %s",
+ normalizedPath), e);
}
}
throw new IllegalArgumentException(String.format("Failed to get child operation for %s", legacyData), e);
}
- if(potentialOp.getIdentifier() instanceof AugmentationIdentifier) {
+ if (potentialOp.getIdentifier() instanceof AugmentationIdentifier) {
currentOp = potentialOp;
ArrayList<PathArgument> reworkedArgs = new ArrayList<>(normalizedPath.getPath());
reworkedArgs.add(potentialOp.getIdentifier());
Preconditions.checkArgument(currentOp != null,
"Instance Identifier %s does not reference correct schema Node.", normalizedPath);
- return new AbstractMap.SimpleEntry<InstanceIdentifier,NormalizedNode<?, ?>>(normalizedPath,currentOp.normalize(legacyData));
+ return new AbstractMap.SimpleEntry<InstanceIdentifier, NormalizedNode<?, ?>>(normalizedPath,
+ currentOp.normalize(legacyData));
}
- public InstanceIdentifier toLegacy(final InstanceIdentifier normalized) {
+ public InstanceIdentifier toLegacy(final InstanceIdentifier normalized) throws DataNormalizationException {
ImmutableList.Builder<PathArgument> legacyArgs = ImmutableList.builder();
PathArgument previous = null;
+ DataNormalizationOperation<?> currentOp = operation;
for (PathArgument normalizedArg : normalized.getPath()) {
- if (normalizedArg instanceof NodeIdentifier) {
- if (previous != null) {
- legacyArgs.add(previous);
- }
- previous = normalizedArg;
- } else if (normalizedArg instanceof NodeIdentifierWithPredicates) {
- // We skip previous node, which was mixin.
- previous = normalizedArg;
- } else if (normalizedArg instanceof AugmentationIdentifier) {
- // We ignore argument
+ currentOp = currentOp.getChild(normalizedArg);
+ if(!currentOp.isMixin()) {
+ legacyArgs.add(normalizedArg);
}
- // FIXME : Add option for reading choice
- }
- if (previous != null) {
- legacyArgs.add(previous);
}
return new InstanceIdentifier(legacyArgs.build());
}
public static Node<?> toLegacy(final NormalizedNode<?, ?> node) {
if (node instanceof MixinNode) {
/**
- * Direct reading of MixinNodes is not supported,
- * since it is not possible in legacy APIs create pointer
- * to Mixin Nodes.
+ * Direct reading of MixinNodes is not supported, since it is not
+ * possible in legacy APIs create pointer to Mixin Nodes.
*
*/
return null;
final NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> mixin) {
ArrayList<Node<?>> ret = new ArrayList<>();
for (NormalizedNode<?, ?> child : mixin.getValue()) {
- if(child instanceof MixinNode && child instanceof NormalizedNodeContainer<?, ?, ?>) {
- Iterables.addAll(ret,toLegacyNodesFromMixin((NormalizedNodeContainer) child));
+ if (child instanceof MixinNode && child instanceof NormalizedNodeContainer<?, ?, ?>) {
+ Iterables.addAll(ret, toLegacyNodesFromMixin((NormalizedNodeContainer) child));
} else {
ret.add(toLegacy(child));
}