super(schema);
}
- public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas, final boolean rootListItem) {
+ public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas) {
Preconditions.checkArgument(!schemas.isEmpty(), "Expecting at least one schema");
// Pop the first node...
final DataSchemaNode schema = schemas.pop();
if (schemas.isEmpty()) {
// Simple, direct node
- return addChild(schema,rootListItem);
+ return addChild(schema);
}
// The choice/case mess, reuse what we already popped
CompositeNodeDataWithSchema caseNodeDataWithSchema = findChoice(childNodes, choiceCandidate, caseCandidate);
if (caseNodeDataWithSchema == null) {
- final ChoiceNodeDataWithSchema choiceNodeDataWithSchema = new ChoiceNodeDataWithSchema(choiceNode);
+ ChoiceNodeDataWithSchema choiceNodeDataWithSchema = new ChoiceNodeDataWithSchema(choiceNode);
addChild(choiceNodeDataWithSchema);
- caseNodeDataWithSchema = choiceNodeDataWithSchema.addCompositeChild(caseNode,rootListItem);
+ caseNodeDataWithSchema = choiceNodeDataWithSchema.addCompositeChild(caseNode);
}
- return caseNodeDataWithSchema.addChild(schemas, rootListItem);
+ return caseNodeDataWithSchema.addChild(schemas);
}
private AbstractNodeDataWithSchema addSimpleChild(final DataSchemaNode schema) {
private CaseNodeDataWithSchema findChoice(final Collection<AbstractNodeDataWithSchema> childNodes, final DataSchemaNode choiceCandidate,
final DataSchemaNode caseCandidate) {
if (childNodes != null) {
- for (final AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) {
+ for (AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) {
if (nodeDataWithSchema instanceof ChoiceNodeDataWithSchema
&& nodeDataWithSchema.getSchema().getQName().equals(choiceCandidate.getQName())) {
- final CaseNodeDataWithSchema casePrevious = ((ChoiceNodeDataWithSchema) nodeDataWithSchema).getCase();
+ 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 erlier. Data aren't from the same case.",
return null;
}
- AbstractNodeDataWithSchema addCompositeChild(final DataSchemaNode schema, final boolean rootListItem) {
+ AbstractNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
CompositeNodeDataWithSchema newChild;
if (schema instanceof ListSchemaNode) {
newChild = new ListNodeDataWithSchema(schema);
- /*
- * If we are reading root we may want to emit map also for object which represent one list
- * item.
- * */
- if(rootListItem) {
- addCompositeChild(newChild);
- final ListEntryNodeDataWithSchema entry = new ListEntryNodeDataWithSchema(schema);
- newChild.addChild(entry);
- return entry;
- }
} else if (schema instanceof LeafListSchemaNode) {
newChild = new LeafListNodeDataWithSchema(schema);
} else if (schema instanceof ContainerSchemaNode) {
}
void addCompositeChild(final CompositeNodeDataWithSchema newChild) {
- final AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema());
+ AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema());
if (augSchema != null) {
augmentationsToChild.put(augSchema, newChild);
} else {
}
}
- private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema, final boolean rootListItem) {
- final AbstractNodeDataWithSchema newChild = addSimpleChild(schema);
- return newChild == null ? addCompositeChild(schema,rootListItem) : newChild;
+ private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema) {
+ AbstractNodeDataWithSchema newChild = addSimpleChild(schema);
+ return newChild == null ? addCompositeChild(schema) : newChild;
}
public void addChild(final AbstractNodeDataWithSchema newChild) {
*/
AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
if (parent instanceof AugmentationTarget && !((parent instanceof ChoiceCaseNode) || (parent instanceof ChoiceSchemaNode))) {
- for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
- final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
+ for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
+ DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
if (childInAugmentation != null) {
return augmentation;
}
@Override
public void write(final NormalizedNodeStreamWriter writer) throws IOException {
- for (final AbstractNodeDataWithSchema child : children) {
+ for (AbstractNodeDataWithSchema child : children) {
child.write(writer);
}
- for (final 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()) {
writer.startAugmentationNode(toAugmentationIdentifier(augmentationToChild.getKey()));
- for (final AbstractNodeDataWithSchema nodeDataWithSchema : childsFromAgumentation) {
+ for (AbstractNodeDataWithSchema nodeDataWithSchema : childsFromAgumentation) {
nodeDataWithSchema.write(writer);
}
reader.peek();
isEmpty = false;
final CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema(parentNode);
- read(reader, compositeNodeDataWithSchema,true);
+ read(reader, compositeNodeDataWithSchema);
compositeNodeDataWithSchema.write(writer);
return this;
((SimpleNodeDataWithSchema) parent).setValue(translatedValue);
}
- public void read(final JsonReader in, final AbstractNodeDataWithSchema parent, final boolean rootRead) throws IOException {
+ public void read(final JsonReader in, AbstractNodeDataWithSchema parent) throws IOException {
switch (in.peek()) {
case STRING:
case NUMBER:
case BEGIN_ARRAY:
in.beginArray();
while (in.hasNext()) {
- AbstractNodeDataWithSchema newChild = null;
- if (parent instanceof ListNodeDataWithSchema) {
- newChild = new ListEntryNodeDataWithSchema(parent.getSchema());
- ((CompositeNodeDataWithSchema) parent).addChild(newChild);
- } else if (parent instanceof LeafListNodeDataWithSchema) {
- newChild = new LeafListEntryNodeDataWithSchema(parent.getSchema());
- ((CompositeNodeDataWithSchema) parent).addChild(newChild);
- }
- read(in, newChild,false);
+ final AbstractNodeDataWithSchema newChild = newArrayEntry(parent);
+ read(in, newChild);
}
in.endArray();
return;
case BEGIN_OBJECT:
final Set<String> namesakes = new HashSet<>();
in.beginObject();
+ /*
+ * This allows parsing of incorrectly /as showcased/
+ * in testconf nesting of list items - eg.
+ * lists with one value are sometimes serialized
+ * without wrapping array.
+ *
+ */
+ if(isArray(parent)) {
+ parent = newArrayEntry(parent);
+ }
while (in.hasNext()) {
final String jsonElementName = in.nextName();
final NamespaceAndName namespaceAndName = resolveNamespace(jsonElementName, parent.getSchema());
+ getCurrentNamespace() + " doesn't exist.");
}
- AbstractNodeDataWithSchema newChild;
- newChild = ((CompositeNodeDataWithSchema) parent).addChild(childDataSchemaNodes,rootRead);
-// FIXME:anyxml data shouldn't be skipped but should be loaded somehow. will be specified after 17AUG2014
+ final AbstractNodeDataWithSchema newChild = ((CompositeNodeDataWithSchema) parent).addChild(childDataSchemaNodes);
+ /*
+ * FIXME:anyxml data shouldn't be skipped but should be loaded somehow.
+ * will be able to load anyxml which conforms to YANG data using these
+ * parser, for other anyxml will be harder.
+ */
if (newChild instanceof AnyXmlNodeDataWithSchema) {
in.skipValue();
} else {
- read(in, newChild,false);
+ read(in, newChild);
}
removeNamespace();
}
}
}
+ private boolean isArray(final AbstractNodeDataWithSchema parent) {
+ return parent instanceof ListNodeDataWithSchema || parent instanceof ListNodeDataWithSchema;
+ }
+
+ private AbstractNodeDataWithSchema newArrayEntry(final AbstractNodeDataWithSchema parent) {
+ AbstractNodeDataWithSchema newChild;
+ if (parent instanceof ListNodeDataWithSchema) {
+ newChild = new ListEntryNodeDataWithSchema(parent.getSchema());
+ } else if (parent instanceof LeafListNodeDataWithSchema) {
+ newChild = new LeafListEntryNodeDataWithSchema(parent.getSchema());
+ } else {
+ throw new IllegalStateException("Incorrec nesting caused by parser.");
+ }
+ ((CompositeNodeDataWithSchema) parent).addChild(newChild);
+ return newChild;
+ }
+
private Object translateValueByType(final String value, final DataSchemaNode node) {
final TypeDefinition<? extends Object> typeDefinition = typeDefinition(node);
if (typeDefinition == null) {