Bug 8675: Fix a design flaw of the new XML parser
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / CompositeNodeDataWithSchema.java
index 45791b1effe884a1abda9fc3f1bdea4ce16ec8a9..86b113ff2f60b8a8f16a283be8600e24bf4c5433 100644 (file)
@@ -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.
+ *
+ * <p>
+ * 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<AugmentationSchema, AbstractNodeDataWithSchema> augmentationsToChild = ArrayListMultimap.create();
+    private final Multimap<AugmentationSchema, AbstractNodeDataWithSchema> 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<DataSchemaNode> 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<AugmentationSchema, Collection<AbstractNodeDataWithSchema>> augmentationToChild : augmentationsToChild.asMap().entrySet()) {
+        for (Entry<AugmentationSchema, Collection<AbstractNodeDataWithSchema>> augmentationToChild
+                : augmentationsToChild.asMap().entrySet()) {
             final Collection<AbstractNodeDataWithSchema> 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<QName> qnames = Collections2.transform(schema.getChildNodes(), DataSchemaNode::getQName);
         return new YangInstanceIdentifier.AugmentationIdentifier(ImmutableSet.copyOf(qnames));
     }