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

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

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

Config.asNodeList介绍

[英]Returns a list of child Config nodes if the node is Type#OBJECT. Returns a list of element nodes if the node is Type#LIST. Throws MissingValueException if the node is Type#MISSING. Otherwise, if node is Type#VALUE, it throws ConfigMappingException.
[中]如果节点类型为#OBJECT,则返回子配置节点的列表。如果节点类型为#list,则返回元素节点列表。如果节点类型#缺失,则引发MissingValueException。否则,如果节点的类型为#VALUE,则会抛出ConfigMappingException。

代码示例

代码示例来源: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. private Stream<Config> traverseSubNodes(Config config, Predicate<Config> predicate) {
  2. if (config.type().isLeaf()) {
  3. return Stream.of(config);
  4. } else {
  5. return config.asNodeList()
  6. .map(list -> list.stream()
  7. .filter(predicate)
  8. .map(node -> traverseSubNodes(node, predicate))
  9. .reduce(Stream.of(config), Stream::concat))
  10. .orElseThrow(MissingValueException.createSupplier(key()));
  11. }
  12. }

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

  1. private SecurityHandler(Builder builder) {
  2. // must copy values to be safely immutable
  3. this.rolesAllowed = builder.rolesAllowed.flatMap(strings -> {
  4. Set<String> newRoles = new HashSet<>(strings);
  5. return Optional.of(newRoles);
  6. });
  7. // must copy values to be safely immutable
  8. this.customObjects = builder.customObjects.flatMap(store -> {
  9. ClassToInstanceStore<Object> ctis = new ClassToInstanceStore<>();
  10. ctis.putAll(store);
  11. return Optional.of(ctis);
  12. });
  13. config = builder.config;
  14. explicitAuthenticator = builder.explicitAuthenticator;
  15. explicitAuthorizer = builder.explicitAuthorizer;
  16. authenticate = builder.authenticate;
  17. authenticationOptional = builder.authenticationOptional;
  18. audited = builder.audited;
  19. auditEventType = builder.auditEventType;
  20. auditMessageFormat = builder.auditMessageFormat;
  21. authorize = builder.authorize;
  22. combined = builder.combined;
  23. queryParamHandlers.addAll(builder.queryParamHandlers);
  24. config.ifPresent(conf -> conf.asNodeList().get().forEach(node -> configMap.put(node.name(), node)));
  25. }

代码示例来源: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. 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. .asNodeList()
  2. .orElse(CollectionsHelper.listOf())
  3. .stream()

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

  1. @Override
  2. public void init(Config config) {
  3. config.get(PROVIDER_NAME + ".auth-method-mapping")
  4. .asNodeList()
  5. .ifPresent(nl -> {
  6. nl.forEach(conf -> {
  7. conf.get("key").asString().ifPresent(key -> {
  8. if (LOGIN_CONFIG_METHOD.equals(key)) {
  9. authenticator = conf.get("provider")
  10. .asString()
  11. .orElse(authenticator);
  12. }
  13. });
  14. });
  15. });
  16. }

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

  1. /**
  2. * Create an instance from config. Expects key "users" to be the current key.
  3. * Example:
  4. * <pre>
  5. * users: [
  6. * {
  7. * login = "jack"
  8. * password = "${CLEAR=password}"
  9. * roles = ["user", "admin"]
  10. * },
  11. * {
  12. * login = "jill"
  13. * # master password is "jungle", password is "password"
  14. * password = "${AES=3XQ8A1RszE9JbXl+lUnnsX0gakuqjnTyp8YJWIAU1D3SiM2TaSnxd6U0/LjrdJYv}"
  15. * roles = ["user"]
  16. * }
  17. * ]
  18. * </pre>
  19. *
  20. * @param config to load this user store from
  21. * @return {@link UserStore} instance
  22. */
  23. public static ConfigUserStore create(Config config) {
  24. ConfigUserStore store = new ConfigUserStore();
  25. config.asNodeList().ifPresent(configs -> configs.forEach(config1 -> {
  26. User user = config1.as(ConfigUser::create).get();
  27. store.users.put(user.login(), user);
  28. }));
  29. return store;
  30. }

代码示例来源: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. * Load header configuration from config.
  3. *
  4. * @param config config instance, expecting object array as children
  5. * @return signed headers configuration loaded from config
  6. */
  7. public static SignedHeadersConfig create(Config config) {
  8. Builder builder = builder();
  9. config.asNodeList().get().forEach(methodConfig -> {
  10. HeadersConfig mc = HeadersConfig.create(methodConfig);
  11. methodConfig.get("method")
  12. .asString()
  13. .ifPresentOrElse(method -> builder.config(method, mc),
  14. () -> builder.defaultConfig(mc));
  15. });
  16. return builder.build();
  17. }

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

  1. /**
  2. * Update fields from configuration.
  3. *
  4. * @param config Configuration
  5. * @return updated builder instance
  6. */
  7. public Builder config(Config config) {
  8. config.get("name").asString().ifPresent(this::name);
  9. config.get("default").asBoolean().ifPresent(this::isDefault);
  10. config.get("authentication").asList(FlaggedProvider::create)
  11. .ifPresent(this.authenticators::addAll);
  12. config.get("authorization").asList(FlaggedProvider::create)
  13. .ifPresent(this.authorizers::addAll);
  14. config.get("outbound").asNodeList()
  15. .ifPresent(configs -> configs.forEach(outConfig -> addOutboundProvider(outConfig.get("name")
  16. .asString()
  17. .get())));
  18. return this;
  19. }

代码示例来源: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. }

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

  1. for (Config socketConfig : socketsConfig.asNodeList().orElse(CollectionsHelper.listOf())) {
  2. String socketName = socketConfig.name();
  3. sockets.put(socketName, configureSocket(socketConfig, SocketConfiguration.builder()).build());

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

  1. private Stream<Config> traverseSubNodes(Config config, Predicate<Config> predicate) {
  2. if (config.type().isLeaf()) {
  3. return Stream.of(config);
  4. } else {
  5. return config.asNodeList()
  6. .map(list -> list.stream()
  7. .filter(predicate)
  8. .map(node -> traverseSubNodes(node, predicate))
  9. .reduce(Stream.of(config), Stream::concat))
  10. .orElseThrow(MissingValueException.createSupplier(key()));
  11. }
  12. }

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

  1. private SecurityHandler(Builder builder) {
  2. // must copy values to be safely immutable
  3. this.rolesAllowed = builder.rolesAllowed.flatMap(strings -> {
  4. Set<String> newRoles = new HashSet<>(strings);
  5. return Optional.of(newRoles);
  6. });
  7. // must copy values to be safely immutable
  8. this.customObjects = builder.customObjects.flatMap(store -> {
  9. ClassToInstanceStore<Object> ctis = new ClassToInstanceStore<>();
  10. ctis.putAll(store);
  11. return Optional.of(ctis);
  12. });
  13. config = builder.config;
  14. explicitAuthenticator = builder.explicitAuthenticator;
  15. explicitAuthorizer = builder.explicitAuthorizer;
  16. authenticate = builder.authenticate;
  17. authenticationOptional = builder.authenticationOptional;
  18. audited = builder.audited;
  19. auditEventType = builder.auditEventType;
  20. auditMessageFormat = builder.auditMessageFormat;
  21. authorize = builder.authorize;
  22. combined = builder.combined;
  23. queryParamHandlers.addAll(builder.queryParamHandlers);
  24. config.ifPresent(conf -> conf.asNodeList().forEach(node -> configMap.put(node.name(), node)));
  25. }

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

  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: io.helidon.config/helidon-config

  1. .asNodeList()
  2. .orElse(CollectionsHelper.listOf())
  3. .stream()

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

  1. @Override
  2. public void init(Config config) {
  3. config.get(PROVIDER_NAME + ".auth-method-mapping")
  4. .asNodeList()
  5. .ifPresent(nl -> {
  6. nl.forEach(conf -> {
  7. conf.get("key").asString().ifPresent(key -> {
  8. if (LOGIN_CONFIG_METHOD.equals(key)) {
  9. authenticator = conf.get("provider")
  10. .asString()
  11. .orElse(authenticator);
  12. }
  13. });
  14. });
  15. });
  16. }

相关文章