return false;
}
+
+ public boolean isKeyedEntry() {
+ return false;
+ }
+
protected Set<QName> getQNameIdentifiers() {
return Collections.singleton(identifier.getNodeType());
}
return Builders.leafSetEntryBuilder().withNodeIdentifier(nodeId).withValue(node.getValue()).build();
}
+
+ @Override
+ public boolean isKeyedEntry() {
+ return true;
+ }
}
private static abstract class CompositeNodeNormalizationOpertation<T extends PathArgument> extends
protected NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode) {
ImmutableMap.Builder<QName, Object> keys = ImmutableMap.builder();
for (QName key : keyDefinition) {
- SimpleNode<?> valueNode = checkNotNull(compositeNode.getFirstSimpleByName(key),"List node %s MUST contain leaf %s with value.",getIdentifier().getNodeType(),key);
+
+ SimpleNode<?> valueNode = checkNotNull(compositeNode.getFirstSimpleByName(key),
+ "List node %s MUST contain leaf %s with value.", getIdentifier().getNodeType(), key);
keys.put(key, valueNode.getValue());
}
}
return builder.build();
}
+
+
+ @Override
+ public boolean isKeyedEntry() {
+ return true;
+ }
}
private static final class ContainerNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
import java.util.AbstractMap;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.Map;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
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;
public class DataNormalizer {
- private final SchemaContext schemaContext;
-
private final DataNormalizationOperation<?> operation;
public DataNormalizer(final SchemaContext ctx) {
- schemaContext = ctx;
operation = DataNormalizationOperation.from(ctx);
}
ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder();
DataNormalizationOperation<?> currentOp = operation;
- for (PathArgument legacyArg : legacy.getPath()) {
+ Iterator<PathArgument> 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());
}
- normalizedArgs.add(legacyArg);
+ if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) {
+ normalizedArgs.add(legacyArg);
+ }
}
return new InstanceIdentifier(normalizedArgs.build());
}