本文整理匯總了Java中com.typesafe.config.ConfigException.BadValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigException.BadValue方法的具體用法?Java ConfigException.BadValue怎麽用?Java ConfigException.BadValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.typesafe.config.ConfigException
的用法示例。
在下文中一共展示了ConfigException.BadValue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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<>();
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: decodeObject
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
/**
* Instantiate an object without a compile time expected type. This expects a config of the
* form "{plugin-category: {...}}". ie. there should be exactly one top level key and that
* key should be a valid, loaded, plug-in category.
*/
public <T> T decodeObject(Config config) throws JsonProcessingException, IOException {
if (config.root().size() != 1) {
throw new ConfigException.Parse(config.root().origin(),
"config root must have exactly one key");
}
String category = config.root().keySet().iterator().next();
PluginMap pluginMap = pluginRegistry.asMap().get(category);
if (pluginMap == null) {
throw new ConfigException.BadValue(config.root().get(category).origin(),
category,
"top level key must be a valid category");
}
ConfigValue configValue = config.root().get(category);
return (T) decodeObject(pluginMap.baseClass(), configValue);
}
示例5: PersistentBlocksFactory
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
public PersistentBlocksFactory(Config config) {
if (config.hasPath("store.leveldb") && config.hasPath("store.memory")) {
throw new ConfigException.BadValue(config.origin(), "store", "only one store is allowed: either memory or leveldb");
} else if (config.hasPath("store.leveldb")) {
Config leveldbConfig = config.getConfig("store.leveldb");
if (config.hasPath("store.default-leveldb"))
leveldbConfig = leveldbConfig.withFallback(config.getConfig("store.default-leveldb"));
storeFactory = new LevelDBStoreFactory(leveldbConfig);
} else if (config.hasPath("store.memory")) {
storeFactory = new MemstoreFactory();
} else {
throw new ConfigException.BadValue(config.origin(), "store", "store must be either memory or leveldb");
}
}
示例6: createColoredValidatorFactory
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
private ColoredValidatorFactory createColoredValidatorFactory(Config config) {
String chain = config.getString("blockchain.chain");
if ("testnet3".equals(chain)) {
return new ColoredValidatorFactory(new ColoredValidatorConfig(true, true));
} else if ("regtest".equals(chain)) {
return new ColoredValidatorFactory(new ColoredValidatorConfig(true, true));
} else if ("production".equals(chain)) {
return new ColoredValidatorFactory(new ColoredValidatorConfig(true, false));
} else if ("signedregtest".equals(chain)) {
return new ColoredValidatorFactory(new ColoredValidatorConfig(true, true));
} else {
throw new ConfigException.BadValue(config.origin(), "blockchain.chain", "Invalid chain: " + chain);
}
}
示例7: setServerConfigDataSource
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
private void setServerConfigDataSource(String key, ServerConfig serverConfig) {
try {
serverConfig.setDataSource(new WrappingDatasource(dbApi.getDatabase(key).getDataSource()));
} catch(Exception e) {
throw new ConfigException.BadValue(
"ebean." + key,
e.getMessage(),
e
);
}
}
示例8: addModelClassesToServerConfig
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
private void addModelClassesToServerConfig(String key, ServerConfig serverConfig, Set<String> classes) {
for (String clazz: classes) {
try {
serverConfig.addClass(Class.forName(clazz, true, environment.classLoader()));
} catch (Exception e) {
throw new ConfigException.BadValue(
"ebean." + key,
"Cannot register class [" + clazz + "] in Ebean server",
e
);
}
}
}
示例9: setOption
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
@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);
}
};
}
示例10: badConfOption
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test(expected = ConfigException.BadValue.class)
public void badConfOption() throws Exception {
new MockUnit(HttpHandler.class, Provider.class)
.run(unit -> {
new JettyServer(unit.get(HttpHandler.class),
config.withValue("jetty.threads.MinThreads", ConfigValueFactory.fromAnyRef("x")),
unit.get(Provider.class));
});
}
示例11: expandSugar
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
public static ConfigValue expandSugar(Config config, PluginRegistry pluginRegistry) {
if (config.root().size() != 1) {
throw new ConfigException.Parse(config.root().origin(),
"config root must have exactly one key");
}
String category = config.root().keySet().iterator().next();
PluginMap pluginMap = pluginRegistry.asMap().get(category);
if (pluginMap == null) {
throw new ConfigException.BadValue(config.root().get(category).origin(),
category,
"top level key must be a valid category");
}
Class<?> baseClass = Objects.firstNonNull(pluginMap.baseClass(), Object.class);
return expandSugar(baseClass, config.root().get(category), pluginRegistry);
}
示例12: checkAliasesForCyclesHelper
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
private void checkAliasesForCyclesHelper(String key, Set<String> visited) {
visited.add(key);
String nextKey = aliases.get(key);
if (nextKey == null) {
// should mean it is present in the bimap
return;
}
if (visited.contains(nextKey)) {
throw new ConfigException.BadValue(config.root().get(key).origin(), key, "cyclical aliases detected");
} else {
checkAliasesForCyclesHelper(nextKey, visited);
}
}
示例13: badValue
import com.typesafe.config.ConfigException; //導入方法依賴的package包/類
private static ConfigException badValue(String message, Config config, String path) {
return new ConfigException.BadValue(config.getValue(path).origin(), path, message);
}