/** * Returns the schema context of the YANG files present in a directory. * * @param di directory path * @return YANG schema context * @throws SvcLogicException when YANG file reading fails */ static SchemaContext getSchemaCtxFromDir(String di) throws SvcLogicException { Path d = Paths.get(di); File dir = d.toFile(); List<File> yangFiles = new LinkedList<>(); getYangFiles(dir, yangFiles); final Collection<YangStatementStreamSource> sources = new ArrayList<>(yangFiles.size()); for (File file : yangFiles) { try { sources.add(create(forFile(file))); } catch (IOException | YangSyntaxErrorException e) { throw new SvcLogicException(YANG_FILE_ERR + e.getMessage(), e); } } final CrossSourceStatementReactor.BuildAction reactor = defaultReactor() .newBuild(DEFAULT_MODE).addSources(sources); try { return reactor.buildEffective(); } catch (ReactorException e) { throw new SvcLogicException(YANG_FILE_ERR + e.getMessage(), e); } }
/** * Add library sources. Only library sources required by main sources are present in resulting SchemaContext. * Any other library sources are ignored and this also applies to error reporting. * * <p> * Library sources are not supported in semantic version mode currently. * * @param libSources yang sources which should be added into library sources * @return This build action, for fluent use. */ public @NonNull BuildAction addLibSources(final StatementStreamSource... libSources) { addLibSources(Arrays.asList(libSources)); return this; }
/** * Start a new reactor build using the specified statement parser mode and enabling all features and deviations. * * @param statementParserMode Parser mode to use * @return A new {@link BuildAction}. * @throws NullPointerException if statementParserMode is null */ public @NonNull BuildAction newBuild(final StatementParserMode statementParserMode) { return new BuildAction(supportedTerminology, supportedValidation, requireNonNull(statementParserMode)); }
parserRuleCtx.getClass(), e.getKey()); reactor.addSource(YangStatementStreamSource.create(e.getKey(), (StatementContext) parserRuleCtx, ast.getSymbolicName().orElse(null))); schemaContext = reactor.buildEffective(); } catch (final ReactorException ex) { throw new SchemaResolutionException("Failed to resolve required models", ex.getSourceIdentifier(), ex);
parserRuleCtx.getClass(), e.getKey()); reactor.addSource(YangStatementStreamSource.create(e.getKey(), (StatementContext) parserRuleCtx, ast.getSymbolicName().orElse(null))); schemaContext = reactor.buildEffective(); } catch (final ReactorException ex) { throw new SchemaResolutionException("Failed to resolve required models", ex.getSourceIdentifier(), ex);
@Override public Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException { final List<EffectiveStatement<?, ?>> effectiveStatements; try { effectiveStatements = buildAction.buildEffective().getRootEffectiveStatements(); } catch (ReactorException e) { throw decodeReactorException(e); } return effectiveStatements.stream() .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast) .collect(toImmutableMap(ModuleEffectiveStatement::localQNameModule, identity())); }
@Override public List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException { try { return buildAction.build().getRootStatements(); } catch (ReactorException e) { throw decodeReactorException(e); } }
@Override public YangParser addLibSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException { buildAction.addLibSources(sourceToStatementStream(source)); return null; }
@Override public SchemaContext buildSchemaContext() throws YangParserException { try { return buildAction.buildEffective(); } catch (ReactorException e) { throw decodeReactorException(e); } }
@Override public YangParser setSupportedFeatures(final Set<QName> supportedFeatures) { buildAction.setSupportedFeatures(supportedFeatures); return this; }
/** * Add main sources. All main sources are present in resulting SchemaContext. * * @param sources * which should be added into main sources * @return This build action, for fluent use. */ public @NonNull BuildAction addSources(final StatementStreamSource... sources) { addSources(Arrays.asList(sources)); return this; }
@Override public SchemaContext buildSchemaContext() throws YangParserException { try { return buildAction.buildEffective(); } catch (ReactorException e) { throw decodeReactorException(e); } }
@Override public YangParser setSupportedFeatures(final Set<QName> supportedFeatures) { buildAction.setSupportedFeatures(supportedFeatures); return this; }
@Override public YangParser setModulesWithSupportedDeviations( final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) { buildAction.setModulesWithSupportedDeviations(modulesDeviatedByModules); return this; }
@Override public Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException { final List<EffectiveStatement<?, ?>> effectiveStatements; try { effectiveStatements = buildAction.buildEffective().getRootEffectiveStatements(); } catch (ReactorException e) { throw decodeReactorException(e); } return effectiveStatements.stream() .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast) .collect(toImmutableMap(ModuleEffectiveStatement::localQNameModule, identity())); }
@Override public List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException { try { return buildAction.build().getRootStatements(); } catch (ReactorException e) { throw decodeReactorException(e); } }
@Override public YangParser setModulesWithSupportedDeviations( final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) { buildAction.setModulesWithSupportedDeviations(modulesDeviatedByModules); return this; }
@Override public YangParser addSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException { buildAction.addSources(sourceToStatementStream(source)); return null; }
@Override public YangParser addSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException { buildAction.addSources(sourceToStatementStream(source)); return null; }
@Override public YangParser addLibSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException { buildAction.addLibSources(sourceToStatementStream(source)); return null; }