These are useless things that introduce verbosity.
At the end of the day, EffectiveModelContextProvider is someone who has
EffectiveModelContext modelContext()
method -- which is but an idiom.
If we need to throw in a source of ISEs and callbacks, we are modeling
something much different -- better expressed explicitly where needed.
Change-Id: I6b1c11b01a0656a6a373e0d9b940607ee7a20aa0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
@Override
protected final JSONCodec<QName> identityRefCodec(final IdentityrefTypeDefinition type, final QNameModule module) {
- return new IdentityrefJSONCodec(getEffectiveModelContext(), module);
+ return new IdentityrefJSONCodec(modelContext(), module);
}
@Override
*/
public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory,
final JsonWriter jsonWriter, final @Nullable XMLNamespace initialNs) {
- return new Exclusive(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.getEffectiveModelContext()),
- jsonWriter, new JSONStreamWriterExclusiveRootContext(initialNs));
+ return new Exclusive(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.modelContext()), jsonWriter,
+ new JSONStreamWriterExclusiveRootContext(initialNs));
}
/**
*/
public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory,
final Absolute path, final XMLNamespace initialNs, final JsonWriter jsonWriter) {
- return new Exclusive(codecFactory,
- NormalizedNodeStreamWriterStack.of(codecFactory.getEffectiveModelContext(), path), jsonWriter,
- new JSONStreamWriterExclusiveRootContext(initialNs));
+ return new Exclusive(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.modelContext(), path),
+ jsonWriter, new JSONStreamWriterExclusiveRootContext(initialNs));
}
/**
*/
public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory,
final JsonWriter jsonWriter, final @Nullable XMLNamespace initialNs) {
- return new Nested(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.getEffectiveModelContext()),
- jsonWriter, new JSONStreamWriterSharedRootContext(initialNs));
+ return new Nested(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.modelContext()), jsonWriter,
+ new JSONStreamWriterSharedRootContext(initialNs));
}
/**
*/
public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory,
final Absolute path, final XMLNamespace initialNs, final JsonWriter jsonWriter) {
- return new Nested(codecFactory,
- NormalizedNodeStreamWriterStack.of(codecFactory.getEffectiveModelContext(), path), jsonWriter,
- new JSONStreamWriterSharedRootContext(initialNs));
+ return new Nested(codecFactory, NormalizedNodeStreamWriterStack.of(codecFactory.modelContext(), path),
+ jsonWriter, new JSONStreamWriterSharedRootContext(initialNs));
}
/**
@Override
public void startLeafNode(final NodeIdentifier name) throws IOException {
tracker.startLeafNode(name);
- context.emittingChild(codecs.getEffectiveModelContext(), writer);
- context.writeChildJsonIdentifier(codecs.getEffectiveModelContext(), writer, name.getNodeType());
+ context.emittingChild(codecs.modelContext(), writer);
+ context.writeChildJsonIdentifier(codecs.modelContext(), writer, name.getNodeType());
}
@Override
@Override
public void startLeafSetEntryNode(final NodeWithValue<?> name) throws IOException {
tracker.startLeafSetEntryNode(name);
- context.emittingChild(codecs.getEffectiveModelContext(), writer);
+ context.emittingChild(codecs.modelContext(), writer);
}
@Override
public final boolean startAnydataNode(final NodeIdentifier name, final Class<?> objectModel) throws IOException {
if (NormalizedAnydata.class.isAssignableFrom(objectModel)) {
tracker.startAnydataNode(name);
- context.emittingChild(codecs.getEffectiveModelContext(), writer);
- context.writeChildJsonIdentifier(codecs.getEffectiveModelContext(), writer, name.getNodeType());
+ context.emittingChild(codecs.modelContext(), writer);
+ context.writeChildJsonIdentifier(codecs.modelContext(), writer, name.getNodeType());
return true;
}
@Override
public final NormalizedNodeStreamWriter startMountPoint(final MountPointLabel label,
final MountPointContext mountCtx) throws IOException {
- final EffectiveModelContext ctx = mountCtx.getEffectiveModelContext();
+ final EffectiveModelContext ctx = mountCtx.modelContext();
return new Nested(codecs.rebaseTo(ctx), NormalizedNodeStreamWriterStack.of(ctx), writer,
new JSONStreamWriterSharedRootContext(context.getNamespace()));
}
public final boolean startAnyxmlNode(final NodeIdentifier name, final Class<?> objectModel) throws IOException {
if (DOMSource.class.isAssignableFrom(objectModel)) {
tracker.startAnyxmlNode(name);
- context.emittingChild(codecs.getEffectiveModelContext(), writer);
- context.writeChildJsonIdentifier(codecs.getEffectiveModelContext(), writer, name.getNodeType());
+ context.emittingChild(codecs.modelContext(), writer);
+ context.writeChildJsonIdentifier(codecs.modelContext(), writer, name.getNodeType());
return true;
}
return false;
@Override
public final void endNode() throws IOException {
tracker.endNode();
- context = context.endNode(codecs.getEffectiveModelContext(), writer);
+ context = context.endNode(codecs.modelContext(), writer);
}
@Override
throw new IOException("Unexpected root context " + context);
}
- context.endNode(codecs.getEffectiveModelContext(), writer);
+ context.endNode(codecs.modelContext(), writer);
writer.close();
}
}
anydata.writeTo(JSONNormalizedNodeStreamWriter.createNestedWriter(
- codecs.rebaseTo(inference.getEffectiveModelContext()), inference, context.getNamespace(), writer));
+ codecs.rebaseTo(inference.modelContext()), inference, context.getNamespace(), writer));
}
private void writeAnyXmlValue(final DOMSource anyXmlValue) throws IOException {
throw new IllegalArgumentException("Illegal parent node " + parent);
}
} else {
- parentNode = stack.getEffectiveModelContext();
+ parentNode = stack.modelContext();
}
}
public static @NonNull JsonParserStream create(final @NonNull NormalizedNodeStreamWriter writer,
final @NonNull JSONCodecFactory codecFactory) {
return new JsonParserStream(writer, codecFactory,
- SchemaInferenceStack.of(codecFactory.getEffectiveModelContext()), false);
+ SchemaInferenceStack.of(codecFactory.modelContext()), false);
}
/**
public static @NonNull JsonParserStream createLenient(final @NonNull NormalizedNodeStreamWriter writer,
final @NonNull JSONCodecFactory codecFactory) {
return new JsonParserStream(writer, codecFactory,
- SchemaInferenceStack.of(codecFactory.getEffectiveModelContext()), true);
+ SchemaInferenceStack.of(codecFactory.modelContext()), true);
}
/**
final var moduleNamePart = childName.substring(0, lastIndexOfColon);
nodeNamePart = childName.substring(lastIndexOfColon + 1);
- final var m = codecs.getEffectiveModelContext().findModuleStatements(moduleNamePart).iterator();
+ final var m = codecs.modelContext().findModuleStatements(moduleNamePart).iterator();
namespace = m.hasNext() ? m.next().localQNameModule().getNamespace() : null;
} else {
nodeNamePart = childName;
for (var potentialUri : potentialUris) {
sb.append('\n');
// FIXME how to get information about revision from JSON input? currently first available is used.
- sb.append(codecs.getEffectiveModelContext().findModuleStatements(potentialUri).iterator().next()
+ sb.append(codecs.modelContext().findModuleStatements(potentialUri).iterator().next()
.argument().getLocalName());
}
return sb.toString();
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
final class IdentityrefXmlCodec implements XmlCodec<QName> {
- private final @NonNull EffectiveModelContext context;
+ private final @NonNull EffectiveModelContext modelContext;
private final @NonNull QNameModule parentModule;
private final @Nullable PreferredPrefixes pref;
- IdentityrefXmlCodec(final EffectiveModelContext context, final QNameModule parentModule,
+ IdentityrefXmlCodec(final EffectiveModelContext modelContext, final QNameModule parentModule,
final @Nullable PreferredPrefixes pref) {
- this.context = requireNonNull(context);
+ this.modelContext = requireNonNull(modelContext);
this.parentModule = requireNonNull(parentModule);
this.pref = pref;
}
@Override
public QName parseValue(final NamespaceContext ctx, final String str) {
- return IdentityCodecUtil.parseIdentity(str, context, prefix -> {
+ return IdentityCodecUtil.parseIdentity(str, modelContext, prefix -> {
if (prefix.isEmpty()) {
return parentModule;
}
final var prefixedNS = ctx.getNamespaceURI(prefix);
checkArgument(prefixedNS != null, "Failed to resolve prefix %s", prefix);
- final var modules = context.findModuleStatements(XMLNamespace.of(prefixedNS)).iterator();
+ final var modules = modelContext.findModuleStatements(XMLNamespace.of(prefixedNS)).iterator();
checkArgument(modules.hasNext(), "Could not find module for namespace %s", prefixedNS);
return modules.next().localQNameModule();
}).getQName();
@Override
protected QNameModule moduleForPrefix(final String prefix) {
- final var modules = codecFactory.getEffectiveModelContext()
+ final var modules = codecFactory.modelContext()
.findModuleStatements(XMLNamespace.of(namespaceContext.getNamespaceURI(prefix)))
.iterator();
return modules.hasNext() ? modules.next().localQNameModule() : null;
InstanceIdentifierXmlCodec(final XmlCodecFactory codecFactory, final @Nullable PreferredPrefixes pref) {
this.codecFactory = requireNonNull(codecFactory);
this.pref = pref;
- dataContextTree = DataSchemaContextTree.from(codecFactory.getEffectiveModelContext());
+ dataContextTree = DataSchemaContextTree.from(codecFactory.modelContext());
}
@Override
*/
public static @NonNull NormalizedNodeStreamWriter create(final XMLStreamWriter writer,
final EffectiveStatementInference inference, final boolean preferPrefixes) {
- return new SchemaAwareXMLStreamNormalizedNodeStreamWriter(writer, inference.getEffectiveModelContext(),
+ return new SchemaAwareXMLStreamNormalizedNodeStreamWriter(writer, inference.modelContext(),
NormalizedNodeStreamWriterStack.of(inference), preferPrefixes);
}
private final @Nullable PreferredPrefixes pref;
private XmlCodecFactory(final MountPointContext mountCtx, final boolean modelPrefixes) {
- super(mountCtx.getEffectiveModelContext(), new SharedCodecCache<>());
+ super(mountCtx.modelContext(), new SharedCodecCache<>());
this.mountCtx = requireNonNull(mountCtx);
- pref = modelPrefixes ? new PreferredPrefixes.Shared(getEffectiveModelContext()) : null;
+ pref = modelPrefixes ? new PreferredPrefixes.Shared(modelContext()) : null;
instanceIdentifierCodec = new InstanceIdentifierXmlCodec(this, pref);
}
@Override
protected XmlCodec<?> identityRefCodec(final IdentityrefTypeDefinition type, final QNameModule module) {
- return new IdentityrefXmlCodec(getEffectiveModelContext(), module, pref);
+ return new IdentityrefXmlCodec(modelContext(), module, pref);
}
@Override
throw new IllegalArgumentException("Illegal parent node " + stmt);
}
} else {
- parentNode = stack.getEffectiveModelContext();
+ parentNode = stack.modelContext();
}
}
*/
public static XmlParserStream create(final NormalizedNodeStreamWriter writer,
final EffectiveStatementInference parentNode, final boolean strictParsing) {
- return create(writer, XmlCodecFactory.create(parentNode.getEffectiveModelContext()), parentNode, strictParsing);
+ return create(writer, XmlCodecFactory.create(parentNode.modelContext()), parentNode, strictParsing);
}
/**
* instead and maintain a {@link XmlCodecFactory} to match the current {@link MountPointContext}.
*/
public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx) {
- return create(writer, mountCtx, SchemaInferenceStack.of(mountCtx.getEffectiveModelContext()).toInference(),
- true);
+ return create(writer, mountCtx, SchemaInferenceStack.of(mountCtx.modelContext()).toInference(), true);
}
/**
public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final XmlCodecFactory codecs,
final Absolute parentNode, final boolean strictParsing) {
return new XmlParserStream(writer, codecs,
- SchemaInferenceStack.of(codecs.getEffectiveModelContext(), parentNode), strictParsing);
+ SchemaInferenceStack.of(codecs.modelContext(), parentNode), strictParsing);
}
@Beta
@Beta
public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx,
final YangInstanceIdentifier parentNode, final boolean strictParsing) {
- final var init = DataSchemaContextTree.from(mountCtx.getEffectiveModelContext())
+ final var init = DataSchemaContextTree.from(mountCtx.modelContext())
.enterPath(parentNode)
.orElseThrow();
return new XmlParserStream(writer, XmlCodecFactory.create(mountCtx), init.stack(), strictParsing);
final Optional<QNameModule> optModule = resolveXmlNamespace(attributeNS);
if (optModule.isPresent()) {
final QName qname = QName.create(optModule.orElseThrow(), localName);
- final var optAnnotation = AnnotationSchemaNode.find(codecs.getEffectiveModelContext(),
+ final var optAnnotation = AnnotationSchemaNode.find(codecs.modelContext(),
new AnnotationName(qname));
if (optAnnotation.isPresent()) {
final AnnotationSchemaNode schema = optAnnotation.orElseThrow();
private Optional<QNameModule> resolveXmlNamespace(final String xmlNamespace) {
return resolvedNamespaces.computeIfAbsent(xmlNamespace, nsUri -> {
- final var it = codecs.getEffectiveModelContext().findModuleStatements(XMLNamespace.of(nsUri)).iterator();
+ final var it = codecs.modelContext().findModuleStatements(XMLNamespace.of(nsUri)).iterator();
return it.hasNext() ? Optional.of(it.next().localQNameModule()) : Optional.empty();
});
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import static java.util.Objects.requireNonNull;
+
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.MountPointLabel;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
/**
* A simple {@link MountPointContext} which does not contain any mount points.
*/
-final class EmptyMountPointContext extends AbstractEffectiveModelContextProvider implements MountPointContext {
- EmptyMountPointContext(final EffectiveModelContext modelContext) {
- super(modelContext);
+record EmptyMountPointContext(@NonNull EffectiveModelContext modelContext) implements MountPointContext {
+ EmptyMountPointContext {
+ requireNonNull(modelContext);
}
@Override
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.MountPointLabel;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
/**
* A context of either an explicit (RFC8528 Schema Mount instance) or implicit (system root). It encapsulates a data
* so that proper {@link MountPointLabel}ed {@link NormalizedMountPoint}s can be created. This is enough to integrate
* with other elements of this API.
*/
-public interface MountPointContext extends EffectiveModelContextProvider {
+public interface MountPointContext {
+ /**
+ * Return this mount point's {@link EffectiveModelContext}.
+ *
+ * @return this mount point's {@link EffectiveModelContext}
+ */
+ @NonNull EffectiveModelContext modelContext();
+
/**
* Attempt to acquire a {@link MountPointContextFactory} to resolve schemas for the purposes of interpreting
* this mount point. An empty result indicates the mount point is not attached.
*/
package org.opendaylight.yangtools.yang.data.impl.schema;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ArrayListMultimap;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaTreeInference;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
* in the order as they are defined in YANG file.
*/
public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
- private final EffectiveModelContext schemaContext;
+ private final EffectiveModelContext modelContext;
private final SchemaNode root;
private SchemaNode currentSchemaNode;
* Create a new writer backed by a {@link NormalizedNodeStreamWriter}.
*
* @param writer Back-end writer
- * @param schemaContext Associated {@link EffectiveModelContext}
+ * @param modelContext Associated {@link EffectiveModelContext}
*/
public SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
- final EffectiveModelContext schemaContext) {
+ final EffectiveModelContext modelContext) {
super(writer);
- root = this.schemaContext = requireNonNull(schemaContext);
+ root = this.modelContext = requireNonNull(modelContext);
}
private SchemaOrderedNormalizedNodeWriter(final NormalizedNodeStreamWriter writer,
final SchemaInferenceStack stack) {
super(writer);
- schemaContext = stack.getEffectiveModelContext();
+ modelContext = stack.modelContext();
if (!stack.isEmpty()) {
- final EffectiveStatement<?, ?> current = stack.currentStatement();
+ final var 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;
+ if (current instanceof SchemaNode schemaNode) {
+ root = schemaNode;
+ } else {
+ throw new IllegalArgumentException("Instantiating at " + current + " is not supported");
+ }
} else {
- root = schemaContext;
+ root = modelContext;
}
}
@Override
public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
- if (schemaContext.equals(root)) {
- currentSchemaNode = schemaContext.dataChildByName(node.name().getNodeType());
+ if (modelContext.equals(root)) {
+ currentSchemaNode = modelContext.dataChildByName(node.name().getNodeType());
} else {
currentSchemaNode = root;
}
throws IOException {
//Set current schemaNode
- try (SchemaNodeSetter sns = new SchemaNodeSetter(dataSchemaNode)) {
+ try (var sns = new SchemaNodeSetter(dataSchemaNode)) {
if (node == null) {
return this;
}
}
private void write(final Collection<NormalizedNode> nodes, final SchemaNode dataSchemaNode) throws IOException {
- for (final NormalizedNode node : nodes) {
+ for (var node : nodes) {
write(node, dataSchemaNode);
}
}
final boolean endParent) throws IOException {
// Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
final var qnameToNodes = ArrayListMultimap.<QName, NormalizedNode>create();
- for (final NormalizedNode child : children) {
+ for (var child : children) {
putChild(qnameToNodes, child);
}
if (parentContainer instanceof ListSchemaNode && qnameToNodes.containsKey(parentSchemaNode.getQName())) {
write(qnameToNodes.get(parentSchemaNode.getQName()), parentSchemaNode);
} else {
- for (final DataSchemaNode schemaNode : parentContainer.getChildNodes()) {
+ for (var schemaNode : parentContainer.getChildNodes()) {
write(qnameToNodes.get(schemaNode.getQName()), schemaNode);
}
}
} else if (parentSchemaNode instanceof ChoiceSchemaNode parentChoice) {
- for (final CaseSchemaNode ccNode : parentChoice.getCases()) {
- for (final DataSchemaNode dsn : ccNode.getChildNodes()) {
- if (qnameToNodes.containsKey(dsn.getQName())) {
- write(qnameToNodes.get(dsn.getQName()), dsn);
+ for (var childCase : parentChoice.getCases()) {
+ for (var childCaseChild : childCase.getChildNodes()) {
+ final var node = qnameToNodes.asMap().get(childCaseChild.getQName());
+ if (node != null) {
+ write(node, childCaseChild);
}
}
}
} else {
- for (final NormalizedNode child : children) {
+ for (var child : children) {
writeLeaf(child);
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
* Read-only snapshot of a {@link DataTree}. The snapshot is stable and isolated, e.g. data tree changes occurring after
* the snapshot has been taken are not visible through the snapshot.
*/
-public interface DataTreeSnapshot extends EffectiveModelContextProvider {
+public interface DataTreeSnapshot {
+ /**
+ * Return the {@link EffectiveModelContext} effective at the time this snapshot was taken.
+ *
+ * @return the {@link EffectiveModelContext} effective at the time this snapshot was taken
+ */
+ @NonNull EffectiveModelContext modelContext();
+
/**
* Read a particular node from the snapshot.
*
Optional<NormalizedNode> readNode(YangInstanceIdentifier path);
/**
- * Create a new data tree modification based on this snapshot, using the
- * specified data application strategy.
+ * Create a new data tree modification based on this snapshot, using the specified data application strategy.
*
* @return A new data tree modification
*/
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
import org.opendaylight.yangtools.yang.data.tree.impl.node.Version;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class InMemoryDataTreeModification extends AbstractCursorAware implements CursorAwareDataTreeModification,
- EffectiveModelContextProvider {
+final class InMemoryDataTreeModification extends AbstractCursorAware implements CursorAwareDataTreeModification {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeModification.class);
private static final byte STATE_OPEN = 0;
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
- return snapshot.getEffectiveModelContext();
+ public EffectiveModelContext modelContext() {
+ return snapshot.modelContext();
}
@Override
if (newRoot == null) {
throw new IllegalStateException("Data tree root is not present, possibly removed by previous modification");
}
- return new InMemoryDataTreeSnapshot(snapshot.getEffectiveModelContext(), newRoot, strategyTree)
- .newModification();
+ return new InMemoryDataTreeSnapshot(snapshot.modelContext(), newRoot, strategyTree).newModification();
}
Version getVersion() {
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshotCursor;
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements CursorAwareDataTreeSnapshot,
- EffectiveModelContextProvider {
+final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements CursorAwareDataTreeSnapshot {
+ private final @NonNull EffectiveModelContext modelContext;
private final @NonNull RootApplyStrategy applyOper;
- private final @NonNull EffectiveModelContext schemaContext;
private final @NonNull TreeNode rootNode;
- InMemoryDataTreeSnapshot(final EffectiveModelContext schemaContext, final TreeNode rootNode,
+ InMemoryDataTreeSnapshot(final EffectiveModelContext modelContext, final TreeNode rootNode,
final RootApplyStrategy applyOper) {
- this.schemaContext = requireNonNull(schemaContext);
+ this.modelContext = requireNonNull(modelContext);
this.rootNode = requireNonNull(rootNode);
this.applyOper = requireNonNull(applyOper);
}
}
@Override
- public EffectiveModelContext getEffectiveModelContext() {
- return schemaContext;
+ public EffectiveModelContext modelContext() {
+ return modelContext;
}
@Override
package org.opendaylight.yangtools.yang.data.tree.leafref;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
-public final class LeafRefContext extends AbstractEffectiveModelContextProvider {
+public final class LeafRefContext {
+ private final @NonNull EffectiveModelContext modelContext;
private final QName currentNodeQName;
private final ImmutableList<QName> currentNodePath;
private volatile LeafRefPath leafRefNodePath = null;
LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
- super(leafRefContextBuilder.getSchemaContext());
+ modelContext = requireNonNull(leafRefContextBuilder.modelContext());
currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
currentNodePath = leafRefContextBuilder.getCurrentNodePath();
leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
module = leafRefContextBuilder.getLeafRefContextModule();
}
+ /**
+ * Return the {@link EffectiveModelContext} from which this context was derived.
+ *
+ * @return the {@link EffectiveModelContext} from which this context was derived
+ */
+ public @NonNull EffectiveModelContext modelContext() {
+ return modelContext;
+ }
+
public static LeafRefContext create(final EffectiveModelContext ctx) {
return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
}
private Iterator<QName> descendantIterator(final SchemaNodeIdentifier node) {
final Iterator<QName> nodeSteps = node.getNodeIdentifiers().iterator();
if (node instanceof SchemaNodeIdentifier.Absolute) {
- final Iterator<QName> mySteps = currentNodePath.iterator();
- while (mySteps.hasNext()) {
- final QName myNext = mySteps.next();
+ for (QName myNext : currentNodePath) {
checkArgument(nodeSteps.hasNext(), "Node %s is an ancestor of %s", node, currentNodePath);
final QName nodeNext = nodeSteps.next();
checkArgument(myNext.equals(nodeNext), "Node %s is not a descendant of %s", node, currentNodePath);
private final QName currentNodeQName;
private final ImmutableList<QName> currentNodePath;
- private final EffectiveModelContext schemaContext;
+ private final EffectiveModelContext modelContext;
private LeafRefPath leafRefTargetPath = null;
private LeafRefPath absoluteLeafRefTargetPath = null;
private boolean isReferencing = false;
LeafRefContextBuilder(final QName currentNodeQName, final ImmutableList<QName> currentNodePath,
- final EffectiveModelContext schemaContext) {
+ final EffectiveModelContext modelContext) {
this.currentNodeQName = requireNonNull(currentNodeQName);
this.currentNodePath = requireNonNull(currentNodePath);
- this.schemaContext = requireNonNull(schemaContext);
+ this.modelContext = requireNonNull(modelContext);
}
@NonNull LeafRefContext build() {
return currentNodeQName;
}
- EffectiveModelContext getSchemaContext() {
- return schemaContext;
+ EffectiveModelContext modelContext() {
+ return modelContext;
}
LeafRefPath getAbsoluteLeafRefTargetPath() {
Module getLeafRefContextModule() {
final QNameModule qnameModule = currentNodePath.isEmpty() ? currentNodeQName.getModule()
: currentNodePath.get(0).getModule();
- return schemaContext.findModule(qnameModule).orElse(null);
+ return modelContext.findModule(qnameModule).orElse(null);
}
void addReferencedByLeafRefCtx(final QName qname, final LeafRefContext leafRef) {
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.Composite;
import org.opendaylight.yangtools.yang.data.util.impl.context.ContainerContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
/**
* Semantic tree binding a {@link EffectiveModelContext} to a {@link NormalizedNode} tree. Since the layout of the
* schema and data has differences, the mapping is not trivial -- which is where this class comes in.
*/
-public final class DataSchemaContextTree extends AbstractEffectiveModelContextProvider {
+public final class DataSchemaContextTree {
public record NodeAndStack(@NonNull DataSchemaContext node, @NonNull SchemaInferenceStack stack) {
public NodeAndStack(final @NonNull DataSchemaContext node, final @NonNull SchemaInferenceStack stack) {
this.node = requireNonNull(node);
}
});
+ private final @NonNull EffectiveModelContext modelContext;
private final @NonNull ContainerContext root;
- private DataSchemaContextTree(final EffectiveModelContext ctx) {
- super(ctx);
- root = new ContainerContext(ctx);
+ private DataSchemaContextTree(final EffectiveModelContext modelContext) {
+ this.modelContext = requireNonNull(modelContext);
+ root = new ContainerContext(modelContext);
}
public static @NonNull DataSchemaContextTree from(final @NonNull EffectiveModelContext ctx) {
return TREES.getUnchecked(ctx);
}
+ /**
+ * Return the {@link EffectiveModelContext} used to derive this tree.
+ *
+ * @return the {@link EffectiveModelContext} used to derive this tree
+ */
+ public @NonNull EffectiveModelContext modelContext() {
+ return modelContext;
+ }
+
/**
* Find a child node as identified by an absolute {@link YangInstanceIdentifier}.
*
import static java.util.Objects.requireNonNull;
-import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Optional;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.MountPointLabel;
import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext;
import org.opendaylight.yangtools.yang.data.api.schema.MountPointContextFactory;
import org.opendaylight.yangtools.yang.data.util.AbstractMountPointContextFactory.MountPointDefinition;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
-final class ImmutableMountPointContext extends AbstractEffectiveModelContextProvider
+record ImmutableMountPointContext(
+ @NonNull EffectiveModelContext modelContext,
+ @NonNull ImmutableMap<MountPointLabel, MountPointDefinition> mountPoints,
+ @NonNull Function<MountPointDefinition, MountPointContextFactory> createFactory)
implements Immutable, MountPointContext {
- private final ImmutableMap<MountPointLabel, MountPointDefinition> mountPoints;
- private final Function<MountPointDefinition, MountPointContextFactory> createFactory;
+ ImmutableMountPointContext {
+ requireNonNull(modelContext);
+ requireNonNull(mountPoints);
+ requireNonNull(createFactory);
+ }
ImmutableMountPointContext(final EffectiveModelContext modelContext,
final Iterable<MountPointDefinition> mountPoints,
final Function<MountPointDefinition, MountPointContextFactory> createFactory) {
- super(modelContext);
- this.mountPoints = Maps.uniqueIndex(mountPoints, MountPointDefinition::label);
- this.createFactory = requireNonNull(createFactory);
+ this(modelContext, Maps.uniqueIndex(mountPoints, MountPointDefinition::label), createFactory);
}
@Override
public Optional<MountPointContextFactory> findMountPoint(final MountPointLabel label) {
- final MountPointDefinition def = mountPoints.get(requireNonNull(label));
+ final var def = mountPoints.get(requireNonNull(label));
return def == null ? Optional.empty() : Optional.of(createFactory.apply(def));
}
-
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return super.addToStringAttributes(helper).add("mountPoints", mountPoints);
- }
}
throw new IllegalArgumentException("Cannot instantiate on " + current);
}
} else {
- root = dataTree.getEffectiveModelContext();
+ root = dataTree.modelContext();
}
}
offset = 0;
final DataSchemaContextTree tree = codec.getDataContextTree();
- stack = SchemaInferenceStack.of(tree.getEffectiveModelContext());
+ stack = SchemaInferenceStack.of(tree.modelContext());
current = tree.getRoot();
}
import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* @param <T> Codec type
*/
-public abstract class AbstractCodecFactory<T extends TypeAwareCodec<?, ?, ?>>
- extends AbstractEffectiveModelContextProvider {
+public abstract class AbstractCodecFactory<T extends TypeAwareCodec<?, ?, ?>> {
private static final Logger LOG = LoggerFactory.getLogger(AbstractCodecFactory.class);
+ private final @NonNull EffectiveModelContext modelContext;
private final @NonNull CodecCache<T> cache;
- protected AbstractCodecFactory(final @NonNull EffectiveModelContext schemaContext,
+ protected AbstractCodecFactory(final @NonNull EffectiveModelContext modelContext,
final @NonNull CodecCache<T> cache) {
- super(schemaContext);
+ this.modelContext = requireNonNull(modelContext);
this.cache = requireNonNull(cache);
}
return cache.getComplex(schema, ret);
}
+ /**
+ * Return the {@link EffectiveModelContext} backing this factory.
+ *
+ * @return the {@link EffectiveModelContext} backing this factory
+ */
+ public final @NonNull EffectiveModelContext modelContext() {
+ return modelContext;
+ }
+
protected abstract T binaryCodec(BinaryTypeDefinition type);
protected abstract T booleanCodec(BooleanTypeDefinition type);
@NonNull QName expected, @NonNull InputStream stream) throws IOException, NormalizationException;
private void checkInference(final EffectiveStatementInference inference) {
- final var modelContext = inference.getEffectiveModelContext();
- final var local = getEffectiveModelContext();
- if (!local.equals(modelContext)) {
+ final var local = modelContext();
+ if (!local.equals(inference.modelContext())) {
throw new IllegalArgumentException("Mismatched inference, expecting model context " + local);
}
}
private static DataSchemaContextTree CONTEXT;
- private final SchemaInferenceStack stack = SchemaInferenceStack.of(CONTEXT.getEffectiveModelContext());
+ private final SchemaInferenceStack stack = SchemaInferenceStack.of(CONTEXT.modelContext());
@BeforeAll
static void init() {
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.api;
-
-import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * Interface for listeners interested in updates of an {@link EffectiveModelContext}.
- */
-@Beta
-@NonNullByDefault
-public interface EffectiveModelContextListener {
- /**
- * Invoked when the model context changes.
- *
- * @param newModelContext New model context being installed
- */
- void onModelContextUpdated(EffectiveModelContext newModelContext);
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.api;
-
-import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
-
-/**
- * A static provider of an {@link EffectiveModelContext}.
- *
- * @author Robert Varga
- */
-@Beta
-public interface EffectiveModelContextProvider {
- /**
- * Return the {@link EffectiveModelContext} attached to this object.
- *
- * @return An EffectiveModelContext instance.
- * @throws IllegalStateException if the context is not available.
- */
- @NonNull EffectiveModelContext getEffectiveModelContext();
-}
* derived from the line of reasoning.
*/
@Beta
-public interface EffectiveStatementInference extends EffectiveModelContextProvider, Immutable {
+public interface EffectiveStatementInference extends Immutable {
+ /**
+ * Return the {@link EffectiveModelContext} against which this inference is made.
+ *
+ * @return the {@link EffectiveModelContext} against which this inference is made
+ */
+ @NonNull EffectiveModelContext modelContext();
+
/**
* An {@code Unmodifiable} {@link List} of {@link EffectiveStatement}s, ordered in some meaningful way. Precise
* semantics of the statement order is clarified by individual {@link EffectiveStatementInference} specializations.
+++ /dev/null
-/*
- * Copyright (c) 2020 PANTHEON.tech s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.model.spi;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-
-/**
- * Utility superclass for classes returning a constant {@link EffectiveModelContext}.
- */
-@Beta
-@NonNullByDefault
-public abstract class AbstractEffectiveModelContextProvider implements EffectiveModelContextProvider {
- private final EffectiveModelContext modelContext;
-
- protected AbstractEffectiveModelContextProvider(final EffectiveModelContext modelContext) {
- this.modelContext = requireNonNull(modelContext);
- }
-
- @Override
- public final EffectiveModelContext getEffectiveModelContext() {
- return modelContext;
- }
-
- @Override
- public final String toString() {
- return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
- }
-
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return helper.add("modelContext", modelContext);
- }
-}
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
/**
- * A simple capture of an {@link AbstractEffectiveModelContextProvider} and {@link EffectiveStatementInference}s.
+ * A {@link EffectiveStatementInference}s with its attached {@link EffectiveModelContext}.
*
* @param <T> constituent {@link EffectiveStatement} type
*/
@Beta
public abstract class AbstractEffectiveStatementInference<T extends EffectiveStatement<?, ?>>
- extends AbstractEffectiveModelContextProvider implements EffectiveStatementInference {
+ implements EffectiveStatementInference {
+ private final @NonNull EffectiveModelContext modelContext;
+
protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext) {
- super(modelContext);
+ this.modelContext = requireNonNull(modelContext);
+ }
+
+ @Override
+ public final EffectiveModelContext modelContext() {
+ return modelContext;
}
@Override
public abstract List<T> statementPath();
+ @Override
+ public final String toString() {
+ return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
+ }
+
+ protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return helper.add("modelContext", modelContext);
+ }
+
/**
* A simple capture of an {@link AbstractEffectiveStatementInference} and a list of {@link EffectiveStatement}s. No
* further guarantees are made.
import org.slf4j.LoggerFactory;
/**
- * Default implementation of a a {@link SchemaTreeInference}. Guaranteed to be consistent with its
- * {@link #getEffectiveModelContext()}.
+ * Default implementation of a {@link SchemaTreeInference}. Guaranteed to be consistent with its
+ * {@link #modelContext()}.
*/
@Beta
@NonNullByDefault
void testUnsafeOf() {
final var path = ImmutableList.of(container);
final var inference = DefaultSchemaTreeInference.unsafeOf(modelContext, path);
- assertSame(modelContext, inference.getEffectiveModelContext());
+ assertSame(modelContext, inference.modelContext());
assertSame(path, inference.statementPath());
}
final var path = ImmutableList.of(container);
final var inference = DefaultSchemaTreeInference.verifiedOf(modelContext, path);
- assertSame(modelContext, inference.getEffectiveModelContext());
+ assertSame(modelContext, inference.modelContext());
assertSame(path, inference.statementPath());
}
*/
package org.opendaylight.yangtools.yang.model.util;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableBiMap;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.BiMapYangNamespaceContext;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.YangNamespaceContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
/**
* Utility {@link YangNamespaceContext} backed by a SchemaContext, resolving namespaces to their module names. This
* resolved by using the latest revision available.
*/
@Beta
-public final class ModuleNameNamespaceContext extends AbstractEffectiveModelContextProvider
- implements YangNamespaceContext {
+public final class ModuleNameNamespaceContext implements YangNamespaceContext {
@java.io.Serial
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
+
+ private final @NonNull EffectiveModelContext modelContext;
- @SuppressFBWarnings(value = "SE_NO_SUITABLE_CONSTRUCTOR", justification = "Handled through writeReplace()")
- public ModuleNameNamespaceContext(final EffectiveModelContext schemaContext) {
- super(schemaContext);
+ public ModuleNameNamespaceContext(final EffectiveModelContext modelContext) {
+ this.modelContext = requireNonNull(modelContext);
}
/**
*/
public BiMapYangNamespaceContext toBiMap() {
final var builder = ImmutableBiMap.<String, QNameModule>builder();
- for (var module : getEffectiveModelContext().getModuleStatements().values()) {
+ for (var module : modelContext.getModuleStatements().values()) {
final var name = module.argument().getLocalName();
builder.put(name, findNamespaceForPrefix(name).orElseThrow());
}
@Override
public QNameModule namespaceForPrefix(final String prefix) {
- final var modules = getEffectiveModelContext().findModuleStatements(prefix).iterator();
+ final var modules = modelContext.findModuleStatements(prefix).iterator();
return modules.hasNext() ? modules.next().localQNameModule() : null;
}
@Override
public String prefixForNamespace(final QNameModule namespace) {
- return getEffectiveModelContext().findModuleStatement(namespace)
+ return modelContext.findModuleStatement(namespace)
.map(module -> module.argument().getLocalName())
.orElse(null);
}
private Object writeReplace() {
return toBiMap();
}
+
+ @java.io.Serial
+ private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+ throwNSE();
+ }
+
+ @java.io.Serial
+ private void readObjectNoData() throws ObjectStreamException {
+ throwNSE();
+ }
+
+ @java.io.Serial
+ private void writeObject(final ObjectOutputStream stream) throws IOException {
+ throwNSE();
+ }
+
+ private static void throwNSE() throws NotSerializableException {
+ throw new NotSerializableException(ModuleNameNamespaceContext.class.getName());
+ }
}
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.common.YangDataName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
* This class is designed for single-threaded uses and does not make any guarantees around concurrent access.
*/
@Beta
-public final class SchemaInferenceStack implements Mutable, EffectiveModelContextProvider, LeafrefResolver {
+public final class SchemaInferenceStack implements Mutable, LeafrefResolver {
/**
* Semantic binding of {@link EffectiveStatementInference} produced by {@link SchemaInferenceStack}. Sequence of
* {@link #statementPath()} is implementation-specific.
* @return A new stack
*/
public @NonNull SchemaInferenceStack toSchemaInferenceStack() {
- return new SchemaInferenceStack(getEffectiveModelContext(), deque, currentModule, groupingDepth, clean);
+ return new SchemaInferenceStack(modelContext(), deque, currentModule, groupingDepth, clean);
}
}
}
}
- private final @NonNull EffectiveModelContext effectiveModel;
+ private final @NonNull EffectiveModelContext modelContext;
private final ArrayDeque<EffectiveStatement<?, ?>> deque;
private @Nullable ModuleEffectiveStatement currentModule;
private SchemaInferenceStack(final EffectiveModelContext effectiveModel, final int expectedSize) {
deque = new ArrayDeque<>(expectedSize);
- this.effectiveModel = requireNonNull(effectiveModel);
+ modelContext = requireNonNull(effectiveModel);
clean = true;
}
private SchemaInferenceStack(final SchemaInferenceStack source) {
deque = source.deque.clone();
- effectiveModel = source.effectiveModel;
+ modelContext = source.modelContext;
currentModule = source.currentModule;
groupingDepth = source.groupingDepth;
clean = source.clean;
}
- private SchemaInferenceStack(final EffectiveModelContext effectiveModel,
+ private SchemaInferenceStack(final EffectiveModelContext modelContext,
final ArrayDeque<EffectiveStatement<?, ?>> deque, final ModuleEffectiveStatement currentModule,
final int groupingDepth, final boolean clean) {
- this.effectiveModel = requireNonNull(effectiveModel);
+ this.modelContext = requireNonNull(modelContext);
this.deque = deque.clone();
this.currentModule = currentModule;
this.groupingDepth = groupingDepth;
}
private SchemaInferenceStack(final EffectiveModelContext effectiveModel) {
- this.effectiveModel = requireNonNull(effectiveModel);
+ modelContext = requireNonNull(effectiveModel);
deque = new ArrayDeque<>();
clean = true;
}
*/
public static @NonNull SchemaInferenceStack ofInference(final EffectiveStatementInference inference) {
if (inference.statementPath().isEmpty()) {
- return new SchemaInferenceStack(inference.getEffectiveModelContext());
+ return new SchemaInferenceStack(inference.modelContext());
} else if (inference instanceof SchemaTreeInference sti) {
return ofInference(sti);
} else if (inference instanceof Inference inf) {
*/
public static @NonNull SchemaInferenceStack ofInference(final SchemaTreeInference inference) {
return inference instanceof DefaultSchemaTreeInference dsti ? ofInference(dsti)
- : of(inference.getEffectiveModelContext(), inference.toSchemaNodeIdentifier());
+ : of(inference.modelContext(), inference.toSchemaNodeIdentifier());
}
/**
private static @NonNull SchemaInferenceStack ofTrusted(final DefaultSchemaTreeInference inference) {
final var path = inference.statementPath();
- final var ret = new SchemaInferenceStack(inference.getEffectiveModelContext(), path.size());
+ final var ret = new SchemaInferenceStack(inference.modelContext(), path.size());
ret.currentModule = ret.getModule(path.get(0).argument());
ret.deque.addAll(path);
return ret;
@VisibleForTesting
static @NonNull SchemaInferenceStack ofUntrusted(final DefaultSchemaTreeInference inference) {
- final var ret = of(inference.getEffectiveModelContext(), inference.toSchemaNodeIdentifier());
+ final var ret = of(inference.modelContext(), inference.toSchemaNodeIdentifier());
if (!Iterables.elementsEqual(ret.deque, inference.statementPath())) {
throw new IllegalArgumentException("Provided " + inference + " is not consistent with resolved path "
+ ret.toSchemaTreeInference());
return ret;
}
- @Override
- public EffectiveModelContext getEffectiveModelContext() {
- return effectiveModel;
+ /**
+ * Return the {@link EffectiveModelContext} this stack operates on.
+ *
+ * @return the {@link EffectiveModelContext} this stack operates on
+ */
+ public @NonNull EffectiveModelContext modelContext() {
+ return modelContext;
}
/**
final var checkedName = requireNonNull(name);
final var namespace = name.module();
- final var module = effectiveModel.getModuleStatements().get(namespace);
+ final var module = modelContext.getModuleStatements().get(namespace);
if (module == null) {
throw new IllegalArgumentException("Module for " + namespace + " not found");
}
* @return An {@link Inference}
*/
public @NonNull Inference toInference() {
- return new Inference(effectiveModel, deque.clone(), currentModule, groupingDepth, clean);
+ return new Inference(modelContext, deque.clone(), currentModule, groupingDepth, clean);
}
/**
*/
public @NonNull SchemaTreeInference toSchemaTreeInference() {
checkInInstantiatedContext();
- return DefaultSchemaTreeInference.unsafeOf(getEffectiveModelContext(), reconstructDeque().stream()
+ return DefaultSchemaTreeInference.unsafeOf(modelContext, reconstructDeque().stream()
.map(stmt -> (SchemaTreeEffectiveStatement<?>) stmt)
.collect(ImmutableList.toImmutableList()));
}
}
private @NonNull ModuleEffectiveStatement getModule(final @NonNull QName nodeIdentifier) {
- final var module = effectiveModel.getModuleStatements().get(nodeIdentifier.getModule());
+ final var module = modelContext.getModuleStatements().get(nodeIdentifier.getModule());
if (module == null) {
throw new IllegalArgumentException("Module for " + nodeIdentifier + " not found");
}
private SchemaInferenceStack reconstructSchemaInferenceStack() {
// Let's walk all statements and decipher them into a temporary stack
- final var tmp = new SchemaInferenceStack(effectiveModel, deque.size());
+ final var tmp = new SchemaInferenceStack(modelContext, deque.size());
for (var stmt : deque) {
// Order of checks is significant
if (stmt instanceof DataTreeEffectiveStatement<?> dataTree) {