org.opendaylight.yangtools.yang.model.api.Module类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(122)

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

Module介绍

[英]This interface contains the methods for getting the data from the YANG module.

Example of YANG module`
#getName() module_name{
   #getYangVersion() "1";

   #getNamespace() "urn:module:namespace";
   #getPrefix() "prefix";

   #getDescription() "description test";
   #getReference() "reference test";

   #getOrganization()"John Doe, john.doe@email.com";
   #getContact() "http://www.opendaylight.org/";

   #getFeatures() feature-test{
     description "description of some feature";
  }
   #getNotifications() notification-test;
   #getRpcs() rpc-test;
   #getIdentities() identity-test;
   #getExtensionSchemaNodes() extension-test;
   #getRevision() 2011-08-27 {
   #getImports() other_module {
    prefix "other_module_prefix"
    revision-date 2011-08-27
  }

  container cont {
  }
   #getAugmentations() "/cont" { ;
  }
} [中]此接口包含从模块获取数据的方法。 YANG模块的示例
#getName() module_name{
   #getYangVersion() "1";

   #getNamespace() "urn:module:namespace";
   #getPrefix() "prefix";

   #getDescription() "description test";
   #getReference() "reference test";

   #getOrganization()"John Doe, john.doe@email.com";
   #getContact() "http://www.opendaylight.org/";

   #getFeatures() feature-test{
     description "description of some feature";
  }
   #getNotifications() notification-test;
   #getRpcs() rpc-test;
   #getIdentities() identity-test;
   #getExtensionSchemaNodes() extension-test;
   #getRevision() 2011-08-27 {
   #getImports() other_module {
    prefix "other_module_prefix"
    revision-date 2011-08-27
  }

  container cont {
  }
   #getAugmentations() "/cont" { ;
  }
} `

代码示例

代码示例来源:origin: org.opendaylight.controller/yang-jmx-generator

public static QName getQName(final Module currentModule) {
    return QName.create(currentModule.getNamespace(), currentModule.getRevision(), currentModule.getName());
  }
}

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

@Override
public void enterPrefix(final PrefixContext ctx) {
  final String prefix = ctx.getText();
  if (!leafrefModule.getPrefix().equals(prefix)) {
    final Optional<QNameModule> qnameModuleOpt = getQNameModuleForImportPrefix(leafrefModule, prefix);
    checkArgument(qnameModuleOpt.isPresent(), "No module import for prefix: %s in module: %s", prefix,
      leafrefModule.getName());
    currentQnameModule = qnameModuleOpt.get();
  } else {
    currentQnameModule = leafrefModule.getQNameModule();
  }
}

代码示例来源:origin: opendaylight/yangtools

@Override
public Set<RpcDefinition> getOperations() {
  final Set<RpcDefinition> rpcs = new HashSet<>();
  for (Module m : getModules()) {
    rpcs.addAll(m.getRpcs());
  }
  return rpcs;
}

代码示例来源:origin: opendaylight/yangtools

private static Collection<ModuleImport> allImports(final Module mod) {
  if (mod.getSubmodules().isEmpty()) {
    return mod.getImports();
  }
  final Collection<ModuleImport> concat = new LinkedHashSet<>();
  concat.addAll(mod.getImports());
  for (Module sub : mod.getSubmodules()) {
    concat.addAll(sub.getImports());
  }
  return concat;
}

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

private static URI getModuleNamespace(final SchemaContext ctx, final String moduleName) {
  for (final Module module : ctx.getModules()) {
    if (moduleName.equals(module.getName())) {
      return module.getNamespace();
    }
  }
  throw new IllegalArgumentException("Module " + moduleName + "does not exists in provided schema context");
}

代码示例来源:origin: opendaylight/yangtools

private QName createQName(final String prefix, final String localName) {
  final Module module = schemaContext.findModule(schemaNode.getQName().getModule()).get();
  if (prefix.isEmpty() || module.getPrefix().equals(prefix)) {
    return QName.create(module.getQNameModule(), localName);
  }
  for (final ModuleImport moduleImport : module.getImports()) {
    if (prefix.equals(moduleImport.getPrefix())) {
      final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
          moduleImport.getRevision()).get();
      return QName.create(importedModule.getQNameModule(),localName);
    }
  }
  throw new IllegalArgumentException(String.format("Failed to lookup a module for prefix %s", prefix));
}

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

private static Collection<Module> getImportedModules(final Map<ModuleId, Module> allModules,
    final Set<Module> baseModules, final TreeMultimap<String, Module> nameToModulesAll) {
  List<Module> relatedModules = Lists.newLinkedList();
  for (Module module : baseModules) {
    for (ModuleImport moduleImport : module.getImports()) {
      Optional<Revision> revisionDate = moduleImport.getRevision();
      if (!revisionDate.isPresent()) {
        revisionDate = nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision();
      }
      ModuleId key = new ModuleId(moduleImport.getModuleName(), revisionDate);
      Module importedModule = allModules.get(key);
      Preconditions.checkArgument(importedModule != null,
          "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key,
          module.getQNameModule(), module.getName(), allModules);
      relatedModules.add(importedModule);
      //calling imports recursive
      relatedModules.addAll(getImportedModules(allModules, Collections.singleton(importedModule),
            nameToModulesAll));
    }
  }
  return relatedModules;
}

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

private boolean checkModuleDependency(final Module module, final Collection<ModuleId> rootModules) {
  for (ModuleId rootModule : rootModules) {
    if (rootModule.equals(new ModuleId(module.getName(), module.getRevision()))) {
      return true;
    }
    //handling/checking imports regarding root modules
    for (ModuleImport moduleImport : module.getImports()) {
      if (moduleImport.getModuleName().equals(rootModule.getName())) {
        return !moduleImport.getRevision().isPresent()
            || moduleImport.getRevision().equals(rootModule.getRev());
      }
    }
    //submodules handling
    for (Module moduleSub : module.getSubmodules()) {
      return checkModuleDependency(moduleSub, rootModules);
    }
  }
  return false;
}

代码示例来源:origin: org.opendaylight.controller/yang-jmx-generator

Set<QName> allIdentitiesInModule = Sets.newHashSet(Collections2.transform(currentModule.getIdentities(), QNAME_FROM_NODE));
for (RpcDefinition rpc : currentModule.getRpcs()) {
  ContainerSchemaNode input = rpc.getInput();
  if (input != null) {
                .getNodeParameter();
            QName identityQName = QName.create(
                currentModule.getNamespace(),
                currentModule.getRevision(),
                localIdentityName);
            Preconditions.checkArgument(allIdentitiesInModule.contains(identityQName),

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

private Submodules createSubmodulesForModule(final Module module) {
    final List<Submodule> submodulesList = Lists.newArrayList();
    for (final Module subModule : module.getSubmodules()) {
      final SubmoduleBuilder subModuleEntryBuilder = new SubmoduleBuilder();
      subModuleEntryBuilder.setName(new YangIdentifier(subModule.getName()))
          .setRevision(new OptionalRevision(SimpleDateFormatUtil.getRevisionFormat().format(subModule.getRevision())));
      submodulesList.add(subModuleEntryBuilder.build());
    }

    return  new SubmodulesBuilder().setSubmodule(submodulesList).build();
  }
}

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

/**
 * Returns the namespace of the module which is specified as argument of
 * YANG {@link Module <b><font color="#00FF00">namespace</font></b>}
 * keyword. If you need both namespace and revision, please consider using
 * {@link #getQNameModule()}.
 *
 * @return URI format of the namespace of the module
 */
@Override
default URI getNamespace() {
  return getQNameModule().getNamespace();
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding2-java-api-generator

public static Module getSortedQName(final Set<Module> modules, final String name) {
  final TreeMap<Optional<Revision>, Module> sorted = new TreeMap<>(Revision::compare);
  for (Module module : modules) {
    if (name.equals(module.getName())) {
      sorted.put(module.getRevision(), module);
    }
  }
  return sorted.lastEntry().getValue();
}

代码示例来源:origin: opendaylight/controller

private String findYangModuleName(final QName qname, final SchemaContext schemaContext)
    throws ConfigXMLReaderException {
  for (Module m : schemaContext.getModules()) {
    if (qname.getModule().equals(m.getQNameModule())) {
      return m.getName();
    }
  }
  throw new ConfigXMLReaderException(
      String.format("%s: Could not find yang module for QName %s", logName, qname));
}

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

@Override
@SuppressWarnings("checkstyle:parameterName")
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
    final int charPositionInLine, final String msg, final RecognitionException e) {
  LOG.debug("Syntax error in module {} at {}:{}: {}", module.getName(), line, charPositionInLine, msg, e);
  exceptions.add(new LeafRefPathSyntaxErrorException(module.getName(), line, charPositionInLine, msg, e));
}

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

/**
 * Converts all <b>identities</b> of the module to the list of
 * <code>Type</code> objects.
 *
 * @param module
 *            module from which is obtained set of all identity objects to
 *            iterate over them
 * @param context
 *            schema context only used as input parameter for method
 *            {@link identityToGenType}
 *
 */
private void allIdentitiesToGenTypes(final Module module, final SchemaContext context) {
  final Set<IdentitySchemaNode> schemaIdentities = module.getIdentities();
  final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
  if (schemaIdentities != null && !schemaIdentities.isEmpty()) {
    for (final IdentitySchemaNode identity : schemaIdentities) {
      identityToGenType(module, basePackageName, identity, context);
    }
  }
}

代码示例来源:origin: org.opendaylight.controller/config-netconf-connector

private static Map<String, Map<Date, IdentityMapping>> transformIdentities(Set<Module> modules) {
  Map<String, Map<Date, IdentityMapping>> mappedIds = Maps.newHashMap();
  for (Module module : modules) {
    String namespace = module.getNamespace().toString();
    Map<Date, IdentityMapping> revisionsByNamespace= mappedIds.get(namespace);
    if(revisionsByNamespace == null) {
      revisionsByNamespace = Maps.newHashMap();
      mappedIds.put(namespace, revisionsByNamespace);
    }
    Date revision = module.getRevision();
    IdentityMapping identityMapping = revisionsByNamespace.get(revision);
    if(identityMapping == null) {
      identityMapping = new IdentityMapping();
      revisionsByNamespace.put(revision, identityMapping);
    }
    for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
      identityMapping.addIdSchemaNode(identitySchemaNode);
    }
  }
  return mappedIds;
}

代码示例来源:origin: org.opendaylight.controller/sal-rest-connector

private static RpcDefinition findRpc(final SchemaContext schemaContext, final String identifierDecoded) {
  final String[] splittedIdentifier = identifierDecoded.split(":");
  if (splittedIdentifier.length != 2) {
    final String errMsg = identifierDecoded + " couldn't be splitted to 2 parts (module:rpc name)";
    LOG.debug(errMsg);
    throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.INVALID_VALUE);
  }
  for (final Module module : schemaContext.getModules()) {
    if (module.getName().equals(splittedIdentifier[0])) {
      for (final RpcDefinition rpcDefinition : module.getRpcs()) {
        if (rpcDefinition.getQName().getLocalName().equals(splittedIdentifier[1])) {
          return rpcDefinition;
        }
      }
    }
  }
  return null;
}

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

private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) {
  final BiMap<String, URI> prefixMap = HashBiMap.create(module.getImports().size() + 1);
  prefixMap.put(module.getPrefix(), module.getNamespace());
  for (final ModuleImport imp : module.getImports()) {
    final String prefix = imp.getPrefix();
    final URI namespace = getModuleNamespace(ctx, imp.getModuleName());
    prefixMap.put(prefix, namespace);
  }
  return prefixMap;
}

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

private void emitBodyNodes(final Module input) {
  for (final ExtensionDefinition extension : input.getExtensionSchemaNodes()) {
    emitExtension(extension);
  }
  for (final FeatureDefinition definition : input.getFeatures()) {
    emitFeature(definition);
  }
  for (final IdentitySchemaNode identity : input.getIdentities()) {
    emitIdentity(identity);
  }
  for (final Deviation deviation : input.getDeviations()) {
    emitDeviation(deviation);
  }
  emitDataNodeContainer(input);
  for (final AugmentationSchemaNode augmentation : input.getAugmentations()) {
    emitAugment(augmentation);
  }
  for (final RpcDefinition rpc : input.getRpcs()) {
    emitRpc(rpc);
  }
  emitNotifications(input.getNotifications());
}

代码示例来源:origin: org.opendaylight.controller/sal-rest-connector

@Override
public QName deserialize(final IdentityValuesDTO data) {
  final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
  final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint);
  if (module == null) {
    logger.info("Module was not found for namespace {}", valueWithNamespace.getNamespace());
    logger.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace));
    return null;
  }
  return QName.create(module.getNamespace(), module.getRevision(), valueWithNamespace.getValue());
}

相关文章