本文整理了Java中io.helidon.config.Config.key()
方法的一些代码示例,展示了Config.key()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.key()
方法的具体详情如下:
包路径:io.helidon.config.Config
类名称: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
private GenericConfigValueImpl(Config owningConfig,
Supplier<Optional<T>> valueSupplier,
Function<Config, ConfigValue<T>> configMethod) {
super(owningConfig.key());
this.owningConfig = owningConfig;
this.valueSupplier = valueSupplier;
this.configMethod = configMethod;
}
代码示例来源:origin: oracle/helidon
@Override
public T apply(Config config, ConfigMapper configMapper) {
throw new ConfigMappingException(config.key(), type, "No mapper configured");
}
代码示例来源:origin: oracle/helidon
private void findProviderSpecificConfig(Config pConf, AtomicReference<Config> providerSpecific) {
// no service for this class, must choose the configuration by selection
pConf.asNodeList().get().stream().filter(this::notReservedProviderKey).forEach(providerSpecificConf -> {
if (!providerSpecific.compareAndSet(null, providerSpecificConf)) {
throw new SecurityException("More than one provider configurations found, each provider can only"
+ " have one provide specific config. Conflict: "
+ providerSpecific.get().key()
+ " and " + providerSpecificConf.key());
}
});
}
代码示例来源:origin: oracle/helidon
/**
* Utility method wrapping an arbitrary mapper and ensuring proper exceptions are produced if needed.
*
* @param mapper mapping function. Function throws {@link ConfigMappingException} in case the value cannot be mapped.
* @param <T> mapped Java type.
* @return mapped value.
*/
private static <T> Function<Config, T> wrapMapper(Function<Config, T> mapper) {
return (node) -> {
try {
return mapper.apply(node);
} catch (MissingValueException | ConfigMappingException ex) {
throw ex;
} catch (RuntimeException ex) {
throw new ConfigMappingException(
node.key(), "Invocation of mapper '" + mapper + "' has failed with an exception.", ex);
}
};
}
代码示例来源:origin: oracle/helidon
@Override
public <T> T map(Config config, GenericType<T> type) throws MissingValueException, ConfigMappingException {
Mapper<?> mapper = mappers.computeIfAbsent(type, theType -> findMapper(theType, config.key()));
return cast(type, mapper.apply(config, this), config.key());
}
代码示例来源:origin: oracle/helidon
/**
* Wrap a simple String value mapping function into a contextual mapper.
*
* @param mapper arbitrary String configuration value to a Java type mapping function.
* @param <T> mapped Java type.
* @return contextual mapper wrapping the simple String value mapping function.
* @throws MissingValueException in case the configuration node does not represent an existing configuration node.
* @throws ConfigMappingException in case the mapper fails to map the existing configuration value
* to an instance of a given Java type.
*/
static <T> Function<Config, T> wrap(Function<String, T> mapper) {
return (node) -> nodeValue(node)
.map(value -> safeMap(node.key(), value, mapper))
.orElseThrow(MissingValueException.createSupplier(node.key()));
}
代码示例来源:origin: oracle/helidon
private void findProviderService(Map<String, SecurityProviderService> configKeyToService,
String knownKeys,
Config pConf,
AtomicReference<SecurityProviderService> service,
AtomicReference<Config> providerSpecific) {
// everything else is based on provider specific configuration
pConf.asNodeList().get().stream().filter(this::notReservedProviderKey).forEach(providerSpecificConf -> {
if (!providerSpecific.compareAndSet(null, providerSpecificConf)) {
throw new SecurityException("More than one provider configurations found, each provider can only"
+ " have one provider specific config. Conflict: "
+ providerSpecific.get().key()
+ " and " + providerSpecificConf.key());
}
String keyName = providerSpecificConf.name();
if (configKeyToService.containsKey(keyName)) {
service.set(configKeyToService.get(keyName));
} else {
throw new SecurityException("Configuration key " + providerSpecificConf.key()
+ " is not a valid provider configuration. Supported keys: "
+ knownKeys);
}
});
}
代码示例来源:origin: oracle/helidon
private List<Object> createArguments(Config configNode) {
List<Object> arguments = new ArrayList<>(parameterValueProviders.size());
parameterValueProviders.forEach((name, propertyWrapper) -> {
Config subConfig = configNode.get(name);
Object argument = propertyWrapper
.get(subConfig)
.orElseThrow(() -> new ConfigMappingException(configNode.key(),
type,
"Missing value for parameter '" + name + "'."));
arguments.add(argument);
});
return arguments;
}
代码示例来源:origin: oracle/helidon
/**
* Computes the difference between the first {@code Config} and the second
* one.
* @param origConfig original configuration
* @param newConfig newer configuration
* @return {@code ConfigDiff} representing the changes
*/
static ConfigDiff from(Config origConfig, Config newConfig) {
Stream<Config> forward = origConfig.traverse()
.filter(origNode -> notEqual(origNode, newConfig.get(origNode.key())));
Stream<Config> backward = newConfig.traverse()
.filter(newNode -> notEqual(newNode, origConfig.get(newNode.key())));
Set<Config.Key> changedKeys = Stream.concat(forward, backward)
.map(Config::key)
.distinct()
.flatMap(ConfigDiff::expandKey)
.distinct()
.collect(toSet());
return new ConfigDiff(newConfig, changedKeys);
}
代码示例来源:origin: oracle/helidon
@Override
public T apply(Config config) throws ConfigMappingException, MissingValueException {
try {
return type.cast(methodHandle.invoke(invokeParameter(config)));
} catch (ConfigMappingException ex) {
throw ex;
} catch (Throwable ex) {
throw new ConfigMappingException(config.key(), type,
"Invocation of " + methodName + " has failed with an exception.", ex);
}
}
}
代码示例来源: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
static <T> ConfigValue<List<T>> createList(Config config,
Function<Config, ConfigValue<T>> getValue,
Function<Config, ConfigValue<List<T>>> getListValue) {
Supplier<Optional<List<T>>> valueSupplier = () -> {
try {
return config.asNodeList()
.map(list -> list.stream()
.map(theConfig -> getValue.apply(theConfig).get())
.collect(Collectors.toList())
);
} catch (MissingValueException | ConfigMappingException ex) {
throw new ConfigMappingException(config.key(),
"Error to map complex node item to list. " + ex.getLocalizedMessage(),
ex);
}
};
return new GenericConfigValueImpl<>(config, valueSupplier, getListValue);
}
代码示例来源:origin: oracle/helidon
public T create(Config config) {
try {
Object builder = builderType.cast(builderHandler.invoke());
for (PropertyAccessor<?> builderAccessor : builderAccessors) {
builderAccessor.set(builder, config.get(builderAccessor.name()));
}
return buildType.cast(buildHandler.invoke(builder));
} catch (ConfigMappingException ex) {
throw ex;
} catch (Throwable ex) {
throw new ConfigMappingException(
config.key(),
buildType,
"Builder java bean initialization has failed with an exception.",
ex);
}
}
}
代码示例来源:origin: oracle/helidon
@Override
public T apply(Config config) throws ConfigMappingException, MissingValueException {
try {
T instance = type.cast(constructorHandle.invoke());
for (PropertyAccessor<?> propertyAccessor : propertyAccessors) {
propertyAccessor.set(instance, config.get(propertyAccessor.name()));
}
return instance;
} catch (ConfigMappingException ex) {
throw ex;
} catch (Throwable ex) {
throw new ConfigMappingException(
config.key(),
type,
"Generic java bean initialization has failed with an exception.",
ex);
}
}
}
代码示例来源:origin: oracle/helidon
private void registerRouting(Routing.Rules routing) {
Config wsConfig = config.get("web-server");
SecurityHandler defaults = SecurityHandler.create(wsConfig.get("defaults"), defaultHandler);
wsConfig.get("paths").asNodeList().ifPresent(configs -> {
for (Config pathConfig : configs) {
List<Http.RequestMethod> methods = pathConfig.get("methods").asNodeList().orElse(listOf())
.stream()
.map(Config::asString)
.map(ConfigValue::get)
.map(Http.RequestMethod::create)
.collect(Collectors.toList());
String path = pathConfig.get("path")
.asString()
.orElseThrow(() -> new SecurityException(pathConfig
.key() + " must contain path key with a path to "
+ "register to web server"));
if (methods.isEmpty()) {
routing.any(path, SecurityHandler.create(pathConfig, defaults));
} else {
routing.anyOf(methods, path, SecurityHandler.create(pathConfig, defaults));
}
}
});
}
}
代码示例来源:origin: oracle/helidon
/**
* Update this builder from configuration.
*
* @param config configuration instance located on {@link PolicyValidatorService#configKey()}
* @return updated builder instance
*/
public Builder config(Config config) {
this.config = config;
config.get("validators").asList(Config.class).ifPresent(configs -> {
for (Config validatorConfig : configs) {
validatorConfig.get("class").asString()
.ifPresentOrElse(clazz -> {
//attempt to instantiate
addExecutor(instantiate(clazz));
}, () -> {
throw new SecurityException(
"validators key may only contain an array of class to class names, at key: "
+ validatorConfig.key());
});
}
});
return this;
}
代码示例来源:origin: oracle/helidon
public <T> Function<T, Supplier<PollingStrategy>> apply(Config config, Class<T> targetType)
throws ConfigMappingException, MissingValueException {
Config properties = config.get(PROPERTIES_KEY) // use properties config node
.asNode()
.orElse(Config.empty(config)); // or empty config node
return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
.flatMap(type -> this
.builtin(type, properties, targetType))) // return built-in polling strategy
.or(() -> config.get(CLASS_KEY)
.as(Class.class) // `class` is specified
.flatMap(clazz -> custom(clazz, properties, targetType))) // return custom polling strategy
.asOptional()
.orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted polling-strategy configuration."));
}
代码示例来源:origin: oracle/helidon
@Override
public RetryPolicy apply(Config config) throws ConfigMappingException, MissingValueException {
Config properties = config.get(PROPERTIES_KEY) // use properties config node
.asNode()
.orElse(Config.empty(config)); // or empty config node
return OptionalHelper.from(config.get(TYPE_KEY).asString() // `type` is specified
.flatMap(type -> this.builtin(type, properties))) // return built-in retry policy
.or(() -> config.get(CLASS_KEY)
.as(Class.class) // `class` is specified
.flatMap(clazz -> custom(clazz, properties))) // return custom retry policy
.asOptional()
.orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted retry-policy configuration."));
}
代码示例来源:origin: oracle/helidon
@Override
public ConfigSource apply(Config config) throws ConfigMappingException, MissingValueException {
Config properties = config.get(PROPERTIES_KEY) // use properties config node
.asNode()
.orElse(Config.empty(config)); // or empty config node
return OptionalHelper.from(config.get(TYPE_KEY)
.asString() // `type` is specified
.flatMap(type -> OptionalHelper
.from(builtin(type, properties)) // return built-in source
.or(() -> providers(type, properties))
.asOptional())) // or use sources - custom type to class mapping
.or(() -> config.get(CLASS_KEY)
.as(Class.class) // `class` is specified
.flatMap(clazz -> custom(clazz, properties))) // return custom source
.asOptional()
.orElseThrow(() -> new ConfigMappingException(config.key(), "Uncompleted source configuration."));
}
代码示例来源:origin: oracle/helidon
@Override
public ZipkinTracerBuilder config(Config config) {
config.get("service").asString().ifPresent(this::serviceName);
config.get("protocol").asString().ifPresent(this::collectorProtocol);
config.get("host").asString().ifPresent(this::collectorHost);
config.get("port").asInt().ifPresent(this::collectorPort);
config.get("path").asString().ifPresent(this::collectorPath);
config.get("api-version").asString().ifPresent(this::configApiVersion);
config.get("enabled").asBoolean().ifPresent(this::enabled);
config.get("tags").detach()
.asMap()
.orElseGet(CollectionsHelper::mapOf)
.forEach(this::addTracerTag);
config.get("boolean-tags")
.asNodeList()
.ifPresent(nodes -> {
nodes.forEach(node -> {
this.addTracerTag(node.key().name(), node.asBoolean().get());
});
});
config.get("int-tags")
.asNodeList()
.ifPresent(nodes -> {
nodes.forEach(node -> {
this.addTracerTag(node.key().name(), node.asInt().get());
});
});
return this;
}
内容来源于网络,如有侵权,请联系作者删除!