X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Futil%2FCompositeNodeDataWithSchema.java;h=86b113ff2f60b8a8f16a283be8600e24bf4c5433;hb=f7132512adc35b5bc2628bf1cfd5f740e06e34cb;hp=45791b1effe884a1abda9fc3f1bdea4ce16ec8a9;hpb=d2269a6fc5ceda91c54446a8458eceb78ca659b9;p=yangtools.git diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/CompositeNodeDataWithSchema.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/CompositeNodeDataWithSchema.java index 45791b1eff..86b113ff2f 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/CompositeNodeDataWithSchema.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/CompositeNodeDataWithSchema.java @@ -34,14 +34,19 @@ 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. + * Utility class used for tracking parser state as needed by a StAX-like parser. + * This class is to be used only by respective XML and JSON parsers in yang-data-codec-xml and yang-data-codec-gson. + * + *

+ * Represents a node which is composed of multiple simpler nodes. */ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { /** - * nodes which were added to schema via augmentation and are present in data input + * nodes which were added to schema via augmentation and are present in data input. */ - private final Multimap augmentationsToChild = ArrayListMultimap.create(); + private final Multimap augmentationsToChild = + ArrayListMultimap.create(); /** * remaining data nodes (which aren't added via augment). Every of one them should have the same QName. @@ -52,6 +57,15 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { super(schema); } + private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema) { + AbstractNodeDataWithSchema newChild = addSimpleChild(schema); + return newChild == null ? addCompositeChild(schema) : newChild; + } + + public void addChild(final AbstractNodeDataWithSchema newChild) { + children.add(newChild); + } + public AbstractNodeDataWithSchema addChild(final Deque schemas) { Preconditions.checkArgument(!schemas.isEmpty(), "Expecting at least one schema"); @@ -131,8 +145,9 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { CaseNodeDataWithSchema casePrevious = ((ChoiceNodeDataWithSchema) nodeDataWithSchema).getCase(); Preconditions.checkArgument(casePrevious.getSchema().getQName().equals(caseCandidate.getQName()), - "Data from case %s are specified but other data from case %s were specified earlier. Data aren't from the same case.", - caseCandidate.getQName(), casePrevious.getSchema().getQName()); + "Data from case %s are specified but other data from case %s were specified earlier." + + " Data aren't from the same case.", caseCandidate.getQName(), + casePrevious.getSchema().getQName()); return casePrevious; } @@ -169,15 +184,6 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { } } - private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema) { - AbstractNodeDataWithSchema newChild = addSimpleChild(schema); - return newChild == null ? addCompositeChild(schema) : newChild; - } - - public void addChild(final AbstractNodeDataWithSchema newChild) { - children.add(newChild); - } - /** * Return a hint about how may children we are going to generate. * @return Size of currently-present node list. @@ -191,7 +197,8 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { for (AbstractNodeDataWithSchema child : children) { child.write(writer); } - for (Entry> augmentationToChild : augmentationsToChild.asMap().entrySet()) { + for (Entry> augmentationToChild + : augmentationsToChild.asMap().entrySet()) { final Collection childsFromAgumentation = augmentationToChild.getValue(); if (!childsFromAgumentation.isEmpty()) { // FIXME: can we get the augmentation schema? @@ -214,7 +221,8 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { * @param child child node * @return augmentation schema */ - private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) { + private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, + final DataSchemaNode child) { if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) { for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) { DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName()); @@ -226,7 +234,8 @@ public class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { return null; } - public static YangInstanceIdentifier.AugmentationIdentifier getNodeIdentifierForAugmentation(final AugmentationSchema schema) { + public static YangInstanceIdentifier.AugmentationIdentifier getNodeIdentifierForAugmentation( + final AugmentationSchema schema) { final Collection qnames = Collections2.transform(schema.getChildNodes(), DataSchemaNode::getQName); return new YangInstanceIdentifier.AugmentationIdentifier(ImmutableSet.copyOf(qnames)); }