本文整理汇总了Java中org.apache.commons.configuration.ConversionException类的典型用法代码示例。如果您正苦于以下问题:Java ConversionException类的具体用法?Java ConversionException怎么用?Java ConversionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConversionException类属于org.apache.commons.configuration包,在下文中一共展示了ConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readDefaultSharedFolders
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
private void readDefaultSharedFolders() {
synchronized (sharedFoldersLock) {
if (!defaultSharedFoldersRead) {
Boolean useDefault;
try {
useDefault = configuration.getBoolean(KEY_USE_DEFAULT_FOLDERS, null);
} catch (ConversionException e) {
useDefault = null;
String useDefaultString = configuration.getString(KEY_USE_DEFAULT_FOLDERS, null);
if (!isBlank(useDefaultString)) {
LOGGER.warn(
"Invalid configured value for {} \"{}\", using default",
KEY_USE_DEFAULT_FOLDERS,
useDefaultString
);
}
}
if (useDefault != null) {
defaultSharedFolders = useDefault.booleanValue();
} else {
defaultSharedFolders = isSharedFoldersEmpty();
}
defaultSharedFoldersRead = true;
}
}
}
示例2: getCustomProgramPath
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Gets the configured custom program {@link Path} from the
* {@link Configuration} using the specified key. If the specified key has
* no value, {@code null} is returned.
*
* @param configurationKey the {@link Configuration} key to use.
* @return The resulting {@link Path} or {@code null}.
* @throws ConfigurationException If the configured value can't be parsed as
* a valid {@link Path}.
*/
@Nullable
public Path getCustomProgramPath(@Nullable String configurationKey) throws ConfigurationException {
if (isBlank(configurationKey) || configuration == null) {
return null;
}
try {
String configuredPath = configuration.getString(configurationKey);
if (isBlank(configuredPath)) {
return null;
}
return Paths.get(configuredPath);
} catch (ConversionException | InvalidPathException e) {
throw new ConfigurationException(
"Invalid configured custom program path in \"" + configurationKey + "\": " + e.getMessage(),
e
);
}
}
示例3: getOptionValueFromConfig
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
private Object getOptionValueFromConfig(
Option option, Configuration config) {
Object optionValue = null;
try {
if (option.getType().equals(Boolean.class)) {
optionValue = config.getString(option.getLongOpt());
if (optionValue != null) {
optionValue = config.getBoolean(option.getLongOpt());
}
} else {
optionValue = config.getString(option.getLongOpt());
}
} catch (ConversionException cex) {
optionValue = null;
}
return optionValue;
}
示例4: buildConfigurationMap
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
public Map<String,Object> buildConfigurationMap(String key) {
Map<String,Object> config = new HashMap<String, Object>();
config.put("comment",configurationService.getComment(key));
config.put("type",configurationService.getType(key));
config.put("value",configurationService.getConfiguration(key));
if (config.get("type") != null) {
try {
if (((String) config.get("type")).startsWith("java.lang.Integer")) {
config.put("value", configurationService.getIntConfiguration(key));
} else if (((String) config.get("type")).startsWith("java.lang.Boolean")) {
config.put("value", configurationService.getBooleanConfiguration(key));
} else if (((String) config.get("type")).startsWith("java.lang.Double")) {
config.put("value", configurationService.getDoubleConfiguration(key));
} else if (((String) config.get("type")).startsWith("java.lang.Long")) {
config.put("value", configurationService.getLongConfiguration(key));
}
} catch (ConversionException e) {
log.warn("key {} cannot be converted to given type {}", key, config.get("type"));
}
}
return config;
}
示例5: setCustomProgramPathConfiguration
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Sets a new {@link ProgramExecutableType#CUSTOM} {@link Path} in the
* {@link Configuration} for the specified key. No change is done to any
* {@link ExternalProgramInfo} instance. To set the {@link Path} both in the
* {@link Configuration} and in the {@link ExternalProgramInfo} instance in
* one operation, use {@link #setCustomProgramPath}.
*
* @param customPath the new {@link Path} or {@code null} to clear it.
* @param configurationKey the {@link Configuration} key under which to
* store the {@code path}.
* @return {@code true} if a change was made, {@code false} otherwise.
*/
public boolean setCustomProgramPathConfiguration(@Nullable Path customPath, @Nonnull String configurationKey) {
if (isBlank(configurationKey)) {
throw new IllegalArgumentException("configurationKey can't be blank");
}
if (configuration == null) {
return false;
}
if (customPath == null) {
if (configuration.containsKey(configurationKey)) {
configuration.clearProperty(configurationKey);
return true;
}
return false;
}
boolean changed;
try {
String currentValue = configuration.getString(configurationKey);
changed = !customPath.toString().equals(currentValue);
} catch (ConversionException e) {
changed = true;
}
if (changed) {
configuration.setProperty(configurationKey, customPath.toString());
}
return changed;
}
示例6: getInt
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Return the <code>int</code> value for a given configuration key. First, the key
* is looked up in the current configuration settings. If it exists and contains a
* valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
*
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
int getInt(String key, int def) {
int value;
try {
value = configuration.getInt(key, def);
} catch (ConversionException e) {
value = def;
}
log(key, value, def);
return value;
}
示例7: getLong
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Return the <code>long</code> value for a given configuration key. First, the key
* is looked up in the current configuration settings. If it exists and contains a
* valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
*
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
long getLong(String key, long def) {
long value;
try {
value = configuration.getLong(key, def);
} catch (ConversionException e) {
value = def;
}
log(key, value, def);
return value;
}
示例8: getDouble
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Return the <code>double</code> value for a given configuration key. First, the key
* is looked up in the current configuration settings. If it exists and contains a
* valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
*
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
double getDouble(String key, double def) {
double value;
try {
value = configuration.getDouble(key, def);
} catch (ConversionException e) {
value = def;
}
log(key, value, def);
return value;
}
示例9: getBoolean
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
/**
* Return the <code>boolean</code> value for a given configuration key. First, the
* key is looked up in the current configuration settings. If it exists and contains
* a valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
*
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
boolean getBoolean(String key, boolean def) {
boolean value;
try {
value = configuration.getBoolean(key, def);
} catch (ConversionException e) {
value = def;
}
log(key, value, def);
return value;
}
示例10: getRetryCount
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
int getRetryCount() {
try {
int retry = conf.getInt("retry", DEFAULT_RETRY_ATTEMPTS);
retry = Math.max(0, retry);
retry = Math.min(100, retry);
return retry;
} catch (ConversionException ex) {
LOG.log(Level.WARNING, null, ex);
return DEFAULT_RETRY_ATTEMPTS;
}
}
示例11: getTimeout
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
long getTimeout() {
try {
long timeout = conf.getLong(PROP_TIMEOUT, DEFAULT_TIMEOUT);
timeout = Math.max(0, timeout);
return timeout;
} catch (ConversionException ex) {
LOG.log(Level.WARNING, null, ex);
return DEFAULT_TIMEOUT;
}
}
示例12: from
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
public static CejshConfig from(Configuration conf) {
CejshConfig cc = new CejshConfig();
cc.setCejshXslUrl(conf.getString(PROP_MODS_XSL_URL, null));
// cc.setJournalUrl(conf.getString(PROP_JOURNALS_URL, null));
try {
boolean debug = conf.getBoolean(PROP_DEBUG, Boolean.FALSE);
cc.setLogLevel(debug ? Level.INFO : Level.FINE);
} catch (ConversionException ex) {
LOG.log(Level.SEVERE, PROP_DEBUG, ex);
}
return cc;
}
示例13: getJavaScaling
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
private ScalingMethod getJavaScaling(String key) {
String val = config.getString(key);
if (val == null || val.isEmpty()) {
return ScalingMethod.BICUBIC_STEPPED;
}
try {
ScalingMethod hint = ScalingMethod.valueOf(val);
return hint;
} catch (Exception e) {
throw new ConversionException(key, e);
}
}
示例14: getPositiveInteger
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
private Integer getPositiveInteger(String key) {
Integer val = config.getInteger(key, null);
if (val != null && val <= 0) {
throw new ConversionException(key + " expects positive integer!");
}
return val;
}
示例15: getString
import org.apache.commons.configuration.ConversionException; //导入依赖的package包/类
@Override
public String getString(String key, String defaultValue) {
try {
String value = getConfiguration().getString(key, defaultValue);
return value;
} catch (ConversionException e) {
return defaultValue;
}
}