本文整理了Java中org.xnio.Option.parseValue()
方法的一些代码示例,展示了Option.parseValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.parseValue()
方法的具体详情如下:
包路径:org.xnio.Option
类名称:Option
方法名:parseValue
[英]Parse a string value for this option.
[中]分析此选项的字符串值。
代码示例来源:origin: wildfly/wildfly
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue) {
set(key, key.parseValue(stringValue, key.getClass().getClassLoader()));
return this;
}
代码示例来源:origin: wildfly/wildfly
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param classLoader the class loader to use for parsing the value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue, ClassLoader classLoader) {
set(key, key.parseValue(stringValue, classLoader));
return this;
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings("rawtypes")
private static Consumer<Map.Entry<String, ConfigValue>> setOption(final Config config,
final String level,
final BiConsumer<Option, Object> setter) {
return entry -> {
String name = entry.getKey();
Object value = entry.getValue().unwrapped();
Option option = findOption(name, UndertowOptions.class, Options.class);
if (option != null) {
// parse option to adjust correct type
Object parsedValue = value.toString();
try {
parsedValue = option.parseValue(value.toString(), null);
} catch (NumberFormatException ex) {
// try bytes
try {
parsedValue = option.parseValue(config.getBytes(level + "." + name).toString(), null);
} catch (ConfigException.BadValue badvalue) {
// try duration
parsedValue = option.parseValue(
config.getDuration(level + "." + name, TimeUnit.MILLISECONDS) + "", null);
}
}
log.debug("{}.{}({})", level, option.getName(), parsedValue);
setter.accept(option, parsedValue);
} else {
log.error("Unknown option: 'undertow.{}.{} = {}'", level, name, value);
}
};
}
代码示例来源:origin: wildfly/wildfly
private OptionMap createChannelOptionMap(final OperationContext context, final ModelNode channelCreationOptionsNode)
throws OperationFailedException {
final OptionMap optionMap;
if (channelCreationOptionsNode.isDefined()) {
final OptionMap.Builder optionMapBuilder = OptionMap.builder();
final ClassLoader loader = this.getClass().getClassLoader();
for (final Property optionProperty : channelCreationOptionsNode.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE
.resolveModelAttribute(context, propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE
.resolveModelAttribute(context, propValueModel).asString();
optionMapBuilder.set(option, option.parseValue(value, loader));
}
optionMap = optionMapBuilder.getMap();
} else {
optionMap = OptionMap.EMPTY;
}
return optionMap;
}
代码示例来源:origin: wildfly/wildfly
private OptionMap getChannelCreationOptions(final OperationContext context) throws OperationFailedException {
// read the full model of the current resource
final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
final ModelNode channelCreationOptions = fullModel.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
if (channelCreationOptions.isDefined() && channelCreationOptions.asInt() > 0) {
final ClassLoader loader = this.getClass().getClassLoader();
final OptionMap.Builder builder = OptionMap.builder();
for (final Property optionProperty : channelCreationOptions.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context,propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
builder.set(option, option.parseValue(value, loader));
}
return builder.getMap();
}
return OptionMap.EMPTY;
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue) {
set(key, key.parseValue(stringValue, key.getClass().getClassLoader()));
return this;
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param classLoader the class loader to use for parsing the value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue, ClassLoader classLoader) {
set(key, key.parseValue(stringValue, classLoader));
return this;
}
代码示例来源:origin: org.jooby/jooby-undertow
@SuppressWarnings("rawtypes")
private static Consumer<Map.Entry<String, ConfigValue>> setOption(final Config config,
final String level,
final BiConsumer<Option, Object> setter) {
return entry -> {
String name = entry.getKey();
Object value = entry.getValue().unwrapped();
Option option = findOption(name, UndertowOptions.class, Options.class);
if (option != null) {
// parse option to adjust correct type
Object parsedValue = value.toString();
try {
parsedValue = option.parseValue(value.toString(), null);
} catch (NumberFormatException ex) {
// try bytes
try {
parsedValue = option.parseValue(config.getBytes(level + "." + name).toString(), null);
} catch (ConfigException.BadValue badvalue) {
// try duration
parsedValue = option.parseValue(
config.getDuration(level + "." + name, TimeUnit.MILLISECONDS) + "", null);
}
}
log.debug("{}.{}({})", level, option.getName(), parsedValue);
setter.accept(option, parsedValue);
} else {
log.error("Unknown option: 'undertow.{}.{} = {}'", level, name, value);
}
};
}
代码示例来源:origin: org.jboss.as/jboss-as-remoting
private static void addOptions(OperationContext context, ModelNode properties, OptionMap.Builder builder) throws OperationFailedException {
final ClassLoader loader = SecurityActions.getClassLoader(ConnectorResource.class);
for (Property property : properties.asPropertyList()) {
String name = property.getName();
if (!name.contains(".")) {
name = "org.xnio.Options." + name;
}
final Option option = Option.fromString(name, loader);
String value = PropertyResource.VALUE.resolveModelAttribute(context, property.getValue()).asString();
builder.set(option, option.parseValue(value, loader));
}
}
代码示例来源:origin: wildfly/wildfly-core
@SuppressWarnings("unchecked")
public OptionMap.Builder resolveOption(final ExpressionResolver context, final ModelNode model, OptionMap.Builder builder) throws OperationFailedException {
ModelNode value = resolveModelAttribute(context, model);
if (value.isDefined()) {
if (getType() == ModelType.INT) {
builder.set((Option<Integer>) option, value.asInt());
} else if (getType() == ModelType.LONG) {
builder.set(option, value.asLong());
} else if (getType() == ModelType.BOOLEAN) {
builder.set(option, value.asBoolean());
} else if (optionType.isEnum()) {
builder.set(option, option.parseValue(value.asString(), option.getClass().getClassLoader()));
}else if (option.getClass().getSimpleName().equals("SequenceOption")) {
builder.setSequence(option, value.asString().split("\\s*,\\s*"));
} else if (getType() == ModelType.STRING) {
builder.set(option, value.asString());
} else {
throw new OperationFailedException("Don't know how to handle: " + option + " with value: " + value);
}
}
return builder;
}
代码示例来源:origin: org.wildfly.core/wildfly-io
@SuppressWarnings("unchecked")
public OptionMap.Builder resolveOption(final ExpressionResolver context, final ModelNode model, OptionMap.Builder builder) throws OperationFailedException {
ModelNode value = resolveModelAttribute(context, model);
if (value.isDefined()) {
if (getType() == ModelType.INT) {
builder.set((Option<Integer>) option, value.asInt());
} else if (getType() == ModelType.LONG) {
builder.set(option, value.asLong());
} else if (getType() == ModelType.BOOLEAN) {
builder.set(option, value.asBoolean());
} else if (optionType.isEnum()) {
builder.set(option, option.parseValue(value.asString(), option.getClass().getClassLoader()));
}else if (option.getClass().getSimpleName().equals("SequenceOption")) {
builder.setSequence(option, value.asString().split("\\s*,\\s*"));
} else if (getType() == ModelType.STRING) {
builder.set(option, value.asString());
} else {
throw new OperationFailedException("Don't know how to handle: " + option + " with value: " + value);
}
}
return builder;
}
代码示例来源:origin: wildfly/wildfly-core
private static void addOptions(OperationContext context, ModelNode properties, OptionMap.Builder builder) throws OperationFailedException {
final ClassLoader loader = WildFlySecurityManager.getClassLoaderPrivileged(ConnectorUtils.class);
for (Property property : properties.asPropertyList()) {
final Option option = getAndValidateOption(loader, property.getName());
String value = PropertyResource.VALUE.resolveModelAttribute(context, property.getValue()).asString();
builder.set(option, option.parseValue(value, loader));
}
}
代码示例来源:origin: org.jboss.as/jboss-as-ejb3
private OptionMap getChannelCreationOptions(final OperationContext context) throws OperationFailedException {
// read the full model of the current resource
final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
final ModelNode channelCreationOptions = fullModel.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
if (channelCreationOptions.isDefined() && channelCreationOptions.asInt() > 0) {
final ClassLoader loader = this.getClass().getClassLoader();
final OptionMap.Builder builder = OptionMap.builder();
for (final Property optionProperty : channelCreationOptions.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = ChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context,propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = ChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
builder.set(option, option.parseValue(value, loader));
}
return builder.getMap();
} else {
return OptionMap.EMPTY;
}
}
代码示例来源:origin: org.apache.camel/camel-undertow
value = option.parseValue(value.toString(), cl);
LOG.trace("Parsed option {}={}", option.getName(), value);
builder.set(option, value);
内容来源于网络,如有侵权,请联系作者删除!