本文整理了Java中io.helidon.config.Config.detach()
方法的一些代码示例,展示了Config.detach()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.detach()
方法的具体详情如下:
包路径:io.helidon.config.Config
类名称:Config
方法名:detach
[英]Returns a copy of the Config node with no parent.
The returned node acts as a root node for the subtree below it. Its key is the empty string; "". The original config node is unchanged, and the original and the copy point to the same children.
Consider the following configuration:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
The Config instances name1 and name2 represents same data and in fact refer to the same object:
Config name1 = config
.get("app")
.get("name");
Config name2 = config
.get("app")
.detach() //DETACHED node
.get("name");
assert name1.asString() == "Example 1";
assert name2.asString() == "Example 1"; //DETACHED node
The only difference is the key each node returns:
assert name1.key() == "app.name";
assert name2.key() == "name"; //DETACHED node
See #asMap() for example of config detaching.
[中]返回没有父节点的配置节点的副本。
返回的节点充当其下子树的根节点。它的键是空字符串;"". 原始配置节点不变,并且原始和副本指向相同的子节点。
考虑以下配置:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
配置实例name1和name2表示相同的数据,实际上引用相同的对象:
Config name1 = config
.get("app")
.get("name");
Config name2 = config
.get("app")
.detach() //DETACHED node
.get("name");
assert name1.asString() == "Example 1";
assert name2.asString() == "Example 1"; //DETACHED node
唯一的区别是每个节点返回的键:
assert name1.key() == "app.name";
assert name2.key() == "name"; //DETACHED node
有关配置分离的示例,请参见#asMap()。
代码示例来源:origin: oracle/helidon
private Config contextConfig(Config rootConfig) {
return rootConfig
.get(AbstractConfigImpl.this.prefix)
.detach()
.get(AbstractConfigImpl.this.key);
}
代码示例来源:origin: oracle/helidon
private SeContainer createContainter(ClassLoader classLoader) {
// not in CDI
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
initializer.setClassLoader(classLoader);
Map<String, Object> props = new HashMap<>(config.helidonConfig()
.get("cdi")
.detach()
.asMap()
.orElse(CollectionsHelper.mapOf()));
initializer.setProperties(props);
// add resource classes explicitly configured without CDI annotations
this.resourceClasses.stream()
.filter(this::notACdiBean)
.forEach(initializer::addBeanClasses);
STARTUP_LOGGER.finest("Initializer");
SeContainer container = initializer.initialize();
STARTUP_LOGGER.finest("Initalizer.initialize()");
return container;
}
代码示例来源:origin: oracle/helidon
/**
* {@inheritDoc}
* <ul>
* <li>{@code media-type-mapping} - type {@code Map} - key to media type, see {@link #mediaTypeMapping(Function)}</li>
* </ul>
*
* @param metaConfig configuration properties used to initialize a builder instance.
* @return modified builder instance
*/
@Override
protected B init(Config metaConfig) {
//media-type-mapping
metaConfig.get(MEDIA_TYPE_MAPPING_KEY).detach().asMap()
.ifPresent(this::initMediaTypeMapping);
return super.init(metaConfig);
}
代码示例来源:origin: oracle/helidon
return mpConfig.helidonConfig().get(configKey).detach().asMap();
} else if (rawType.isAssignableFrom(Set.class)) {
return mpConfig.asSet(configKey, typeArg);
代码示例来源: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;
}
代码示例来源:origin: io.helidon.config/helidon-config
private Config contextConfig(Config rootConfig) {
return rootConfig
.get(AbstractConfigImpl.this.prefix)
.detach()
.get(AbstractConfigImpl.this.key);
}
代码示例来源:origin: io.helidon.microprofile.server/helidon-microprofile-server
private SeContainer createContainter(ClassLoader classLoader) {
// not in CDI
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
initializer.setClassLoader(classLoader);
Map<String, Object> props = new HashMap<>(config.helidonConfig()
.get("cdi")
.detach()
.asMap()
.orElse(CollectionsHelper.mapOf()));
initializer.setProperties(props);
// add resource classes explicitly configured without CDI annotations
this.resourceClasses.stream()
.filter(this::notACdiBean)
.forEach(initializer::addBeanClasses);
STARTUP_LOGGER.finest("Initializer");
SeContainer container = initializer.initialize();
STARTUP_LOGGER.finest("Initalizer.initialize()");
return container;
}
代码示例来源:origin: io.helidon.config/helidon-config
/**
* {@inheritDoc}
* <ul>
* <li>{@code media-type-mapping} - type {@code Map} - key to media type, see {@link #mediaTypeMapping(Function)}</li>
* </ul>
*
* @param metaConfig configuration properties used to initialize a builder instance.
* @return modified builder instance
*/
@Override
protected B init(Config metaConfig) {
//media-type-mapping
metaConfig.get(MEDIA_TYPE_MAPPING_KEY).detach().asMap()
.ifPresent(this::initMediaTypeMapping);
return super.init(metaConfig);
}
代码示例来源:origin: io.helidon.microprofile.config/helidon-microprofile-config-cdi
return mpConfig.helidonConfig().get(configKey).detach().asMap();
} else if (rawType.isAssignableFrom(Set.class)) {
return mpConfig.asSet(configKey, typeArg);
内容来源于网络,如有侵权,请联系作者删除!