import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.RootStmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Root statement class for a YANG source. All statements defined in that YANG source are mapped underneath an instance
*/
public final class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
extends AbstractResumedStatement<A, D, E> implements RootStmtContext.Mutable<A, D, E> {
-
public static final YangVersion DEFAULT_VERSION = YangVersion.VERSION_1;
+ private static final Logger LOG = LoggerFactory.getLogger(RootStatementContext.class);
+ // These namespaces are well-known and not needed after the root is cleaned up
+ private static final Map<Class<?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
+ GroupingNamespace.class, new SweptNamespace(GroupingNamespace.class),
+ SchemaTreeNamespace.class, new SweptNamespace(SchemaTreeNamespace.class),
+ TypeNamespace.class, new SweptNamespace(TypeNamespace.class));
+
private final @NonNull SourceSpecificContext sourceContext;
private final A argument;
final StatementSourceReference ref, final String rawArgument) {
super(def, ref, rawArgument);
this.sourceContext = requireNonNull(sourceContext);
- this.argument = def.parseArgumentValue(this, rawStatementArgument());
+ this.argument = def.parseArgumentValue(this, rawArgument());
}
RootStatementContext(final SourceSpecificContext sourceContext, final StatementDefinitionContext<A, D, E> def,
}
@Override
- public A getStatementArgument() {
+ public A argument() {
return argument;
}
@Override
@Deprecated
- Optional<SchemaPath> schemaPath() {
+ public Optional<SchemaPath> schemaPath() {
return Optional.of(SchemaPath.ROOT);
}
@Override
- public boolean isConfiguration() {
- return true;
+ public EffectiveConfig effectiveConfig() {
+ return EffectiveConfig.UNDETERMINED;
}
@Override
void setRootVersionImpl(final YangVersion version) {
checkArgument(sourceContext.globalContext().getSupportedVersions().contains(version),
- "Unsupported yang version %s in %s", version, getStatementSourceReference());
+ "Unsupported yang version %s in %s", version, sourceReference());
checkState(this.rootVersion == null, "Version of root %s has been already set to %s", argument,
this.rootVersion);
this.rootVersion = requireNonNull(version);
StatementContextBase<A, D, E> reparent(final StatementContextBase<?, ?, ?> newParent) {
throw new UnsupportedOperationException("Root statement cannot be reparented to" + newParent);
}
+
+ @Override
+ void sweepNamespaces() {
+ LOG.trace("Sweeping root {}", this);
+ sweepNamespaces(SWEPT_NAMESPACES);
+ }
}