io.helidon.config.Config.get()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(165)

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

Config.get介绍

[英]Returns the single sub-node for the specified sub-key.

The format of the key is described on #key() method.
[中]返回指定子项的单个子节点。
密钥的格式在#key()方法中描述。

代码示例

代码示例来源:origin: oracle/helidon

@Override
public Config get(Key key) {
  if (key.isRoot()) {
    return this;
  } else {
    return Config.empty().get(this.key).get(key);
  }
}

代码示例来源:origin: oracle/helidon

private String format(String template) {
    Matcher m = PATTERN_REFERENCE.matcher(template);
    final StringBuffer sb = new StringBuffer();
    while (m.find()) {
      m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get()));
    }
    m.appendTail(sb);
    // remove all backslash that encodes ${...}
    m = PATTERN_BACKSLASH.matcher(sb.toString());

    return m.replaceAll("");
  }
}

代码示例来源:origin: oracle/helidon

/**
   * Update builder from configuration.
   *
   * @param config config located on key of this validator
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("operator").asString().map("OR"::equals).ifPresent(this::useOrOperator);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

private static <T> void configure(Config config,
                 String key,
                 Optional<T> defaultValue,
                 Consumer<T> builderMethod,
                 Class<T> clazz) {
  config.get(key).as(clazz).or(() -> defaultValue).ifPresent(builderMethod);
}

代码示例来源:origin: oracle/helidon

@Override
public Locale apply(Config config) throws ConfigMappingException, MissingValueException {
  String language = config.get("language").asString().get();
  String country = config.get("country").asString().orElse("");
  String variant = config.get("variant").asString().orElse("");
  return new Locale("m2:" + language, "m2:" + country, "m2:" + variant);
}

代码示例来源:origin: oracle/helidon

@Override
public Locale apply(Config config) throws ConfigMappingException, MissingValueException {
  String language = config.get("language").asString().get();
  String country = config.get("country").asString().orElse("");
  String variant = config.get("variant").asString().orElse("");
  return new Locale(language, country, variant);
}

代码示例来源:origin: oracle/helidon

static Optional<Resource> fromConfigB64Content(Config config, String keyPrefix) {
  return config.get(keyPrefix + "-content")
      .asString()
      .map(Base64.getDecoder()::decode)
      .map(content -> Resource.create("config:" + keyPrefix + "-content-b64", content));
}

代码示例来源:origin: oracle/helidon

private <T> T findValue(String propertyName, Class<T> propertyType) {
  if (propertyType == Config.class) {
    return config.get().get(propertyName).as(propertyType).get();
  }
  //first iterate over mp sources, than use config
  return findInMpSources(propertyName)
      .map(value -> convert(propertyType, value))
      .orElseGet(() -> config.get().get(propertyName).as(propertyType).get());
}

代码示例来源:origin: oracle/helidon

/**
 * Override default configuration.
 *
 * @param config configuration instance
 * @return updated builder instance
 * @see MetricsSupport for details about configuration keys
 */
public Builder config(Config config) {
  this.config = config;
  config.get("helidon.metrics.context").asString().ifPresent(this::context);
  return this;
}

代码示例来源:origin: oracle/helidon

@Override
  public void configure(MpServiceContext mpServiceContext) {
    CommandScheduler.create(mpServiceContext.helidonConfig().get("helidon.fault-tolerance.async-thread-pool"));
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Update this builder from configuration.
 *
 * @param config config instance located on the key {@link PolicyValidator#configKey()}
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("inherit").asBoolean().ifPresent(this::inherit);
  config.get("statement").asString().ifPresent(this::statement);
  return this;
}

代码示例来源:origin: oracle/helidon

static ConfigUser create(Config config) {
  ConfigUser cu = new ConfigUser();
  cu.login = config.get("login").asString().get();
  cu.password = config.get("password").asString().orElse("").toCharArray();
  cu.roles.addAll(config.get("roles").asList(String.class).orElse(CollectionsHelper.listOf()));
  return cu;
}

代码示例来源:origin: oracle/helidon

private void outbound(Config config) {
    // jwk is optional, we may be propagating existing token
    Resource.create(config, "jwk").ifPresent(this::signJwk);
    config.get("jwt-issuer").asString().ifPresent(this::issuer);
  }
}

代码示例来源:origin: oracle/helidon

private void outbound(Config config) {
    // jwk is optional, we may be propagating existing token
    Resource.create(config, "jwk").ifPresent(this::signJwk);
    config.get("jwt-issuer").asString().ifPresent(this::issuer);
  }
}

代码示例来源:origin: oracle/helidon

static OutboundTarget create(Config c) {
  Builder builder = new Builder();
  builder.config(c);
  builder.name(c.get(CONFIG_NAME).asString().get());
  c.get(CONFIG_TRANSPORTS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addTransport);
  c.get(CONFIG_HOSTS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addHost);
  c.get(CONFIG_PATHS).asList(String.class).orElse(CollectionsHelper.listOf())
      .forEach(builder::addPath);
  return builder.build();
}

代码示例来源:origin: oracle/helidon

static Optional<Resource> fromConfigContent(Config config, String keyPrefix) {
  return config.get(keyPrefix + "-content-plain")
      .asString()
      .map(content -> Resource.create("config:" + keyPrefix + "-content", content));
}

代码示例来源:origin: oracle/helidon

/**
 * Create a new instance from configuration.
 *
 * @param config configuration located at header config
 * @return instance configured from config
 */
public static HeadersConfig create(Config config) {
  return create(config.get("always").asList(String.class).orElse(CollectionsHelper.listOf()),
         config.get("if-present").asList(String.class).orElse(CollectionsHelper.listOf()));
}

代码示例来源:origin: oracle/helidon

private String aliased(String value, Config config) {
  if (value.startsWith(PREFIX_ALIAS)) {
    // another_password=${ALIAS=service_password}
    String alias = removePlaceholder(PREFIX_ALIAS, value);
    return config.get(alias).asString().orElseThrow(MissingValueException.createSupplier(Config.Key.create(alias)));
  }
  return value;
}

代码示例来源:origin: oracle/helidon

private static void register(BaseRegistry registry,
               Config config,
               Metadata meta,
               Metric metric) {
  if (registry.config.get(CONFIG_METRIC_ENABLED_BASE + meta.getName() + ".enabled").asBoolean().orElse(true)) {
    registry.register(meta, metric);
  }
}

代码示例来源:origin: oracle/helidon

@Override
public void filter(ContainerRequestContext requestContext) {
  ServerRequest serverRequest = this.request.get();
  Tracer tracer = serverRequest.webServer().configuration().tracer();
  SpanContext parentSpan = serverRequest.spanContext();
  boolean clientEnabled = config.get("tracing.client.enabled").asBoolean().orElse(true);
  TracingContext tracingContext = TracingContext.create(tracer, serverRequest.headers().toMap(), clientEnabled);
  tracingContext.parentSpan(parentSpan);
  TracingContext.set(tracingContext);
}

相关文章