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

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

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

Config.exists介绍

[英]Returns true if the node exists, whether an object, a list, or a value node.
[中]如果节点存在(无论是对象、列表还是值节点),则返回true。

代码示例

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

/**
 * Returns existing current config node as a {@link Optional} instance
 * or {@link Optional#empty()} in case of {@link Type#MISSING} node.
 *
 * @return current config node as a {@link Optional} instance
 *         or {@link Optional#empty()} in case of {@link Type#MISSING} node.
 */
default ConfigValue<Config> asNode() {
  return ConfigValues.create(this,
                () -> exists() ? Optional.of(this) : Optional.empty(),
                Config::asNode);
}

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

private static Map<Class<?>, Function<Config, ?>> initEssentialMappers() {
  Map<Class<?>, Function<Config, ?>> essentials = new HashMap<>();
  essentials.put(Config.class, (node) -> node);
  essentials.put(String.class, wrap(value -> value));
  essentials.put(OptionalInt.class, (node) -> {
    if (!node.exists()) {
      return OptionalInt.empty();
    }
    return OptionalInt.of(wrap(Integer::parseInt).apply(node));
  });
  essentials.put(OptionalLong.class, (node) -> {
    if (!node.exists()) {
      return OptionalLong.empty();
    }
    return OptionalLong.of(wrap(Long::parseLong).apply(node));
  });
  essentials.put(OptionalDouble.class, (node) -> {
    if (!node.exists()) {
      return OptionalDouble.empty();
    }
    return OptionalDouble.of(wrap(Double::parseDouble).apply(node));
  });
  return Collections.unmodifiableMap(essentials);
}

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

private static Config findMyKey(Config rootConfig, String providerName) {
  if (rootConfig.key().name().equals(providerName)) {
    return rootConfig;
  }
  return rootConfig.get("security.providers")
      .asNodeList()
      .get()
      .stream()
      .filter(it -> it.get(providerName).exists())
      .findFirst()
      .map(it -> it.get(providerName))
      .orElseThrow(() -> new SecurityException("No configuration found for provider named: " + providerName));
}

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

Optional<T> get(Config configNode) {
  try {
    if (configNode.exists()) {
      if (list) {
        return Optional.of(propertyType.cast(configNode.asList(configAsType).get()));
      } else {
        return Optional.of(propertyType.cast(configNode.as(configAsType).get()));
      }
    } else {
      if (defaultSupplier != null) {
        return Optional.ofNullable(defaultSupplier.apply(propertyType, configNode));
      } else {
        return Optional.empty();
      }
    }
  } catch (ConfigException ex) {
    throw ex;
  } catch (Throwable throwable) {
    throw new ConfigException("Unable to set '" + name + "' property.", throwable);
  }
}

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

.ifPresentOrElse(builder::rolesAllowed,
             () -> defaults.rolesAllowed.ifPresent(builder::rolesAllowed));
if (config.exists()) {
  builder.config(config);
if (config.get(KEY_ROLES_ALLOWED).exists()) {
  if (!config.get(KEY_AUTHENTICATE).exists()) {
    builder.authenticate(true);
  if (!config.get(KEY_AUTHORIZE).exists()) {
    builder.authorize(true);
    if (!config.get(KEY_AUTHENTICATE).exists()) {
      builder.authenticate(true);
  if (!config.get(KEY_AUTHENTICATE).exists()) {
    builder.authenticate(true);
  if (!config.get(KEY_AUTHORIZE).exists()) {
    builder.authorize(true);

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

if (socketsConfig.exists()) {
  for (Config socketConfig : socketsConfig.asNodeList().orElse(CollectionsHelper.listOf())) {
    String socketName = socketConfig.name();
if (experimentalConfig.exists()) {
  ExperimentalConfiguration.Builder experimentalBuilder = new ExperimentalConfiguration.Builder();
  Config http2Config = experimentalConfig.get("http2");
  if (http2Config.exists()) {
    Http2Configuration.Builder http2Builder = new Http2Configuration.Builder();
    http2Config.get("enable").asBoolean().ifPresent(http2Builder::enable);

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

if (config.get("security.providers").exists()) {
  security = Security.create(config.get("security"));
} else {
if (webServerConfig.exists() && webServerConfig.get("enabled").asBoolean().orElse(true)) {
  context.serverRoutingBuilder()
      .register(WebSecurity.create(security, config));

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

StaticContentSupport staticContent = cpBuilder.build();
if (context.exists()) {
  routingBuilder.register(context.asString().get(), staticContent);
} else {
StaticContentSupport staticContent = pBuilder.build();
if (context.exists()) {
  routingBuilder.register(context.asString().get(), staticContent);
} else {

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

/**
 * Update this builder from configuration.
 * @param config configuration to read, located on the node of the http basic authentication provider
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("realm").asString().ifPresent(this::realm);
  config.get("principal-type").asString().as(SubjectType::valueOf).ifPresent(this::subjectType);
  // now users may not be configured at all
  Config usersConfig = config.get("users");
  if (usersConfig.exists()) {
    // or it may be jst an empty list (e.g. users: with no subnodes).
    if (!usersConfig.isLeaf()) {
      userStore(usersConfig.as(ConfigUserStore::create)
                   .orElseThrow(() -> new HttpAuthException(
                       "No users configured! Key \"users\" must be in configuration")));
    }
  }
  return this;
}

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

private SocketConfiguration.Builder configureSocket(Config config, SocketConfiguration.Builder soConfigBuilder) {
  config.get("port").asInt().ifPresent(soConfigBuilder::port);
  config.get("bind-address")
      .asString()
      .map(this::string2InetAddress)
      .ifPresent(soConfigBuilder::bindAddress);
  config.get("backlog").asInt().ifPresent(soConfigBuilder::backlog);
  config.get("timeout").asInt().ifPresent(soConfigBuilder::timeoutMillis);
  config.get("receive-buffer").asInt().ifPresent(soConfigBuilder::receiveBufferSize);
  // ssl
  Config sslConfig = config.get("ssl");
  if (sslConfig.exists()) {
    try {
      soConfigBuilder.ssl(SSLContextBuilder.create(sslConfig));
    } catch (IllegalStateException e) {
      throw new ConfigException("Cannot load SSL configuration.", e);
    }
  }
  return soConfigBuilder;
}

代码示例来源:origin: io.helidon.config/helidon-config

/**
 * Returns existing current config node as a {@link Optional} instance
 * or {@link Optional#empty()} in case of {@link Type#MISSING} node.
 *
 * @return current config node as a {@link Optional} instance
 *         or {@link Optional#empty()} in case of {@link Type#MISSING} node.
 */
default ConfigValue<Config> asNode() {
  return ConfigValues.create(this,
                () -> exists() ? Optional.of(this) : Optional.empty(),
                Config::asNode);
}

代码示例来源:origin: io.helidon.config/helidon-config

private static Map<Class<?>, Function<Config, ?>> initEssentialMappers() {
  Map<Class<?>, Function<Config, ?>> essentials = new HashMap<>();
  essentials.put(Config.class, (node) -> node);
  essentials.put(String.class, wrap(value -> value));
  essentials.put(OptionalInt.class, (node) -> {
    if (!node.exists()) {
      return OptionalInt.empty();
    }
    return OptionalInt.of(wrap(Integer::parseInt).apply(node));
  });
  essentials.put(OptionalLong.class, (node) -> {
    if (!node.exists()) {
      return OptionalLong.empty();
    }
    return OptionalLong.of(wrap(Long::parseLong).apply(node));
  });
  essentials.put(OptionalDouble.class, (node) -> {
    if (!node.exists()) {
      return OptionalDouble.empty();
    }
    return OptionalDouble.of(wrap(Double::parseDouble).apply(node));
  });
  return Collections.unmodifiableMap(essentials);
}

代码示例来源:origin: io.helidon.security/helidon-security-integration-webserver

.ifPresentOrElse(builder::rolesAllowed,
             () -> defaults.rolesAllowed.ifPresent(builder::rolesAllowed));
if (config.exists()) {
  builder.config(config);
if (config.get(KEY_ROLES_ALLOWED).exists()) {
  if (!config.get(KEY_AUTHENTICATE).exists()) {
    builder.authenticate(true);
  if (!config.get(KEY_AUTHORIZE).exists()) {
    builder.authorize(true);
    if (!config.get(KEY_AUTHENTICATE).exists()) {
      builder.authenticate(true);
  if (!config.get(KEY_AUTHENTICATE).exists()) {
    builder.authenticate(true);
  if (!config.get(KEY_AUTHORIZE).exists()) {
    builder.authorize(true);

代码示例来源:origin: io.helidon.microprofile/helidon-microprofile-security

if (config.get("security.providers").exists()) {
  security = Security.create(config.get("security"));
} else {
if (webServerConfig.exists() && webServerConfig.get("enabled").asBoolean().orElse(true)) {
  context.serverRoutingBuilder()
      .register(WebSecurity.create(security, config));

代码示例来源:origin: io.helidon.microprofile.server/helidon-microprofile-server

StaticContentSupport staticContent = cpBuilder.build();
if (context.exists()) {
  routingBuilder.register(context.asString().get(), staticContent);
} else {
StaticContentSupport staticContent = pBuilder.build();
if (context.exists()) {
  routingBuilder.register(context.asString().get(), staticContent);
} else {

相关文章