use of org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache in project netconf by opendaylight.
the class NetconfDeviceSimulator method parseSchemasToModuleCapabilities.
private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
final Set<SourceIdentifier> loadedSources = new HashSet<>();
consumer.registerSchemaSourceListener(TextToIRTransformer.create(consumer, consumer));
consumer.registerSchemaSourceListener(new SchemaSourceListener() {
@Override
public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
}
@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
for (final PotentialSchemaSource<?> potentialSchemaSource : potentialSchemaSources) {
loadedSources.add(potentialSchemaSource.getSourceIdentifier());
}
}
@Override
public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
}
});
if (configuration.getSchemasDir() != null) {
LOG.info("Loading models from directory.");
final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
consumer.registerSchemaSourceListener(cache);
} else if (configuration.getModels() != null) {
LOG.info("Loading models from classpath.");
final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getModels());
consumer.registerSchemaSourceListener(cache);
} else {
LOG.info("Custom module loading skipped.");
}
configuration.getDefaultYangResources().forEach(r -> {
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(), Revision.ofNullable(r.getRevision()));
registerSource(consumer, r.getResourcePath(), sourceIdentifier);
});
try {
// necessary for creating mdsal data stores and operations
this.schemaContext = consumer.createEffectiveModelContextFactory().createEffectiveModelContext(loadedSources).get();
} catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context. " + "Please read stack trace and check YANG files in schema directory.", e);
}
final Set<Capability> capabilities = new HashSet<>();
for (final Module module : schemaContext.getModules()) {
for (final Submodule subModule : module.getSubmodules()) {
addModuleCapability(consumer, capabilities, subModule);
}
addModuleCapability(consumer, capabilities, module);
}
return capabilities;
}
Aggregations