@Override
public void leafSetEntryNode(final QName name, final Object value, final Map<QName, String> attributes)
throws IOException {
- final LeafListSchemaNode schema = tracker.leafSetEntryNode();
+ final LeafListSchemaNode schema = tracker.leafSetEntryNode(name);
writeElement(schema.getQName(), value, attributes, schema);
}
@Override
public void leafSetEntryNode(final QName name, final Object value) throws IOException {
- final LeafListSchemaNode schema = tracker.leafSetEntryNode();
+ final LeafListSchemaNode schema = tracker.leafSetEntryNode(name);
writeElement(schema.getQName(), value, Collections.emptyMap(), schema);
}
@Override
return (LeafListSchemaNode)schema;
}
+ @Deprecated
public LeafListSchemaNode leafSetEntryNode() {
final Object parent = getParent();
return (LeafListSchemaNode) parent;
}
+ public LeafListSchemaNode leafSetEntryNode(final QName qname) {
+ final Object parent = getParent();
+ if (parent instanceof LeafListSchemaNode) {
+ return (LeafListSchemaNode) parent;
+ } else {
+ final SchemaNode child = SchemaUtils.findChildSchemaByQName((SchemaNode) parent, qname);
+ Preconditions.checkArgument(child instanceof LeafListSchemaNode,
+ "Node %s is neither a leaf-list nor currently in a leaf-list", child.getPath());
+ return (LeafListSchemaNode) child;
+ }
+ }
+
public ChoiceSchemaNode startChoiceNode(final NodeIdentifier name) {
LOG.debug("Enter choice {}", name);
final SchemaNode schema = getSchema(name);
@Override
public void leafSetEntryNode(final QName name, final Object value, final Map<QName, String> attributes)
throws IOException {
- final LeafListSchemaNode schema = tracker.leafSetEntryNode();
+ final LeafListSchemaNode schema = tracker.leafSetEntryNode(name);
writeElement(schema.getQName(), value, attributes, schema);
}
@Override
public void leafSetEntryNode(final QName name, final Object value) throws IOException {
- final LeafListSchemaNode schema = tracker.leafSetEntryNode();
+ final LeafListSchemaNode schema = tracker.leafSetEntryNode(name);
writeElement(schema.getQName(), value, Collections.emptyMap(), schema);
}
@Override
public static SchemaNode findParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) {
SchemaNode current = Preconditions.checkNotNull(schemaContext);
for (final QName qname : path.getPathFromRoot()) {
- SchemaNode child;
- if (current instanceof DataNodeContainer) {
- child = ((DataNodeContainer) current).getDataChildByName(qname);
+ current = findChildSchemaByQName(current, qname);
+ }
+ return current;
+ }
- if (child == null && current instanceof SchemaContext) {
- child = tryFindGroupings((SchemaContext) current, qname).orNull();
- }
+ /**
+ * Find child schema node identified by its QName within a provided schema node.
+ * @param node schema node
+ * @param qname QName
+ * @return child schema node
+ * @throws java.lang.IllegalArgumentException if the schema node does not allow children
+ */
+ public static SchemaNode findChildSchemaByQName(final SchemaNode node, final QName qname) {
+ SchemaNode child = null;
- if (child == null && current instanceof SchemaContext) {
- child = tryFindNotification((SchemaContext) current, qname)
- .or(tryFindRpc(((SchemaContext) current), qname)).orNull();
- }
- } else if (current instanceof ChoiceSchemaNode) {
- child = ((ChoiceSchemaNode) current).getCaseNodeByName(qname);
- } else if (current instanceof RpcDefinition) {
- switch (qname.getLocalName()) {
- case "input":
- child = ((RpcDefinition) current).getInput();
- break;
- case "output":
- child = ((RpcDefinition) current).getOutput();
- break;
- default:
- child = null;
- break;
- }
- } else {
- throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", current));
+ if (node instanceof DataNodeContainer) {
+ child = ((DataNodeContainer) node).getDataChildByName(qname);
+
+ if (child == null && node instanceof SchemaContext) {
+ child = tryFindGroupings((SchemaContext) node, qname).orNull();
+ }
+
+ if (child == null && node instanceof SchemaContext) {
+ child = tryFindNotification((SchemaContext) node, qname)
+ .or(tryFindRpc(((SchemaContext) node), qname)).orNull();
}
- current = child;
+ } else if (node instanceof ChoiceSchemaNode) {
+ child = ((ChoiceSchemaNode) node).getCaseNodeByName(qname);
+ } else if (node instanceof RpcDefinition) {
+ switch (qname.getLocalName()) {
+ case "input":
+ child = ((RpcDefinition) node).getInput();
+ break;
+ case "output":
+ child = ((RpcDefinition) node).getOutput();
+ break;
+ default:
+ child = null;
+ break;
+ }
+ } else {
+ throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node));
}
- return current;
+
+ return child;
}
private static Optional<SchemaNode> tryFindGroupings(final SchemaContext ctx, final QName qname) {