Search in sources :

Example 1 with StatementParserMode

use of org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode in project yangtools by opendaylight.

the class AssembleSources method apply.

@Override
public FluentFuture<EffectiveModelContext> apply(final List<IRSchemaSource> sources) throws SchemaResolutionException, ReactorException {
    final Map<SourceIdentifier, IRSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
    final Map<SourceIdentifier, YangModelDependencyInfo> deps = Maps.transformValues(srcs, YangModelDependencyInfo::forIR);
    LOG.debug("Resolving dependency reactor {}", deps);
    final StatementParserMode statementParserMode = config.getStatementParserMode();
    final DependencyResolver res = 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());
        throw new SchemaResolutionException("Failed to resolve required models", res.getResolvedSources(), res.getUnsatisfiedImports());
    }
    final YangParser parser = parserFactory.createParser(res.parserConfig());
    config.getSupportedFeatures().ifPresent(parser::setSupportedFeatures);
    config.getModulesDeviatedByModules().ifPresent(parser::setModulesWithSupportedDeviations);
    for (final Entry<SourceIdentifier, IRSchemaSource> entry : srcs.entrySet()) {
        try {
            parser.addSource(entry.getValue());
        } catch (YangSyntaxErrorException | IOException e) {
            throw new SchemaResolutionException("Failed to add source " + entry.getKey(), e);
        }
    }
    final EffectiveModelContext schemaContext;
    try {
        schemaContext = parser.buildEffectiveModel();
    } catch (final YangParserException e) {
        throw new SchemaResolutionException("Failed to resolve required models", e);
    }
    return immediateFluentFuture(schemaContext);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) SemVerSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier) YangParser(org.opendaylight.yangtools.yang.parser.api.YangParser) IOException(java.io.IOException) YangParserException(org.opendaylight.yangtools.yang.parser.api.YangParserException) YangModelDependencyInfo(org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo) SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) YangSyntaxErrorException(org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException) StatementParserMode(org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

IOException (java.io.IOException)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 SchemaResolutionException (org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException)1 SemVerSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 StatementParserMode (org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode)1 YangParser (org.opendaylight.yangtools.yang.parser.api.YangParser)1 YangParserException (org.opendaylight.yangtools.yang.parser.api.YangParserException)1 YangSyntaxErrorException (org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException)1 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)1 YangModelDependencyInfo (org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo)1