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

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

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

Config.key介绍

[英]Returns the fully-qualified key of the Config node.

The fully-qualified key is a sequence of tokens derived from the name of each node along the path from the config root to the current node. Tokens are separated by . (the dot character). See #name() for more information on the format of each token.
[中]返回配置节点的完全限定键。
完全限定键是从每个节点的名称沿着从配置根到当前节点的路径派生的令牌序列。代币之间用空格分隔。(点字符)。有关每个令牌格式的更多信息,请参见#name()。

代码示例

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

  1. private GenericConfigValueImpl(Config owningConfig,
  2. Supplier<Optional<T>> valueSupplier,
  3. Function<Config, ConfigValue<T>> configMethod) {
  4. super(owningConfig.key());
  5. this.owningConfig = owningConfig;
  6. this.valueSupplier = valueSupplier;
  7. this.configMethod = configMethod;
  8. }

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

  1. @Override
  2. public T apply(Config config, ConfigMapper configMapper) {
  3. throw new ConfigMappingException(config.key(), type, "No mapper configured");
  4. }

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

  1. private void findProviderSpecificConfig(Config pConf, AtomicReference<Config> providerSpecific) {
  2. // no service for this class, must choose the configuration by selection
  3. pConf.asNodeList().get().stream().filter(this::notReservedProviderKey).forEach(providerSpecificConf -> {
  4. if (!providerSpecific.compareAndSet(null, providerSpecificConf)) {
  5. throw new SecurityException("More than one provider configurations found, each provider can only"
  6. + " have one provide specific config. Conflict: "
  7. + providerSpecific.get().key()
  8. + " and " + providerSpecificConf.key());
  9. }
  10. });
  11. }

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

  1. /**
  2. * Utility method wrapping an arbitrary mapper and ensuring proper exceptions are produced if needed.
  3. *
  4. * @param mapper mapping function. Function throws {@link ConfigMappingException} in case the value cannot be mapped.
  5. * @param <T> mapped Java type.
  6. * @return mapped value.
  7. */
  8. private static <T> Function<Config, T> wrapMapper(Function<Config, T> mapper) {
  9. return (node) -> {
  10. try {
  11. return mapper.apply(node);
  12. } catch (MissingValueException | ConfigMappingException ex) {
  13. throw ex;
  14. } catch (RuntimeException ex) {
  15. throw new ConfigMappingException(
  16. node.key(), "Invocation of mapper '" + mapper + "' has failed with an exception.", ex);
  17. }
  18. };
  19. }

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

  1. @Override
  2. public <T> T map(Config config, GenericType<T> type) throws MissingValueException, ConfigMappingException {
  3. Mapper<?> mapper = mappers.computeIfAbsent(type, theType -> findMapper(theType, config.key()));
  4. return cast(type, mapper.apply(config, this), config.key());
  5. }

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

  1. /**
  2. * Wrap a simple String value mapping function into a contextual mapper.
  3. *
  4. * @param mapper arbitrary String configuration value to a Java type mapping function.
  5. * @param <T> mapped Java type.
  6. * @return contextual mapper wrapping the simple String value mapping function.
  7. * @throws MissingValueException in case the configuration node does not represent an existing configuration node.
  8. * @throws ConfigMappingException in case the mapper fails to map the existing configuration value
  9. * to an instance of a given Java type.
  10. */
  11. static <T> Function<Config, T> wrap(Function<String, T> mapper) {
  12. return (node) -> nodeValue(node)
  13. .map(value -> safeMap(node.key(), value, mapper))
  14. .orElseThrow(MissingValueException.createSupplier(node.key()));
  15. }

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

  1. private void findProviderService(Map<String, SecurityProviderService> configKeyToService,
  2. String knownKeys,
  3. Config pConf,
  4. AtomicReference<SecurityProviderService> service,
  5. AtomicReference<Config> providerSpecific) {
  6. // everything else is based on provider specific configuration
  7. pConf.asNodeList().get().stream().filter(this::notReservedProviderKey).forEach(providerSpecificConf -> {
  8. if (!providerSpecific.compareAndSet(null, providerSpecificConf)) {
  9. throw new SecurityException("More than one provider configurations found, each provider can only"
  10. + " have one provider specific config. Conflict: "
  11. + providerSpecific.get().key()
  12. + " and " + providerSpecificConf.key());
  13. }
  14. String keyName = providerSpecificConf.name();
  15. if (configKeyToService.containsKey(keyName)) {
  16. service.set(configKeyToService.get(keyName));
  17. } else {
  18. throw new SecurityException("Configuration key " + providerSpecificConf.key()
  19. + " is not a valid provider configuration. Supported keys: "
  20. + knownKeys);
  21. }
  22. });
  23. }

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

  1. private List<Object> createArguments(Config configNode) {
  2. List<Object> arguments = new ArrayList<>(parameterValueProviders.size());
  3. parameterValueProviders.forEach((name, propertyWrapper) -> {
  4. Config subConfig = configNode.get(name);
  5. Object argument = propertyWrapper
  6. .get(subConfig)
  7. .orElseThrow(() -> new ConfigMappingException(configNode.key(),
  8. type,
  9. "Missing value for parameter '" + name + "'."));
  10. arguments.add(argument);
  11. });
  12. return arguments;
  13. }

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

  1. /**
  2. * Computes the difference between the first {@code Config} and the second
  3. * one.
  4. * @param origConfig original configuration
  5. * @param newConfig newer configuration
  6. * @return {@code ConfigDiff} representing the changes
  7. */
  8. static ConfigDiff from(Config origConfig, Config newConfig) {
  9. Stream<Config> forward = origConfig.traverse()
  10. .filter(origNode -> notEqual(origNode, newConfig.get(origNode.key())));
  11. Stream<Config> backward = newConfig.traverse()
  12. .filter(newNode -> notEqual(newNode, origConfig.get(newNode.key())));
  13. Set<Config.Key> changedKeys = Stream.concat(forward, backward)
  14. .map(Config::key)
  15. .distinct()
  16. .flatMap(ConfigDiff::expandKey)
  17. .distinct()
  18. .collect(toSet());
  19. return new ConfigDiff(newConfig, changedKeys);
  20. }

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

  1. @Override
  2. public T apply(Config config) throws ConfigMappingException, MissingValueException {
  3. try {
  4. return type.cast(methodHandle.invoke(invokeParameter(config)));
  5. } catch (ConfigMappingException ex) {
  6. throw ex;
  7. } catch (Throwable ex) {
  8. throw new ConfigMappingException(config.key(), type,
  9. "Invocation of " + methodName + " has failed with an exception.", ex);
  10. }
  11. }
  12. }

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

  1. private static Config findMyKey(Config rootConfig, String providerName) {
  2. if (rootConfig.key().name().equals(providerName)) {
  3. return rootConfig;
  4. }
  5. return rootConfig.get("security.providers")
  6. .asNodeList()
  7. .get()
  8. .stream()
  9. .filter(it -> it.get(providerName).exists())
  10. .findFirst()
  11. .map(it -> it.get(providerName))
  12. .orElseThrow(() -> new SecurityException("No configuration found for provider named: " + providerName));
  13. }

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

  1. static <T> ConfigValue<List<T>> createList(Config config,
  2. Function<Config, ConfigValue<T>> getValue,
  3. Function<Config, ConfigValue<List<T>>> getListValue) {
  4. Supplier<Optional<List<T>>> valueSupplier = () -> {
  5. try {
  6. return config.asNodeList()
  7. .map(list -> list.stream()
  8. .map(theConfig -> getValue.apply(theConfig).get())
  9. .collect(Collectors.toList())
  10. );
  11. } catch (MissingValueException | ConfigMappingException ex) {
  12. throw new ConfigMappingException(config.key(),
  13. "Error to map complex node item to list. " + ex.getLocalizedMessage(),
  14. ex);
  15. }
  16. };
  17. return new GenericConfigValueImpl<>(config, valueSupplier, getListValue);
  18. }

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

  1. public T create(Config config) {
  2. try {
  3. Object builder = builderType.cast(builderHandler.invoke());
  4. for (PropertyAccessor<?> builderAccessor : builderAccessors) {
  5. builderAccessor.set(builder, config.get(builderAccessor.name()));
  6. }
  7. return buildType.cast(buildHandler.invoke(builder));
  8. } catch (ConfigMappingException ex) {
  9. throw ex;
  10. } catch (Throwable ex) {
  11. throw new ConfigMappingException(
  12. config.key(),
  13. buildType,
  14. "Builder java bean initialization has failed with an exception.",
  15. ex);
  16. }
  17. }
  18. }

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

  1. @Override
  2. public T apply(Config config) throws ConfigMappingException, MissingValueException {
  3. try {
  4. T instance = type.cast(constructorHandle.invoke());
  5. for (PropertyAccessor<?> propertyAccessor : propertyAccessors) {
  6. propertyAccessor.set(instance, config.get(propertyAccessor.name()));
  7. }
  8. return instance;
  9. } catch (ConfigMappingException ex) {
  10. throw ex;
  11. } catch (Throwable ex) {
  12. throw new ConfigMappingException(
  13. config.key(),
  14. type,
  15. "Generic java bean initialization has failed with an exception.",
  16. ex);
  17. }
  18. }
  19. }

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

  1. private void registerRouting(Routing.Rules routing) {
  2. Config wsConfig = config.get("web-server");
  3. SecurityHandler defaults = SecurityHandler.create(wsConfig.get("defaults"), defaultHandler);
  4. wsConfig.get("paths").asNodeList().ifPresent(configs -> {
  5. for (Config pathConfig : configs) {
  6. List<Http.RequestMethod> methods = pathConfig.get("methods").asNodeList().orElse(listOf())
  7. .stream()
  8. .map(Config::asString)
  9. .map(ConfigValue::get)
  10. .map(Http.RequestMethod::create)
  11. .collect(Collectors.toList());
  12. String path = pathConfig.get("path")
  13. .asString()
  14. .orElseThrow(() -> new SecurityException(pathConfig
  15. .key() + " must contain path key with a path to "
  16. + "register to web server"));
  17. if (methods.isEmpty()) {
  18. routing.any(path, SecurityHandler.create(pathConfig, defaults));
  19. } else {
  20. routing.anyOf(methods, path, SecurityHandler.create(pathConfig, defaults));
  21. }
  22. }
  23. });
  24. }
  25. }

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

  1. /**
  2. * Update this builder from configuration.
  3. *
  4. * @param config configuration instance located on {@link PolicyValidatorService#configKey()}
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. this.config = config;
  9. config.get("validators").asList(Config.class).ifPresent(configs -> {
  10. for (Config validatorConfig : configs) {
  11. validatorConfig.get("class").asString()
  12. .ifPresentOrElse(clazz -> {
  13. //attempt to instantiate
  14. addExecutor(instantiate(clazz));
  15. }, () -> {
  16. throw new SecurityException(
  17. "validators key may only contain an array of class to class names, at key: "
  18. + validatorConfig.key());
  19. });
  20. }
  21. });
  22. return this;
  23. }

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

  1. public <T> Function<T, Supplier<PollingStrategy>> apply(Config config, Class<T> targetType)
  2. throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this
  8. .builtin(type, properties, targetType))) // return built-in polling strategy
  9. .or(() -> config.get(CLASS_KEY)
  10. .as(Class.class) // `class` is specified
  11. .flatMap(clazz -> custom(clazz, properties, targetType))) // return custom polling strategy
  12. .asOptional()
  13. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted polling-strategy configuration."));
  14. }

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

  1. @Override
  2. public RetryPolicy apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
  7. .flatMap(type -> this.builtin(type, properties))) // return built-in retry policy
  8. .or(() -> config.get(CLASS_KEY)
  9. .as(Class.class) // `class` is specified
  10. .flatMap(clazz -> custom(clazz, properties))) // return custom retry policy
  11. .asOptional()
  12. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted retry-policy configuration."));
  13. }

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

  1. @Override
  2. public ConfigSource apply(Config config) throws ConfigMappingException, MissingValueException {
  3. Config properties = config.get(PROPERTIES_KEY) // use properties config node
  4. .asNode()
  5. .orElse(Config.empty(config)); // or empty config node
  6. return OptionalHelper.from(config.get(TYPE_KEY)
  7. .asString() // `type` is specified
  8. .flatMap(type -> OptionalHelper
  9. .from(builtin(type, properties)) // return built-in source
  10. .or(() -> providers(type, properties))
  11. .asOptional())) // or use sources - custom type to class mapping
  12. .or(() -> config.get(CLASS_KEY)
  13. .as(Class.class) // `class` is specified
  14. .flatMap(clazz -> custom(clazz, properties))) // return custom source
  15. .asOptional()
  16. .orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted source configuration."));
  17. }

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

  1. @Override
  2. public ZipkinTracerBuilder config(Config config) {
  3. config.get("service").asString().ifPresent(this::serviceName);
  4. config.get("protocol").asString().ifPresent(this::collectorProtocol);
  5. config.get("host").asString().ifPresent(this::collectorHost);
  6. config.get("port").asInt().ifPresent(this::collectorPort);
  7. config.get("path").asString().ifPresent(this::collectorPath);
  8. config.get("api-version").asString().ifPresent(this::configApiVersion);
  9. config.get("enabled").asBoolean().ifPresent(this::enabled);
  10. config.get("tags").detach()
  11. .asMap()
  12. .orElseGet(CollectionsHelper::mapOf)
  13. .forEach(this::addTracerTag);
  14. config.get("boolean-tags")
  15. .asNodeList()
  16. .ifPresent(nodes -> {
  17. nodes.forEach(node -> {
  18. this.addTracerTag(node.key().name(), node.asBoolean().get());
  19. });
  20. });
  21. config.get("int-tags")
  22. .asNodeList()
  23. .ifPresent(nodes -> {
  24. nodes.forEach(node -> {
  25. this.addTracerTag(node.key().name(), node.asInt().get());
  26. });
  27. });
  28. return this;
  29. }

相关文章