import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import org.antlr.v4.runtime.ParserRuleContext;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
import org.slf4j.LoggerFactory;
final class SharedSchemaContextFactory implements SchemaContextFactory {
- private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper.create("resolve sources", SchemaResolutionException.class);
+ private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper
+ .create("resolve sources", SchemaResolutionException.class);
private static final Logger LOG = LoggerFactory.getLogger(SharedSchemaContextFactory.class);
- private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues().build();
- private final Cache<Collection<SourceIdentifier>, SchemaContext> semVerCache = CacheBuilder.newBuilder().weakValues().build();
+ private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues()
+ .build();
+ private final Cache<Collection<SourceIdentifier>, SchemaContext> semVerCache = CacheBuilder.newBuilder()
+ .weakValues().build();
private final SharedSchemaRepository repository;
// FIXME: ignored right now
private final SchemaSourceFilter filter;
- // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository (final implementation)
+ // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository
+ // (final implementation)
public SharedSchemaContextFactory(final SharedSchemaRepository repository, final SchemaSourceFilter filter) {
this.repository = Preconditions.checkNotNull(repository);
this.filter = Preconditions.checkNotNull(filter);
final Set<QName> supportedFeatures) {
return createSchemaContext(requiredSources,
statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache,
- new AssembleSources(supportedFeatures, statementParserMode));
+ new AssembleSources(Optional.ofNullable(supportedFeatures), statementParserMode));
}
private ListenableFuture<ASTSchemaSource> requestSource(final SourceIdentifier identifier) {
return ImmutableList.copyOf(uniqueSourceIdentifiers);
}
- private static final class SourceIdMismatchDetector implements Function<List<ASTSchemaSource>, List<ASTSchemaSource>> {
+ private static final class SourceIdMismatchDetector implements Function<List<ASTSchemaSource>,
+ List<ASTSchemaSource>> {
private final List<SourceIdentifier> sourceIdentifiers;
public SourceIdMismatchDetector(final List<SourceIdentifier> sourceIdentifiers) {
final SourceIdentifier realSId = astSchemaSource.getIdentifier();
if (!expectedSId.equals(realSId)) {
- LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. Using actual id",
- expectedSId.getName(), expectedSId, realSId);
+ LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. "
+ + "Using actual id", expectedSId.getName(), expectedSId, realSId);
}
if (filtered.containsKey(realSId)) {
private static final class AssembleSources implements AsyncFunction<List<ASTSchemaSource>, SchemaContext> {
- private final Set<QName> supportedFeatures;
+ private final Optional<Set<QName>> supportedFeatures;
private final StatementParserMode statementParserMode;
private final Function<ASTSchemaSource, SourceIdentifier> getIdentifier;
- private AssembleSources(final Set<QName> supportedFeatures,
+ private AssembleSources(final Optional<Set<QName>> supportedFeatures,
final StatementParserMode statementParserMode) {
this.supportedFeatures = supportedFeatures;
this.statementParserMode = Preconditions.checkNotNull(statementParserMode);
}
@Override
- public ListenableFuture<SchemaContext> apply(@Nonnull final List<ASTSchemaSource> sources) throws SchemaResolutionException,
- SourceException, ReactorException {
+ public ListenableFuture<SchemaContext> apply(@Nonnull final List<ASTSchemaSource> sources)
+ throws SchemaResolutionException, ReactorException {
final Map<SourceIdentifier, ASTSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
final Map<SourceIdentifier, YangModelDependencyInfo> deps =
Maps.transformValues(srcs, ASTSchemaSource::getDependencyInformation);
LOG.debug("Resolving dependency reactor {}", deps);
- final DependencyResolver res = this.statementParserMode == StatementParserMode.SEMVER_MODE ? SemVerDependencyResolver
- .create(deps) : RevisionDependencyResolver.create(deps);
+ final DependencyResolver res = this.statementParserMode == StatementParserMode.SEMVER_MODE
+ ? SemVerDependencyResolver.create(deps) : RevisionDependencyResolver.create(deps);
if (!res.getUnresolvedSources().isEmpty()) {
- LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(), res.getUnsatisfiedImports());
+ LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(),
+ res.getUnsatisfiedImports());
throw new SchemaResolutionException("Failed to resolve required models",
res.getResolvedSources(), res.getUnsatisfiedImports());
}
final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource::getAST);
- final CrossSourceStatementReactor.BuildAction reactor =
- YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, supportedFeatures);
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
+ statementParserMode, supportedFeatures);
for (final Entry<SourceIdentifier, ParserRuleContext> e : asts.entrySet()) {
final ParserRuleContext parserRuleCtx = e.getValue();
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
*
* @param supportedFeatures The set of supported features in the final SchemaContext
* @return A new {@link BuildAction}.
+ *
+ * @deprecated Use {@link #newBuild(Optional)} instead.
*/
+ @Deprecated
public BuildAction newBuild(final Set<QName> supportedFeatures) {
return new BuildAction(warnOnNull(supportedFeatures), StatementParserMode.DEFAULT_MODE);
}
+ /**
+ * Start a new reactor build using default statement parser mode and only specified features.
+ *
+ * @param supportedFeatures The set of supported features in the final SchemaContext, if present.
+ * @return A new {@link BuildAction}.
+ */
+ public BuildAction newBuild(final Optional<Set<QName>> supportedFeatures) {
+ return new BuildAction(supportedFeatures.orElse(null), StatementParserMode.DEFAULT_MODE);
+ }
+
/**
* Start a new reactor build using specified statement parser mode and enabling all features.
*
/**
* Start a new reactor build using default statement parser mode and only specified features.
*
+ * @param statementParserMode Parser mode to use
* @param supportedFeatures The set of supported features in the final SchemaContext
* @return A new {@link BuildAction}.
* @throws NullPointerException if statementParserMode is null
+ *
+ * @deprecated Use {@link #newBuild(StatementParserMode, Optional)} instead.
*/
+ @Deprecated
public BuildAction newBuild(final StatementParserMode statementParserMode,
final Set<QName> supportedFeatures) {
return new BuildAction(warnOnNull(supportedFeatures), statementParserMode);
}
+ /**
+ * Start a new reactor build using default statement parser mode and only specified features.
+ *
+ * @param statementParserMode Parser mode to use
+ * @param supportedFeatures The set of supported features in the final SchemaContext, or absent if all features
+ * encountered should be supported.
+ * @return A new {@link BuildAction}.
+ * @throws NullPointerException if statementParserMode is null
+ */
+ public BuildAction newBuild(final StatementParserMode statementParserMode,
+ final Optional<Set<QName>> supportedFeatures) {
+ return new BuildAction(supportedFeatures.orElse(null), statementParserMode);
+ }
+
private static <T> T warnOnNull(final T obj) {
if (obj == null) {
LOG.info("Set of supported features has not been provided, so all features are supported by default.");