- private SchemaNode getSchema(final PathArgument name) {
- final Object parent = getParent();
- SchemaNode schema = null;
- final QName qname = name.getNodeType();
- if(parent instanceof DataNodeContainer) {
- schema = ((DataNodeContainer)parent).getDataChildByName(qname);
-
- if(schema == null && parent instanceof GroupingDefinition) {
- schema = ((GroupingDefinition) parent);
- }
+ /**
+ * Create a new writer with the specified context and rooted in the specified schema path.
+ *
+ * @param context Associated {@link EffectiveModelContext}
+ * @param operation Operation schema path
+ * @param qname Input/Output container QName
+ * @return A new {@link NormalizedNodeStreamWriter}
+ * @throws NullPointerException if any argument is null
+ * @throws IllegalArgumentException if {@code operation} does not point to an actual operation or if {@code qname}
+ * does not identify a valid root underneath it.
+ */
+ public static @NonNull SchemaTracker forOperation(final EffectiveModelContext context, final Absolute operation,
+ final QName qname) {
+ final SchemaInferenceStack stack = SchemaInferenceStack.of(context, operation);
+ final EffectiveStatement<?, ?> current = stack.currentStatement();
+ checkArgument(current instanceof RpcEffectiveStatement || current instanceof ActionEffectiveStatement,
+ "Path %s resolved into non-operation %s", operation, current);
+ stack.enterSchemaTree(qname);
+ return new SchemaTracker(stack);
+ }