gpt4 book ai didi

org.opendaylight.yangtools.yang.binding.YangModuleInfo类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 20:00:49 30 4
gpt4 key购买 nike

本文整理了Java中org.opendaylight.yangtools.yang.binding.YangModuleInfo类的一些代码示例,展示了YangModuleInfo类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YangModuleInfo类的具体详情如下:
包路径:org.opendaylight.yangtools.yang.binding.YangModuleInfo
类名称:YangModuleInfo

YangModuleInfo介绍

[英]Information and model capture for Binding V1. Instances of this class identify a packaged model and allow access to its YANG text. They also contain references to YangModuleInfo instances as observed at code generation time.

The purpose of this class is to ensure package resolution order in OSGi environments, as implementations of this interface are required to be co-located with generated code. When this module relies on some imports, that dependency is expressed across jars via an implementation requirement to reference YangModuleInfos.
[中]绑定V1的信息和模型捕获。此类的实例标识打包的模型,并允许访问其文本。它们还包含代码生成时观察到的对YangModuleInfo实例的引用。
此类的目的是确保OSGi环境中的包解析顺序,因为该接口的实现需要与生成的代码位于同一位置。当该模块依赖于某些导入时,该依赖关系通过引用模块信息的实现需求跨JAR表达。

代码示例

代码示例来源:origin: org.opendaylight.mdsal/yang-binding

@Override
  public String toString() {
    return MoreObjects.toStringHelper(this).add("name", getName()).toString();
  }
};

代码示例来源:origin: io.lighty.core/lighty-common

private static boolean hasDependency(final YangModuleInfo superiorModel, final YangModuleInfo dependency) {
  for (YangModuleInfo moduleInfo:  superiorModel.getImportedModules()) {
    if (moduleInfo.getName().equals(dependency.getName())) {
      return true;
    }
    hasDependency(moduleInfo, dependency);
  }
  return false;
}

代码示例来源:origin: org.opendaylight.yangtools/yang-binding

/**
 * Given a {@link YangModuleInfo}, create a QName representing it. The QName
 * is formed by reusing the module's namespace and revision using the
 * module's name as the QName's local name.
 *
 * @param moduleInfo
 *            module information
 * @return QName representing the module
 */
public static QName getModuleQName(final YangModuleInfo moduleInfo) {
  checkArgument(moduleInfo != null, "moduleInfo must not be null.");
  return QName.create(moduleInfo.getNamespace(), moduleInfo.getRevision(), moduleInfo.getName());
}

代码示例来源:origin: org.opendaylight.yangtools/binding-generator-impl

private SourceIdentifier sourceIdentifierFrom(final YangModuleInfo moduleInfo) {
  return SourceIdentifier.create(moduleInfo.getName(), Optional.of(moduleInfo.getRevision()));
}

代码示例来源:origin: org.opendaylight.yangtools/yang-binding

private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
    final Builder<YangModuleInfo> moduleInfoSet) {
  moduleInfoSet.add(moduleInfo);
  for (YangModuleInfo dependency : moduleInfo.getImportedModules()) {
    collectYangModuleInfo(dependency, moduleInfoSet);
  }
}

代码示例来源:origin: org.opendaylight.yangtools/yang-binding

public static final QNameModule getQNameModule(final YangModuleInfo modInfo) {
  return QNameModule.create(URI.create(modInfo.getNamespace()), QName.parseRevision(modInfo.getRevision()));
}

代码示例来源:origin: org.opendaylight.mdsal/yang-binding

/**
   * Return a {@link CharSource} accessing the YANG text of the module.
   *
   * @return A CharSource.
   */
  default CharSource getYangTextCharSource() {
    return getYangTextByteSource().asCharSource(StandardCharsets.UTF_8);
  }
}

代码示例来源:origin: org.opendaylight.yangtools/restconf-client-impl

public BindingToRestRpc(final Class<?> proxiedInterface,final BindingNormalizedNodeCodecRegistry mappingService2,final RestconfClientImpl client,final SchemaContext schemaContext) throws Exception {
  this.mappingService = mappingService2;
  this.client  = client;
  this.schcemaContext = schemaContext;
  YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(proxiedInterface);
  this.module = schemaContext.findModuleByName(moduleInfo.getName(),org.opendaylight.yangtools.yang.common.QName.parseRevision(moduleInfo.getRevision()));
}

代码示例来源:origin: org.opendaylight.yangtools/binding-generator-impl

private boolean resolveModuleInfo(final YangModuleInfo moduleInfo) {
  SourceIdentifier identifier = sourceIdentifierFrom(moduleInfo);
  YangModuleInfo previous = sourceIdentifierToModuleInfo.putIfAbsent(identifier, moduleInfo);
  ClassLoader moduleClassLoader = moduleInfo.getClass().getClassLoader();
  if (previous == null) {
    String modulePackageName = moduleInfo.getClass().getPackage().getName();
    packageNameToClassLoader.putIfAbsent(modulePackageName, new WeakReference<ClassLoader>(moduleClassLoader));
    for (YangModuleInfo importedInfo : moduleInfo.getImportedModules()) {
      resolveModuleInfo(importedInfo);
    }
  } else {
    return false;
  }
  return true;
}

代码示例来源:origin: org.opendaylight.yangtools/binding-generator-impl

private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpc(final SchemaContext ctx,
    final Class<? extends DataObject> targetType) {
  final YangModuleInfo moduleInfo;
  try {
    moduleInfo = BindingReflections.getModuleInfo(targetType);
  } catch (Exception e) {
    throw new IllegalArgumentException(
        String.format("Failed to load module information for class %s", targetType), e);
  }
  for(RpcDefinition rpc : ctx.getOperations()) {
    String rpcNamespace = rpc.getQName().getNamespace().toString();
    String rpcRevision = rpc.getQName().getFormattedRevision();
    if(moduleInfo.getNamespace().equals(rpcNamespace) && moduleInfo.getRevision().equals(rpcRevision)) {
      Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName());
      if(potential.isPresent()) {
        return potential;
      }
    }
  }
  return Optional.absent();
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding-generator-impl

private static YangTextSchemaSource toYangTextSource(final SourceIdentifier identifier,
    final YangModuleInfo moduleInfo) {
  return YangTextSchemaSource.delegateForByteSource(identifier, moduleInfo.getYangTextByteSource());
}

代码示例来源:origin: io.fd.hc2vpp.docs/docs-core

ModelTypeIndex() throws IOException {
  namespaceToModuleIndex = collectAllModules(this.getClass().getClassLoader())
      .stream()
      .collect(toMap(YangModelKey::new, yangModuleInfo -> yangModuleInfo.getName().toString()));
}

代码示例来源:origin: io.lighty.core/lighty-common

private static void printDependencies(final Collection<YangModuleInfo> yangModuleInfos, final int prefixLength) {
  for (final YangModuleInfo yangModuleInfo : yangModuleInfos) {
    final QName qname = yangModuleInfo.getName();
    LOG.info("{}{} {} {}", Strings.repeat(" ", prefixLength), qname.getNamespace(), qname.getLocalName(), qname.getRevision());
    printDependencies(yangModuleInfo.getImportedModules(), prefixLength + PREFIX);
  }
}

代码示例来源:origin: io.lighty.core/lighty-common

private static void addDependencies(final Map<ModuleId, YangModuleInfo> resolvedModules, final Collection<YangModuleInfo> importedModules) {
  for (YangModuleInfo yangModuleInfo : importedModules) {
    resolvedModules.put(ModuleId.from(yangModuleInfo), yangModuleInfo);
    LOG.info("Adding [{}] module into known modules", yangModuleInfo);
    addDependencies(resolvedModules, yangModuleInfo.getImportedModules());
  }
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding-generator-impl

@Override
public ListenableFuture<? extends YangTextSchemaSource> getSource(
  final SourceIdentifier sourceIdentifier) {
  final YangModuleInfo yangModuleInfo = sourceIdentifierToModuleInfo.get(sourceIdentifier);
  if (yangModuleInfo == null) {
    LOG.debug("Unknown schema source requested: {}, available sources: {}", sourceIdentifier,
      sourceIdentifierToModuleInfo.keySet());
    return Futures.immediateFailedFuture(new SchemaSourceException(
      "Unknown schema source: " + sourceIdentifier));
  }
  return Futures.immediateFuture(YangTextSchemaSource.delegateForByteSource(sourceIdentifier,
    yangModuleInfo.getYangTextByteSource()));
}

代码示例来源:origin: io.fd.hc2vpp.docs/docs-core

YangModelKey(final YangModuleInfo moduleInfo) {
  this.namespace = moduleInfo.getName().getNamespace().toString();
  Optional<Revision> optRevision = moduleInfo.getName().getRevision();
  this.revision = optRevision.isPresent() ? optRevision.get().toString() : "";
}

代码示例来源:origin: io.lighty.core/lighty-common

public static void printModelInfo(final Set<YangModuleInfo> allModelsFromClasspath) {
  final int prefixLength = 0;
  final Set<YangModuleInfo> topLevelModels = YangModuleUtils.filterTopLevelModels(allModelsFromClasspath);
  LOG.info("# top-level models tree: {}", topLevelModels.size());
  for (final YangModuleInfo yangModuleInfo : topLevelModels) {
    final QName qname = yangModuleInfo.getName();
    LOG.info("{}", qname.getNamespace(), qname.getLocalName(), qname.getRevision());
    printDependencies(yangModuleInfo.getImportedModules(), prefixLength + PREFIX);
  }
  LOG.info("# top-level models list: {}", topLevelModels.size());
  for (final YangModuleInfo yangModuleInfo : topLevelModels) {
    final QName qname = yangModuleInfo.getName();
    LOG.info("{} {} {}", qname.getNamespace(), qname.getLocalName(), qname.getRevision());
  }
  final Set<YangModuleInfo> uniqueModels = YangModuleUtils.filterUniqueModels(allModelsFromClasspath);
  LOG.info("# unique models list   : {}", uniqueModels.size());
  for (final YangModuleInfo yangModuleInfo : uniqueModels) {
    final QName qname = yangModuleInfo.getName();
    LOG.info("{} {} {}", qname.getNamespace(), qname.getLocalName(), qname.getRevision());
  }
}

代码示例来源:origin: io.lighty.core/lighty-common

/**
 * Get all Yang modules from classpath filtered by collection of top-level modules.
 * @param filter
 *   The collection of top-level modules represented by name and revision.
 * @return
 *   Collection top-level modules and all of imported yang module dependencies recursively.
 *   Empty collection is returned if no suitable modules are found.
 */
public static Set<YangModuleInfo> getModelsFromClasspath(final Set<ModuleId> filter) {
  Map<ModuleId, YangModuleInfo> resolvedModules = new HashMap<>();
  ServiceLoader<YangModelBindingProvider> yangProviderLoader = ServiceLoader.load(YangModelBindingProvider.class);
  for (ModuleId moduleId: filter) {
    Set<YangModuleInfo> filteredSet = filterYangModelBindingProviders(moduleId, yangProviderLoader);
    for (YangModuleInfo yangModuleInfo : filteredSet) {
      resolvedModules.put(ModuleId.from(yangModuleInfo), yangModuleInfo);
      LOG.info("Adding [{}] module into known modules", yangModuleInfo);
      addDependencies(resolvedModules, yangModuleInfo.getImportedModules());
    }
  }
  return Collections.unmodifiableSet(resolvedModules.values().stream().collect(Collectors.toSet()));
}

代码示例来源:origin: io.lighty.core/lighty-common

public static void printConfiguration(final Set<YangModuleInfo> allModelsFromClasspath) {
  final Set<YangModuleInfo> topLevelModels = YangModuleUtils.filterTopLevelModels(allModelsFromClasspath);
  LOG.info("# top-level models list: {}", topLevelModels.size());
  for (final YangModuleInfo yangModuleInfo : topLevelModels) {
    final QName qname = yangModuleInfo.getName();
    System.out.println("{ \"nameSpace\": \"" + qname.getNamespace() + "\", \"name\": \""
        + qname.getLocalName() + "\", \"revision\": \"" + qname.getRevision().orElse(null) + "\" },");
  }
  LOG.info("# top-level models list: {}", topLevelModels.size());
  for (final YangModuleInfo yangModuleInfo: topLevelModels) {
    System.out.println(yangModuleInfo.getClass().getCanonicalName() + ".getInstance(),");
  }
}

代码示例来源:origin: io.lighty.core/lighty-common

/**
 * Filter unique models from given entry set.
 * This filter scans recursively dependencies and returns minimal set of models that are unique.
 * @param models
 *   Unfiltered entry set of models.
 * @return
 *   Filtered set of unique models only.
 */
public static Set<YangModuleInfo> filterUniqueModels(final Collection<YangModuleInfo> models) {
  Map<ModuleId, YangModuleInfo> result = new HashMap<>();
  for (YangModuleInfo yangModuleInfo: models) {
    result.put(ModuleId.from(yangModuleInfo), yangModuleInfo);
    for (YangModuleInfo yangModuleInfoDep : filterUniqueModels(yangModuleInfo.getImportedModules())) {
      result.put(ModuleId.from(yangModuleInfoDep), yangModuleInfoDep);
    }
  }
  return new HashSet<>(result.values());
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com