X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FSchemaAwareApplyOperation.java;h=4bb5aed20c72d9a8424063818cf0c84e31630b47;hp=dd7eb3f71b68012b497bee6b5fb2119bcf9455c9;hb=fe8a0e74d2a1591bf77d727d388294a123b19f37;hpb=ccebe1096fdf88a3c883bd55be4aa1b390947377 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java index dd7eb3f71b..4bb5aed20c 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java @@ -1,7 +1,16 @@ +/* + * 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.dom.store.impl; import static com.google.common.base.Preconditions.checkArgument; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -10,6 +19,7 @@ import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType; import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreNodeCompositeBuilder; +import org.opendaylight.yangtools.yang.common.QName; 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; @@ -24,14 +34,21 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode; +import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.AugmentationSchemaProxy; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.AugmentationTarget; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; @@ -50,8 +67,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; import com.google.common.primitives.UnsignedLong; public abstract class SchemaAwareApplyOperation implements ModificationApplyOperation { @@ -60,37 +75,56 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper if (schemaNode instanceof ContainerSchemaNode) { return new ContainerModificationStrategy((ContainerSchemaNode) schemaNode); } else if (schemaNode instanceof ListSchemaNode) { - return new ListMapModificationStrategy((ListSchemaNode) schemaNode); + return fromListSchemaNode((ListSchemaNode) schemaNode); } else if (schemaNode instanceof ChoiceNode) { return new ChoiceModificationStrategy((ChoiceNode) schemaNode); } else if (schemaNode instanceof LeafListSchemaNode) { - return new LeafSetEntryModificationStrategy((LeafListSchemaNode) schemaNode); + return fromLeafListSchemaNode((LeafListSchemaNode) schemaNode); } else if (schemaNode instanceof LeafSchemaNode) { return new LeafModificationStrategy((LeafSchemaNode) schemaNode); } throw new IllegalArgumentException("Not supported schema node type for " + schemaNode.getClass()); } + private static SchemaAwareApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode) { + List keyDefinition = schemaNode.getKeyDefinition(); + if (keyDefinition == null || keyDefinition.isEmpty()) { + return new UnkeyedListModificationStrategy(schemaNode); + } + if (schemaNode.isUserOrdered()) { + return new OrderedMapModificationStrategy(schemaNode); + } + + return new UnorderedMapModificationStrategy(schemaNode); + } + + private static SchemaAwareApplyOperation fromLeafListSchemaNode(final LeafListSchemaNode schemaNode) { + if(schemaNode.isUserOrdered()) { + return new OrderedLeafSetModificationStrategy(schemaNode); + } else { + return new UnorderedLeafSetModificationStrategy(schemaNode); + } + } + + public static SchemaAwareApplyOperation from(final DataNodeContainer resolvedTree, final AugmentationTarget augSchemas, final AugmentationIdentifier identifier) { AugmentationSchema augSchema = null; - allAugments : for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) { + allAugments: for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) { boolean containsAll = true; - for(DataSchemaNode child : potential.getChildNodes()) { - if(identifier.getPossibleChildNames().contains(child.getQName())) { + for (DataSchemaNode child : potential.getChildNodes()) { + if (identifier.getPossibleChildNames().contains(child.getQName())) { augSchema = potential; break allAugments; } } } - if(augSchema != null) { - return new AugmentationModificationStrategy(augSchema,resolvedTree); + if (augSchema != null) { + return new AugmentationModificationStrategy(augSchema, resolvedTree); } return null; } - - protected final ModificationApplyOperation resolveChildOperation(final PathArgument child) { Optional potential = getChild(child); checkArgument(potential.isPresent(), "Operation for child %s is not defined.", child); @@ -115,6 +149,8 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper return isSubtreeModificationApplicable(modification, current); case WRITE: return isWriteApplicable(modification, current); + case MERGE: + return isMergeApplicable(modification,current); case UNMODIFIED: return true; default: @@ -122,6 +158,16 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } } + private boolean isMergeApplicable(final NodeModification modification, final Optional current) { + Optional original = modification.getOriginal(); + if (original.isPresent() && current.isPresent()) { + return isNotConflicting(original.get(), current.get()); + } else if (current.isPresent()) { + return true; + } + return true; + } + protected boolean isWriteApplicable(final NodeModification modification, final Optional current) { Optional original = modification.getOriginal(); if (original.isPresent() && current.isPresent()) { @@ -152,10 +198,16 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper switch (modification.getModificationType()) { case DELETE: - return modification.storeSnapshot(Optional.absent()); + return modification.storeSnapshot(Optional. absent()); case SUBTREE_MODIFIED: - Preconditions.checkArgument(currentMeta.isPresent(),"Metadata not available for modification",modification); - return modification.storeSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(), subtreeVersion))); + Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification", + modification); + return modification.storeSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(), + subtreeVersion))); + case MERGE: + if(currentMeta.isPresent()) { + return modification.storeSnapshot(Optional.of(applyMerge(modification,currentMeta.get(),subtreeVersion))); + } // Fallback to write is intentional - if node is not preexisting merge is same as write case WRITE: return modification.storeSnapshot(Optional.of(applyWrite(modification, currentMeta, subtreeVersion))); case UNMODIFIED: @@ -165,6 +217,9 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } } + protected abstract StoreMetadataNode applyMerge(NodeModification modification, + StoreMetadataNode currentMeta, UnsignedLong subtreeVersion); + protected abstract StoreMetadataNode applyWrite(NodeModification modification, Optional currentMeta, UnsignedLong subtreeVersion); @@ -201,14 +256,16 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper + "is leaf type node. Subtree change is not allowed."); } + @Override + protected StoreMetadataNode applyMerge(final NodeModification modification, final StoreMetadataNode currentMeta, + final UnsignedLong subtreeVersion) { + return applyWrite(modification, Optional.of(currentMeta), subtreeVersion); + } + @Override protected StoreMetadataNode applyWrite(final NodeModification modification, final Optional currentMeta, final UnsignedLong subtreeVersion) { UnsignedLong nodeVersion = subtreeVersion; - if (currentMeta.isPresent()) { - nodeVersion = StoreUtils.increase(currentMeta.get().getNodeVersion()); - } - return StoreMetadataNode.builder().setNodeVersion(nodeVersion).setSubtreeVersion(subtreeVersion) .setData(modification.getWritenValue()).build(); } @@ -270,84 +327,68 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override protected StoreMetadataNode applyWrite(final NodeModification modification, final Optional currentMeta, final UnsignedLong subtreeVersion) { - // + NormalizedNode newValue = modification.getWritenValue(); - UnsignedLong nodeVersion = subtreeVersion; + final UnsignedLong nodeVersion; if (currentMeta.isPresent()) { nodeVersion = StoreUtils.increase(currentMeta.get().getNodeVersion()); + } else { + nodeVersion = subtreeVersion; } - StoreMetadataNode newValueMeta = StoreMetadataNode.createRecursively(newValue, nodeVersion, nodeVersion); + final StoreMetadataNode newValueMeta = StoreMetadataNode.createRecursively(newValue, nodeVersion, nodeVersion); if (!modification.hasAdditionalModifications()) { return newValueMeta; } + @SuppressWarnings("rawtypes") - NormalizedNodeContainerBuilder dataBuilder = createBuilder(modification.getIdentifier()); + NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue); StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder) // .setNodeVersion(nodeVersion) // .setSubtreeVersion(subtreeVersion); - Set processedPreexisting = applyPreexistingChildren(modification, newValueMeta.getChildren(), - builder, nodeVersion); - applyNewChildren(modification, processedPreexisting, builder, nodeVersion); - - return builder.build(); + return mutateChildren(modification.getModifications(), newValueMeta, builder, nodeVersion); + } + @Override + protected StoreMetadataNode applyMerge(final NodeModification modification, final StoreMetadataNode currentMeta, + final UnsignedLong subtreeVersion) { + // For Node Containers - merge is same as subtree change - we only replace children. + return applySubtreeChange(modification, currentMeta, subtreeVersion); } @Override public StoreMetadataNode applySubtreeChange(final NodeModification modification, final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) { + // Bump subtree version to its new target + final UnsignedLong updatedSubtreeVersion = StoreUtils.increase(currentMeta.getSubtreeVersion()); - UnsignedLong updatedSubtreeVersion = StoreUtils.increase(currentMeta.getSubtreeVersion()); @SuppressWarnings("rawtypes") - NormalizedNodeContainerBuilder dataBuilder = createBuilder(modification.getIdentifier()); - StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder) + NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData()); + StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder, currentMeta) .setIdentifier(modification.getIdentifier()).setNodeVersion(currentMeta.getNodeVersion()) .setSubtreeVersion(updatedSubtreeVersion); - // We process preexisting nodes - Set processedPreexisting = applyPreexistingChildren(modification, currentMeta.getChildren(), - builder, updatedSubtreeVersion); - applyNewChildren(modification, processedPreexisting, builder, updatedSubtreeVersion); - return builder.build(); + + return mutateChildren(modification.getModifications(), currentMeta, builder, updatedSubtreeVersion); } - private void applyNewChildren(final NodeModification modification, final Set ignore, - final StoreNodeCompositeBuilder builder, final UnsignedLong subtreeVersion) { - for (NodeModification childModification : modification.getModifications()) { - PathArgument childIdentifier = childModification.getIdentifier(); - // We skip allready processed modifications - if (ignore.contains(childIdentifier)) { - continue; - } + private StoreMetadataNode mutateChildren(final Iterable modifications, final StoreMetadataNode meta, + final StoreNodeCompositeBuilder builder, final UnsignedLong nodeVersion) { - builder.addIfPresent(resolveChildOperation(childIdentifier) // - .apply(childModification, Optional. absent(), subtreeVersion)); - } - } + for (NodeModification mod : modifications) { + final PathArgument id = mod.getIdentifier(); + final Optional cm = meta.getChild(id); - private Set applyPreexistingChildren(final NodeModification modification, - final Iterable children, final StoreNodeCompositeBuilder nodeBuilder, - final UnsignedLong subtreeVersion) { - Builder processedModifications = ImmutableSet. builder(); - for (StoreMetadataNode childMeta : children) { - PathArgument childIdentifier = childMeta.getIdentifier(); - // We retrieve Child modification metadata - Optional childModification = modification.getChild(childIdentifier); - // Node is modified - if (childModification.isPresent()) { - processedModifications.add(childIdentifier); - Optional result = resolveChildOperation(childIdentifier) // - .apply(childModification.get(), Optional.of(childMeta), subtreeVersion); - nodeBuilder.addIfPresent(result); + Optional result = resolveChildOperation(id).apply(mod, cm, nodeVersion); + if (result.isPresent()) { + builder.add(result.get()); } else { - // Child is unmodified - reuse existing metadata and data - // snapshot - nodeBuilder.add(childMeta); + builder.remove(id); } } - return processedModifications.build(); + + return builder.build(); } @Override @@ -367,15 +408,15 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } @SuppressWarnings("rawtypes") - protected abstract NormalizedNodeContainerBuilder createBuilder(PathArgument identifier); + protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode original); } public static abstract class DataNodeContainerModificationStrategy extends NormalizedNodeContainerModificationStrategy { private final T schema; - private final LoadingCache childCache = CacheBuilder.newBuilder().build( - CacheLoader.from(new Function() { + private final LoadingCache childCache = CacheBuilder.newBuilder() + .build(CacheLoader.from(new Function() { @Override public ModificationApplyOperation apply(final PathArgument identifier) { @@ -412,7 +453,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override @SuppressWarnings("rawtypes") - protected abstract DataContainerNodeBuilder createBuilder(PathArgument identifier); + protected abstract DataContainerNodeBuilder createBuilder(NormalizedNode original); @Override public String toString() { @@ -430,45 +471,58 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override @SuppressWarnings("rawtypes") - protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) { - // TODO Auto-generated method stub - checkArgument(identifier instanceof NodeIdentifier); - return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier); + protected DataContainerNodeBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof ContainerNode); + return ImmutableContainerNodeBuilder.create((ContainerNode) original); } + } + public static class UnkeyedListItemModificationStrategy extends + DataNodeContainerModificationStrategy { + + public UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) { + super(schemaNode, UnkeyedListEntryNode.class); + } + + @Override + @SuppressWarnings("rawtypes") + protected DataContainerNodeBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof UnkeyedListEntryNode); + return ImmutableUnkeyedListEntryNodeBuilder.create((UnkeyedListEntryNode) original); + } } public static class AugmentationModificationStrategy extends DataNodeContainerModificationStrategy { protected AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved) { - super(schema, AugmentationNode.class); + super(createAugmentProxy(schema,resolved), AugmentationNode.class); // FIXME: Use resolved children instead of unresolved. } - @Override - protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) { - return Builders.augmentationBuilder().withNodeIdentifier((AugmentationIdentifier) identifier); + @SuppressWarnings("rawtypes") + protected DataContainerNodeBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof AugmentationNode); + return ImmutableAugmentationNodeBuilder.create((AugmentationNode) original); } - } public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy { private final ChoiceNode schema; - private final Map childNodes; + private final Map childNodes; public ChoiceModificationStrategy(final ChoiceNode schemaNode) { super(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode.class); this.schema = schemaNode; ImmutableMap.Builder child = ImmutableMap.builder(); - for(ChoiceCaseNode caze : schemaNode.getCases()) { - for(DataSchemaNode cazeChild : caze.getChildNodes()) { + for (ChoiceCaseNode caze : schemaNode.getCases()) { + for (DataSchemaNode cazeChild : caze.getChildNodes()) { SchemaAwareApplyOperation childNode = from(cazeChild); - child.put(new NodeIdentifier(cazeChild.getQName()),childNode); + child.put(new NodeIdentifier(cazeChild.getQName()), childNode); } } childNodes = child.build(); @@ -481,11 +535,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override @SuppressWarnings("rawtypes") - protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) { - checkArgument(identifier instanceof NodeIdentifier); - return ImmutableChoiceNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier); + protected DataContainerNodeBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode); + return ImmutableChoiceNodeBuilder.create((org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) original); } - } public static class ListEntryModificationStrategy extends DataNodeContainerModificationStrategy { @@ -496,26 +549,53 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override @SuppressWarnings("rawtypes") - protected final DataContainerNodeBuilder createBuilder(final PathArgument identifier) { - return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier((NodeIdentifierWithPredicates) identifier); + protected final DataContainerNodeBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof MapEntryNode); + return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original); + } + } + + public static class UnorderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy { + + private final Optional entryStrategy; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected UnorderedLeafSetModificationStrategy(final LeafListSchemaNode schema) { + super((Class) LeafSetNode.class); + entryStrategy = Optional. of(new LeafSetEntryModificationStrategy(schema)); + } + + @SuppressWarnings("rawtypes") + @Override + protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof LeafSetNode); + return ImmutableLeafSetNodeBuilder.create((LeafSetNode) original); } + @Override + public Optional getChild(final PathArgument identifier) { + if (identifier instanceof NodeWithValue) { + return entryStrategy; + } + return Optional.absent(); + } } - public static class LeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy { + public static class OrderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy { private final Optional entryStrategy; @SuppressWarnings({ "unchecked", "rawtypes" }) - protected LeafSetModificationStrategy(final LeafListSchemaNode schema) { + protected OrderedLeafSetModificationStrategy(final LeafListSchemaNode schema) { super((Class) LeafSetNode.class); entryStrategy = Optional. of(new LeafSetEntryModificationStrategy(schema)); } @SuppressWarnings("rawtypes") @Override - protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) { - return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier); + protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof OrderedLeafSetNode); + return ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode) original); } @Override @@ -525,22 +605,69 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } return Optional.absent(); } + } + + public static class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation { + + private final Optional entryStrategy; + + protected UnkeyedListModificationStrategy(final ListSchemaNode schema) { + entryStrategy = Optional. of(new UnkeyedListItemModificationStrategy(schema)); + } + + @Override + protected StoreMetadataNode applyMerge(final NodeModification modification, final StoreMetadataNode currentMeta, + final UnsignedLong subtreeVersion) { + return applyWrite(modification, Optional.of(currentMeta), subtreeVersion); + } + + @Override + protected StoreMetadataNode applySubtreeChange(final NodeModification modification, + final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) { + throw new UnsupportedOperationException("UnkeyedList does not support subtree change."); + } + + @Override + protected StoreMetadataNode applyWrite(final NodeModification modification, + final Optional currentMeta, final UnsignedLong subtreeVersion) { + return StoreMetadataNode.createRecursively(modification.getWritenValue(), subtreeVersion); + } + + @Override + public Optional getChild(final PathArgument child) { + if (child instanceof NodeIdentifier) { + return entryStrategy; + } + return Optional.absent(); + } + + @Override + protected void verifyWritenStructure(final NormalizedNode writenValue) { + + } + + @Override + protected boolean isSubtreeModificationApplicable(final NodeModification modification, + final Optional current) { + return false; + } } - public static class ListMapModificationStrategy extends NormalizedNodeContainerModificationStrategy { + public static class UnorderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy { private final Optional entryStrategy; - protected ListMapModificationStrategy(final ListSchemaNode schema) { + protected UnorderedMapModificationStrategy(final ListSchemaNode schema) { super(MapNode.class); entryStrategy = Optional. of(new ListEntryModificationStrategy(schema)); } @SuppressWarnings("rawtypes") @Override - protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) { - return ImmutableMapNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier); + protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof MapNode); + return ImmutableMapNodeBuilder.create((MapNode) original); } @Override @@ -553,7 +680,37 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper @Override public String toString() { - return "ListMapModificationStrategy [entry=" + entryStrategy + "]"; + return "UnorderedMapModificationStrategy [entry=" + entryStrategy + "]"; + } + } + + public static class OrderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy { + + private final Optional entryStrategy; + + protected OrderedMapModificationStrategy(final ListSchemaNode schema) { + super(OrderedMapNode.class); + entryStrategy = Optional. of(new ListEntryModificationStrategy(schema)); + } + + @SuppressWarnings("rawtypes") + @Override + protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode original) { + checkArgument(original instanceof OrderedMapNode); + return ImmutableOrderedMapNodeBuilder.create((OrderedMapNode) original); + } + + @Override + public Optional getChild(final PathArgument identifier) { + if (identifier instanceof NodeIdentifierWithPredicates) { + return entryStrategy; + } + return Optional.absent(); + } + + @Override + public String toString() { + return "OrderedMapModificationStrategy [entry=" + entryStrategy + "]"; } } @@ -561,4 +718,12 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper } + public static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) { + Set realChildSchemas = new HashSet<>(); + for(DataSchemaNode augChild : schema.getChildNodes()) { + realChildSchemas.add(resolved.getDataChildByName(augChild.getQName())); + } + return new AugmentationSchemaProxy(schema, realChildSchemas); + } + }