- this.writer = writer;
- this.schemaContext = schemaContext;
- final Collection<SchemaNode> schemaNodes = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, path);
- Preconditions.checkArgument(!schemaNodes.isEmpty(), "Unable to find schema node for supplied schema path: %s",
- path);
- if (schemaNodes.size() > 1) {
- LOG.warn("More possible schema nodes {} for supplied schema path {}", schemaNodes, path);
+ this.root = this.schemaContext = requireNonNull(schemaContext);
+ }
+
+ /**
+ * Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
+ *
+ * @param writer Back-end writer
+ * @param schemaContext Associated {@link EffectiveModelContext}
+ * @param path root path
+ */
+ public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
+ final EffectiveModelContext schemaContext, final SchemaPath path) {
+ super(writer);
+ this.schemaContext = requireNonNull(schemaContext);
+
+ final SchemaInferenceStack stack = SchemaInferenceStack.ofInstantiatedPath(schemaContext, path);
+ if (!stack.isEmpty()) {
+ final EffectiveStatement<?, ?> current = stack.currentStatement();
+ // FIXME: this should be one of NormalizedNodeContainer/NotificationDefinition/OperationDefinition
+ checkArgument(current instanceof SchemaNode, "Instantiating at %s is not supported", current);
+ root = (SchemaNode) current;
+ } else {
+ root = schemaContext;