org.opendaylight.yangtools.yang.model.api.Module.getPrefix()方法的使用及代码示例

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

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

Module.getPrefix介绍

[英]Returns the prefix of the module.
[中]返回模块的前缀。

代码示例

代码示例来源: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 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: 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: opendaylight/yangtools

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: 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-data-jaxen

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

checkArgument(prefix != null, "Prefix string cannot be NULL");
if (prefix.equals(module.getPrefix())) {
  return module;

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

checkArgument(prefix != null, "Prefix string cannot be NULL");
if (prefix.equals(module.getPrefix())) {
  return module;

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

private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity,
    final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) {
  final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity);
  final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get();
  if (identityPrefixAndName.size() == 2) {
    // prefix of local module
    if (identityPrefixAndName.get(0).equals(module.getPrefix())) {
      return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(),
          identityPrefixAndName.get(1)));
    }
    // prefix of imported module
    for (final ModuleImport moduleImport : module.getImports()) {
      if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) {
        final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
          moduleImport.getRevision()).get();
        return findIdentitySchemaNodeInModule(importedModule, QName.create(
          importedModule.getQNameModule(), identityPrefixAndName.get(1)));
      }
    }
    throw new IllegalArgumentException(String.format("Cannot resolve prefix '%s' from identity '%s'.",
        identityPrefixAndName.get(0), identity));
  }
  if (identityPrefixAndName.size() == 1) {
    // without prefix
    return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(),
        identityPrefixAndName.get(0)));
  }
  throw new IllegalArgumentException(String.format("Malformed identity argument: %s.", identity));
}

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

private static IdentitySchemaNode getIdentitySchemaNodeFromString(final String identity,
    final SchemaContext schemaContext, final TypedDataSchemaNode correspondingSchemaNode) {
  final List<String> identityPrefixAndName = COLON_SPLITTER.splitToList(identity);
  final Module module = schemaContext.findModule(correspondingSchemaNode.getQName().getModule()).get();
  if (identityPrefixAndName.size() == 2) {
    // prefix of local module
    if (identityPrefixAndName.get(0).equals(module.getPrefix())) {
      return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(),
          identityPrefixAndName.get(1)));
    }
    // prefix of imported module
    for (final ModuleImport moduleImport : module.getImports()) {
      if (identityPrefixAndName.get(0).equals(moduleImport.getPrefix())) {
        final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
          moduleImport.getRevision()).get();
        return findIdentitySchemaNodeInModule(importedModule, QName.create(
          importedModule.getQNameModule(), identityPrefixAndName.get(1)));
      }
    }
    throw new IllegalArgumentException(String.format("Cannot resolve prefix '%s' from identity '%s'.",
        identityPrefixAndName.get(0), identity));
  }
  if (identityPrefixAndName.size() == 1) {
    // without prefix
    return findIdentitySchemaNodeInModule(module, QName.create(module.getQNameModule(),
        identityPrefixAndName.get(0)));
  }
  throw new IllegalArgumentException(String.format("Malformed identity argument: %s.", identity));
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding2-dom-codec

private static Object qnameDomValueFromString(final Codec<Object, Object> codec, final DataSchemaNode schema,
    final String defaultValue, final SchemaContext schemaContext) {
  final int prefixEndIndex = defaultValue.indexOf(':');
  if (prefixEndIndex != -1) {
    final String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex);
    final Module module = schemaContext.findModule(schema.getQName().getModule()).get();
    if (module.getPrefix().equals(defaultValuePrefix)) {
      return codec.deserialize(QName.create(module.getQNameModule(),
        defaultValue.substring(prefixEndIndex + 1)));
    }
    final Set<ModuleImport> imports = module.getImports();
    for (final ModuleImport moduleImport : imports) {
      if (moduleImport.getPrefix().equals(defaultValuePrefix)) {
        final Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
          moduleImport.getRevision()).get();
        return codec.deserialize(QName.create(importedModule.getQNameModule(),
          defaultValue.substring(prefixEndIndex + 1)));
      }
    }
    return null;
  }
  return codec.deserialize(QName.create(schema.getQName(), defaultValue));
}

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

private static Object qnameDomValueFromString(final Codec<Object, Object> codec, final DataSchemaNode schema,
                       final String defaultValue, final SchemaContext schemaContext) {
  int prefixEndIndex = defaultValue.indexOf(':');
  QName qname;
  if (prefixEndIndex != -1) {
    String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex);
    Module module = schemaContext.findModule(schema.getQName().getModule()).get();
    if (module.getPrefix().equals(defaultValuePrefix)) {
      qname = QName.create(module.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
      return codec.deserialize(qname);
    }
    Set<ModuleImport> imports = module.getImports();
    for (ModuleImport moduleImport : imports) {
      if (moduleImport.getPrefix().equals(defaultValuePrefix)) {
        Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
          moduleImport.getRevision()).get();
        qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
        return codec.deserialize(qname);
      }
    }
    return null;
  }
  qname = QName.create(schema.getQName(), defaultValue);
  return codec.deserialize(qname);
}

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

private void emitModuleHeader(final Module input) {
  emitYangVersionNode(input.getYangVersion());
  emitNamespace(input.getNamespace());
  emitPrefixNode(input.getPrefix());
}

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

/**
   * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG
   * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules
   * and their namespaces. This information is cached and used for improved lookups.
   *
   * @param ctx A SchemaContext
   * @param module Module in which the XPath is defined
   * @return A new Converter
   */
  public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) {
    // Always check for null ctx
    requireNonNull(ctx, "Schema context may not be null");

    // Use immutable map builder for detection of duplicates (which should never occur)
    final Builder<String, QNameModule> b = ImmutableBiMap.builder();
    b.put(module.getPrefix(), module.getQNameModule());

    for (ModuleImport i : module.getImports()) {
      final Optional<Module> mod = ctx.findModule(i.getModuleName(), i.getRevision());
      checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module);

      b.put(i.getPrefix(), mod.get().getQNameModule());
    }

    return Maps.asConverter(b.build());
  }
}

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

/**
   * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG
   * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules
   * and their namespaces. This information is cached and used for improved lookups.
   *
   * @param ctx A SchemaContext
   * @param module Module in which the XPath is defined
   * @return A new Converter
   */
  public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) {
    // Always check for null ctx
    requireNonNull(ctx, "Schema context may not be null");

    // Use immutable map builder for detection of duplicates (which should never occur)
    final Builder<String, QNameModule> b = ImmutableBiMap.builder();
    b.put(module.getPrefix(), module.getQNameModule());

    for (ModuleImport i : module.getImports()) {
      final Optional<Module> mod = ctx.findModule(i.getModuleName(), i.getRevision());
      checkArgument(mod.isPresent(), "Unsatisfied import of %s by module %s", i, module);

      b.put(i.getPrefix(), mod.get().getQNameModule());
    }

    return Maps.asConverter(b.build());
  }
}

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

_builder.append("    ");
_builder.append("prefix \"");
String _prefix = module.getPrefix();
_builder.append(_prefix, "    ");
_builder.append("\";");

相关文章