本文整理匯總了Java中com.typesafe.config.ConfigException類的典型用法代碼示例。如果您正苦於以下問題:Java ConfigException類的具體用法?Java ConfigException怎麽用?Java ConfigException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ConfigException類屬於com.typesafe.config包,在下文中一共展示了ConfigException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispatchConfig
import com.typesafe.config.ConfigException; //導入依賴的package包/類
private void dispatchConfig(Config config, ConfigCallback callback) {
for (Map.Entry<String, ConfigValue> entry : config.root().entrySet()) {
final String id = entry.getKey();
try {
final Config entryConfig = ((ConfigObject) entry.getValue()).toConfig();
final String type = entryConfig.getString("type");
if (Strings.isNullOrEmpty(type)) {
errors.add(new ConfigurationError("Missing type field for " + id + " (" + entryConfig + ")"));
continue;
}
callback.call(type, id, entryConfig);
} catch (ConfigException e) {
errors.add(new ConfigurationError("[" + id + "] " + e.getMessage()));
}
}
}
示例2: KeyValue
import com.typesafe.config.ConfigException; //導入依賴的package包/類
KeyValue(Map.Entry<String, ConfigValue> keyValue) {
key = keyValue.getKey();
description = createDescription(keyValue.getValue());
try {
if (keyValue.getValue().valueType() == ConfigValueType.NULL) {
valueType = "N/A (null)";
defaultValue = "null";
} else {
valueType = keyValue.getValue().valueType().name().toLowerCase();
defaultValue = render(keyValue.getValue());
}
} catch (ConfigException.NotResolved e) {
valueType = "N/A (unresolved)";
defaultValue = keyValue.getValue().render();
}
}
示例3: RelationExtractionRunner
import com.typesafe.config.ConfigException; //導入依賴的package包/類
public RelationExtractionRunner(Config config) {
// load boolean values
this.exploitCore = config.getBoolean("exploit-core");
this.exploitContexts = config.getBoolean("exploit-contexts");
this.separateNounBased = config.getBoolean("separate-noun-based");
this.separatePurposes = config.getBoolean("separate-purposes");
this.separateAttributions = config.getBoolean("separate-attributions");
// instantiate extractor
String extractorClassName = config.getString("relation-extractor");
try {
Class<?> extractorClass = Class.forName(extractorClassName);
Constructor<?> extractorConst = extractorClass.getConstructor();
this.extractor = (RelationExtractor) extractorConst.newInstance();
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
logger.error("Failed to create instance of {}", extractorClassName);
throw new ConfigException.BadValue("relation-extractor." + extractorClassName, "Failed to create instance.");
}
this.elementCoreExtractionMap = new LinkedHashMap<>();
}
示例4: createBitcoinValidatorFactory
import com.typesafe.config.ConfigException; //導入依賴的package包/類
private BitcoinValidatorFactory createBitcoinValidatorFactory(Config config) {
String chain = config.getString("blockchain.chain");
if ("testnet3".equals(chain)) {
return new BitcoinValidatorFactory(new BitcoinTestnetValidatorConfig());
} else if ("regtest".equals(chain)) {
BitcoinRegtestValidatorConfig bitcoinConfig = new BitcoinRegtestValidatorConfig();
if (config.hasPath("feature") && config.getBoolean("feature.native-assets"))
return new BitcoinValidatorFactory(bitcoinConfig, new NativeAssetValidator(bitcoinConfig));
else
return new BitcoinValidatorFactory(bitcoinConfig);
} else if ("production".equals(chain)) {
return new BitcoinValidatorFactory(new BitcoinProductionValidatorConfig());
} else if ("signedregtest".equals(chain)) {
return new BitcoinValidatorFactory(new SignedRegtestValidatorConfig());
} else {
throw new ConfigException.BadValue(config.origin(), "blockchain.chain", "Invalid chain: " + chain);
}
}
示例5: MiningSettingsFactory
import com.typesafe.config.ConfigException; //導入依賴的package包/類
public MiningSettingsFactory(Config config) {
String minerAddress = null;
try {
Config c = config.getConfig("mining");
if (c != null) {
boolean enabled = c.getBoolean("enabled");
if (!c.hasPath("minerAddress")) {
throw new ConfigException.Missing("mining.minerAddress");
}
minerAddress = c.getString("minerAddress");
if (enabled) {
int delayBetweenMiningBlocksSecs = c.getInt("delayBetweenMiningBlocksSecs");
miningConfig = new MiningConfig(true, minerAddress, delayBetweenMiningBlocksSecs);
} else {
miningConfig = new MiningConfig(false, minerAddress, 0);
}
} else {
miningConfig = MiningConfig.DISABLED;
}
} catch (HyperLedgerException e) {
throw new ConfigException.BadValue(config.origin(), "mining.minerAddress", "Cannot decode the minerAddress: " + minerAddress);
}
}
示例6: toPix
import com.typesafe.config.ConfigException; //導入依賴的package包/類
private int toPix(final Config c, final String key) {
try {
return c.getInt(key);
} catch (ConfigException.WrongType e) {
final String valueStr = c.getString(key);
final Matcher matcher = NUMBER.matcher(valueStr);
if (matcher.matches()) {
float factor = 0;
if ("mm".equals(matcher.group(2))) {
factor = MM_TO_PIXEL;
} else if ("cm".equals(matcher.group(2))) {
factor = CM_TO_PIXEL;
} else if ("pt".equals(matcher.group(2))) {
factor = PT_TO_PIXEL;
}
return Math.round(factor * Float.parseFloat(matcher.group(1)));
} else {
throw new RuntimeException("Exclusion can't be read. String not parsable to a number: " + valueStr);
}
}
}
示例7: testWithTextFile
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@Test
public void testWithTextFile(TestContext tc) {
Async async = tc.async();
retriever = ConfigurationRetriever.create(vertx,
new ConfigurationRetrieverOptions().addStore(
new ConfigurationStoreOptions()
.setType("file")
.setFormat("hocon")
.setConfig(new JsonObject().put("path", "src/test/resources/some-text.txt"))));
retriever.getConfiguration(ar -> {
assertThat(ar.failed()).isTrue();
assertThat(ar.cause()).isNotNull().isInstanceOf(ConfigException.class);
async.complete();
});
}
示例8: validateStorageAccountType
import com.typesafe.config.ConfigException; //導入依賴的package包/類
/**
* Validates that the passed in config object contains a valid storage account types section by
* checking that the param is:
* - not absent, null, or wrong type
* - not an empty list
* - contains only valid Storage Accounts
*
* @param instanceSection the instance section of the Azure Plugin config
* @throws IllegalArgumentException if the list is empty or a storage account type in the list is
* not valid
* @throws ConfigException if the storage account type list config section is missing or the wrong
* type
*/
static void validateStorageAccountType(Config instanceSection) throws IllegalArgumentException,
ConfigException {
List<String> storageAccountTypes = instanceSection
.getStringList(Configurations.AZURE_CONFIG_INSTANCE_STORAGE_ACCOUNT_TYPES);
if (storageAccountTypes.size() == 0) {
throw new IllegalArgumentException(String.format(
"The list of Storage Accounts to validate is empty. Valid types: %s.",
Arrays.asList(SkuName.values())));
}
for (String storageAccountType : storageAccountTypes) {
storageAccountType = Configurations.convertStorageAccountTypeString(storageAccountType);
if (SkuName.fromString(storageAccountType) == null) {
throw new IllegalArgumentException(String.format("Storage Account Type '%s' is not " +
"valid. Valid types: %s, valid deprecated types: %s.",
storageAccountType,
Arrays.asList(SkuName.values()),
Configurations.DEPRECATED_STORAGE_ACCOUNT_TYPES.keySet()));
}
}
}
示例9: handleStartAction
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@FXML
protected void handleStartAction(ActionEvent event) {
try {
clientExecutor.setListeners(Arrays.asList(new ProgressBarUpdater(), new RunButtonUpdater()));
clientExecutor.setConfig(configMap);
clientExecutor.run();
} catch (IllegalArgumentException | NullPointerException | ConfigException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initModality(Modality.APPLICATION_MODAL);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Ошибка");
alert.setHeaderText("Произошла ошибка");
alert.setContentText(e.getMessage());
alert.showAndWait();
}
}
示例10: checkValid
import com.typesafe.config.ConfigException; //導入依賴的package包/類
/**
* Validates given config, returns it on success or throws exception on error
*
* @param config Config to validate
* @return Validated config
* @throws ConfigException.Generic If validation of field fails
*/
public static Config checkValid(Config config) {
ConfigValidator validator = new ConfigValidator(config);
try {
checkNotNull(config);
validator.checkLogLevel();
validator.checkAuth();
validator.checkMode();
validator.checkList();
validator.checkDocumentSourceTypes();
validator.checkComparators();
validator.checkUserAgent();
validator.checkYearDeviation();
validator.checkTimeout();
validator.checkDataBase();
} catch (NullPointerException | IllegalArgumentException e) {
throw new ConfigException.Generic(e.getMessage(), e);
}
return config;
}
示例11: checkList
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@Test
public void checkList() throws Exception {
checkValid(parseMap(configMap));
configMap.replace("list", "");
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
configMap.replace("list", "ls");
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
configMap.replace("list", "0123456");
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
configMap.replace("list", "");
configMap.replace("mode", MovieHandler.Type.SET_RATING.toString());
checkValid(parseMap(configMap));
configMap.remove("list");
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
}
示例12: checkComparators
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@Test
public void checkComparators() throws Exception {
checkValid(parseMap(configMap));
configMap.replace("comparators", Arrays.asList(
MovieComparator.Type.YEAR_EQUALS.toString(),
MovieComparator.Type.TITLE_EQUALS.toString()
));
checkValid(parseMap(configMap));
configMap.replace("comparators", Collections.singletonList("not existing comparator"));
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
configMap.remove("comparators");
assertThatThrownBy(() -> checkValid(parseMap(configMap)))
.isInstanceOf(ConfigException.class);
}
示例13: testWithTextFile
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@Test
public void testWithTextFile(TestContext tc) {
Async async = tc.async();
retriever = ConfigRetriever.create(vertx,
new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions()
.setType("file")
.setFormat("hocon")
.setConfig(new JsonObject().put("path", "src/test/resources/some-text.txt"))));
retriever.getConfig(ar -> {
assertThat(ar.failed()).isTrue();
assertThat(ar.cause()).isNotNull().isInstanceOf(ConfigException.class);
async.complete();
});
}
示例14: getStringMap
import com.typesafe.config.ConfigException; //導入依賴的package包/類
/**
* Returns a map view of the data associated with the specified key. If the key corresponds
* to a string list, each element of the list will be mapped to itself. If the key corresponds
* to a nested configuration, the map will contain those entries of the nested configuration which
* have string values (but not, for example, further nested configurations). If the key
* corresponds to some other type, throws an exception from the underlying typesafe config
* implementation.
*
* @param config the configuration
* @param key the key
* @return a map view of the data associated with the specified key
*/
public static Map<String, String> getStringMap(Config config, String key) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
try {
for (String value : config.getStringList(key)) {
builder.put(value, value);
}
} catch (ConfigException.WrongType e) {
Config nestedConfig = config.getConfig(key);
for (Map.Entry<String, ConfigValue> entry : nestedConfig.root().entrySet()) {
String nestedKey = entry.getKey();
String quotelessKey = stripQuotes(nestedKey);
try {
builder.put(quotelessKey, nestedConfig.getString(nestedKey));
} catch (ConfigException.WrongType ignore) {
LOG.warn("Ignoring non-string-valued key: '{}'", quotelessKey);
}
}
}
return builder.build();
}
示例15: loadSkillData
import com.typesafe.config.ConfigException; //導入依賴的package包/類
@Override
public <T extends SkillData> void loadSkillData(T skillData, SkillTree context, SkillLoadingErrors errors, Config c) {
CharacterAttributeSkillData data = (CharacterAttributeSkillData) skillData;
try {
List<? extends Config> attributes = c.getConfigList("attributes");
for (Config subc : attributes) {
String attribute = subc.getString("attribute");
int level = subc.getInt("skill-level");
int val = subc.getInt("attribute-value");
Wrapper wrapper = new Wrapper(NtRpgPlugin.GlobalScope.propertyService.getAttribute(attribute), level, val);
if (wrapper.characterAttribute == null) {
errors.log("Unknown attribute %s in %s", attribute, context.getId());
} else {
data.wrappers.add(wrapper);
}
}
} catch (ConfigException ex) {
}
}