X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-codec-gson%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fcodec%2Fgson%2FCompositeNodeDataWithSchema.java;h=4d40db27f78c2b48cf7611659e46610619156b9d;hb=b52c1ffb0df2b84665b4d222166a3e4cdb8427bb;hp=d34712e4f12909e8dbecdebd87cdc76989d9ac73;hpb=b5c32f072f61abfe730a386f8ffe3862491785cd;p=yangtools.git diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java index d34712e4f1..4d40db27f7 100644 --- a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java @@ -7,11 +7,8 @@ */ package org.opendaylight.yangtools.yang.data.codec.gson; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import java.io.IOException; import java.util.ArrayList; @@ -19,13 +16,10 @@ import java.util.Collection; import java.util.Deque; import java.util.List; import java.util.Map.Entry; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.data.api.schema.stream.SchemaAwareNormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.AugmentationTarget; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; @@ -33,17 +27,12 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.YangModeledAnyXmlSchemaNode; /** * A node which is composed of multiple simpler nodes. */ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { - private static final Function QNAME_FUNCTION = new Function() { - @Override - public QName apply(@Nonnull final DataSchemaNode input) { - return input.getQName(); - } - }; /** * nodes which were added to schema via augmentation and are present in data input @@ -82,7 +71,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { AugmentationSchema augSchema = null; if (choiceCandidate.isAugmenting()) { - augSchema = findCorrespondingAugment(getSchema(), choiceCandidate); + augSchema = SchemaUtils.findCorrespondingAugment(getSchema(), choiceCandidate); } // looking for existing choice @@ -108,6 +97,10 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { if (schema instanceof LeafSchemaNode) { newChild = new LeafNodeDataWithSchema(schema); } else if (schema instanceof AnyXmlSchemaNode) { + // YangModeledAnyXmlSchemaNode is handled by addCompositeChild method. + if (schema instanceof YangModeledAnyXmlSchemaNode) { + return null; + } newChild = new AnyXmlNodeDataWithSchema(schema); } else { return null; @@ -115,7 +108,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { AugmentationSchema augSchema = null; if (schema.isAugmenting()) { - augSchema = findCorrespondingAugment(getSchema(), schema); + augSchema = SchemaUtils.findCorrespondingAugment(getSchema(), schema); } if (augSchema != null) { augmentationsToChild.put(augSchema, newChild); @@ -125,8 +118,8 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { return newChild; } - private CaseNodeDataWithSchema findChoice(final Collection childNodes, final DataSchemaNode choiceCandidate, - final DataSchemaNode caseCandidate) { + private static CaseNodeDataWithSchema findChoice(final Collection childNodes, + final DataSchemaNode choiceCandidate, final DataSchemaNode caseCandidate) { if (childNodes != null) { for (AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) { if (nodeDataWithSchema instanceof ChoiceNodeDataWithSchema @@ -145,22 +138,26 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { } AbstractNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) { - CompositeNodeDataWithSchema newChild; + final CompositeNodeDataWithSchema newChild; + if (schema instanceof ListSchemaNode) { newChild = new ListNodeDataWithSchema(schema); } else if (schema instanceof LeafListSchemaNode) { newChild = new LeafListNodeDataWithSchema(schema); } else if (schema instanceof ContainerSchemaNode) { newChild = new ContainerNodeDataWithSchema(schema); + } else if (schema instanceof YangModeledAnyXmlSchemaNode) { + newChild = new YangModeledAnyXmlNodeDataWithSchema((YangModeledAnyXmlSchemaNode)schema); } else { newChild = new CompositeNodeDataWithSchema(schema); } + addCompositeChild(newChild); return newChild; } void addCompositeChild(final CompositeNodeDataWithSchema newChild) { - AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema()); + AugmentationSchema augSchema = SchemaUtils.findCorrespondingAugment(getSchema(), newChild.getSchema()); if (augSchema != null) { augmentationsToChild.put(augSchema, newChild); } else { @@ -185,31 +182,16 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { return children.size(); } - /** - * Tries to find in {@code parent} which is dealed as augmentation target node with QName as {@code child}. If such - * node is found then it is returned, else null. - */ - AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) { - if (parent instanceof AugmentationTarget && !((parent instanceof ChoiceCaseNode) || (parent instanceof ChoiceSchemaNode))) { - for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) { - DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName()); - if (childInAugmentation != null) { - return augmentation; - } - } - } - return null; - } - @Override - public void write(final NormalizedNodeStreamWriter writer) throws IOException { + public void write(final SchemaAwareNormalizedNodeStreamWriter writer) throws IOException { for (AbstractNodeDataWithSchema child : children) { child.write(writer); } for (Entry> augmentationToChild : augmentationsToChild.asMap().entrySet()) { final Collection childsFromAgumentation = augmentationToChild.getValue(); if (!childsFromAgumentation.isEmpty()) { - writer.startAugmentationNode(toAugmentationIdentifier(augmentationToChild.getKey())); + // FIXME: can we get the augmentation schema? + writer.startAugmentationNode(SchemaUtils.getNodeIdentifierForAugmentation(augmentationToChild.getKey())); for (AbstractNodeDataWithSchema nodeDataWithSchema : childsFromAgumentation) { nodeDataWithSchema.write(writer); @@ -219,9 +201,4 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { } } } - - private static AugmentationIdentifier toAugmentationIdentifier(final AugmentationSchema schema) { - final Collection qnames = Collections2.transform(schema.getChildNodes(), QNAME_FUNCTION); - return new AugmentationIdentifier(ImmutableSet.copyOf(qnames)); - } }