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

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

本文整理了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

  1. @Override
  2. public Config get(Key key) {
  3. if (key.isRoot()) {
  4. return this;
  5. } else {
  6. return Config.empty().get(this.key).get(key);
  7. }
  8. }

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

  1. private String format(String template) {
  2. Matcher m = PATTERN_REFERENCE.matcher(template);
  3. final StringBuffer sb = new StringBuffer();
  4. while (m.find()) {
  5. m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get()));
  6. }
  7. m.appendTail(sb);
  8. // remove all backslash that encodes ${...}
  9. m = PATTERN_BACKSLASH.matcher(sb.toString());
  10. return m.replaceAll("");
  11. }
  12. }

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

  1. /**
  2. * Update builder from configuration.
  3. *
  4. * @param config config located on key of this validator
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("operator").asString().map("OR"::equals).ifPresent(this::useOrOperator);
  9. return this;
  10. }
  11. }

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Override default configuration.
  3. *
  4. * @param config configuration instance
  5. * @return updated builder instance
  6. * @see MetricsSupport for details about configuration keys
  7. */
  8. public Builder config(Config config) {
  9. this.config = config;
  10. config.get("helidon.metrics.context").asString().ifPresent(this::context);
  11. return this;
  12. }

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

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

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

  1. /**
  2. * Update this builder from configuration.
  3. *
  4. * @param config config instance located on the key {@link PolicyValidator#configKey()}
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("inherit").asBoolean().ifPresent(this::inherit);
  9. config.get("statement").asString().ifPresent(this::statement);
  10. return this;
  11. }

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

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

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

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

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

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

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

  1. static OutboundTarget create(Config c) {
  2. Builder builder = new Builder();
  3. builder.config(c);
  4. builder.name(c.get(CONFIG_NAME).asString().get());
  5. c.get(CONFIG_TRANSPORTS).asList(String.class).orElse(CollectionsHelper.listOf())
  6. .forEach(builder::addTransport);
  7. c.get(CONFIG_HOSTS).asList(String.class).orElse(CollectionsHelper.listOf())
  8. .forEach(builder::addHost);
  9. c.get(CONFIG_PATHS).asList(String.class).orElse(CollectionsHelper.listOf())
  10. .forEach(builder::addPath);
  11. return builder.build();
  12. }

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

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

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

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

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

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

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

  1. private static void register(BaseRegistry registry,
  2. Config config,
  3. Metadata meta,
  4. Metric metric) {
  5. if (registry.config.get(CONFIG_METRIC_ENABLED_BASE + meta.getName() + ".enabled").asBoolean().orElse(true)) {
  6. registry.register(meta, metric);
  7. }
  8. }

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

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

相关文章