use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project mdsal by opendaylight.
the class ModuleInfoSnapshotResolver method updateSnapshot.
@Holding("this")
@NonNull
private ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
// Alright, now let's find out which sources got captured
final Set<SourceIdentifier> sources = new HashSet<>();
for (Entry<QNameModule, ModuleEffectiveStatement> entry : effectiveModel.getModuleStatements().entrySet()) {
final Optional<Revision> revision = entry.getKey().getRevision();
final ModuleEffectiveStatement module = entry.getValue();
sources.add(RevisionSourceIdentifier.create(module.argument().getLocalName(), revision));
module.streamEffectiveSubstatements(SubmoduleEffectiveStatement.class).map(submodule -> RevisionSourceIdentifier.create(submodule.argument().getLocalName(), revision)).forEach(sources::add);
}
final Map<SourceIdentifier, YangModuleInfo> moduleInfos = new HashMap<>();
final Map<String, ClassLoader> classLoaders = new HashMap<>();
for (SourceIdentifier source : sources) {
final List<RegisteredModuleInfo> regs = sourceToInfoReg.get(source);
checkState(!regs.isEmpty(), "No registration for %s", source);
final RegisteredModuleInfo reg = regs.get(0);
final YangModuleInfo info = reg.info;
moduleInfos.put(source, info);
final Class<?> infoClass = info.getClass();
classLoaders.put(BindingReflections.getModelRootPackageName(infoClass.getPackage()), infoClass.getClassLoader());
}
final ModuleInfoSnapshot next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
currentSnapshot = next;
return next;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project mdsal by opendaylight.
the class DefaultBindingGenerator method generateFor.
/**
* Resolves generated types from {@code context} schema nodes only for modules specified in {@code modules}.
* Generated types are created for modules, groupings, types, containers, lists, choices, augments, rpcs,
* notification, identities and actions.
*
* @param context schema context which contains data about all schema nodes saved in modules
* @param modules set of modules for which schema nodes should be generated types
* @return list of types (usually a {@link GeneratedType} or an {@link GeneratedTransferObject}), which:
* <ul>
* <li>are generated from {@code context} schema nodes and</li>
* <li>are also part of some of the module in {@code modules} set.</li>
* </ul>
* @throws NullPointerException if any argument is {@code null}, or if {@code modules} contains a {@code null}
* element
*/
@VisibleForTesting
@NonNull
static List<GeneratedType> generateFor(final EffectiveModelContext context, final Collection<? extends Module> modules) {
final Set<ModuleEffectiveStatement> filter = modules.stream().map(Module::asEffectiveStatement).collect(Collectors.toUnmodifiableSet());
final List<GeneratedType> result = new ArrayList<>();
for (ModuleGenerator gen : new GeneratorReactor(context).execute(TypeBuilderFactory.codegen()).values()) {
if (filter.contains(gen.statement())) {
addTypes(result, gen);
}
}
return result;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class ModuleNameNamespaceContext method toBiMap.
/**
* Convert this object to an equivalent {@link BiMapYangNamespaceContext}.
*
* @return A BiMapYangNamespaceContext.
*/
public BiMapYangNamespaceContext toBiMap() {
final Builder<String, QNameModule> builder = ImmutableBiMap.builder();
for (ModuleEffectiveStatement module : getEffectiveModelContext().getModuleStatements().values()) {
final String name = module.argument().getLocalName();
builder.put(name, findNamespaceForPrefix(name).get());
}
return new BiMapYangNamespaceContext(builder.build());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class SchemaInferenceStack method pushFirstTypedef.
@NonNull
private TypedefEffectiveStatement pushFirstTypedef(@NonNull final QName nodeIdentifier) {
final ModuleEffectiveStatement module = getModule(nodeIdentifier);
final TypedefEffectiveStatement ret = pushTypedef(module, nodeIdentifier);
currentModule = module;
return ret;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement in project yangtools by opendaylight.
the class SchemaInferenceStack method getModule.
@NonNull
private ModuleEffectiveStatement getModule(@NonNull final QName nodeIdentifier) {
final ModuleEffectiveStatement module = effectiveModel.getModuleStatements().get(nodeIdentifier.getModule());
checkArgument(module != null, "Module for %s not found", nodeIdentifier);
return module;
}
Aggregations