本文整理汇总了Java中com.typesafe.config.ConfigOrigin类的典型用法代码示例。如果您正苦于以下问题:Java ConfigOrigin类的具体用法?Java ConfigOrigin怎么用?Java ConfigOrigin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigOrigin类属于com.typesafe.config包,在下文中一共展示了ConfigOrigin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkValue
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
@Override
public Object checkValue(String propName, Object value, ConfigOrigin loc) {
if (value instanceof String) {
try {
return Integer.parseInt((String) value);
}
catch (NumberFormatException e) {
throw cannotConvert(loc, propName, value, "integer");
}
}
else if (value instanceof Integer) {
return value;
}
else {
throw cannotConvert(loc, propName, value, "integer");
}
}
示例2: build
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
/**
* Loads, parses, binds, and validates a configuration object.
*
* @param provider the provider to to use for reading configuration files
* @param path the path of the configuration file
* @return a validated configuration object
* @throws IOException if there is an error reading the file
* @throws ConfigurationException if there is an error parsing or validating the file
*/
public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException {
try (InputStream input = provider.open(checkNotNull(path))) {
final JsonNode node = mapper.readTree(hoconFactory.createParser(input));
return build(node, path);
} catch (ConfigException e) {
ConfigurationParsingException.Builder builder = ConfigurationParsingException
.builder("Malformed HOCON")
.setCause(e)
.setDetail(e.getMessage());
ConfigOrigin origin = e.origin();
if (origin != null) {
builder.setLocation(origin.lineNumber(), 0);
}
throw builder.build(path);
}
}
示例3: setStringToConfig
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
/**
* Sets the String value for current configuration's variable to config.
*
* @param key
* The name of settings section.
* @param subKey
* The name of needed variable.
* @param value
* The value to set.
*/
private static void setStringToConfig(String key, String subKey, String newValue,
boolean hideValue) {
String fullPath = MAINKEY + "." + key + "." + subKey;
if (getString(key, subKey).equals(newValue)) {
String messageToLog = hideValue
? String.format("Setting secret configuration value. Key: %s.%s", key, subKey)
: String.format("Configuration value unchanged. Key: %s.%s Value: %s", key,
subKey, newValue);
logger.info(messageToLog);
return;
}
String processedNewValue = ConfigUtil.quoteString(newValue);
// Lets make new Config object with just a single variable.
// Also lets preserve the comments from the original Config.
ConfigOrigin or = conf.getValue(fullPath).origin();
StringBuilder toParse = new StringBuilder();
for (String comment : or.comments()) {
toParse.append("#").append(comment).append("\n");
}
toParse.append(fullPath).append("=").append(processedNewValue);
Config newLittleConfig = ConfigFactory.parseString(toParse.toString());
// Now we have our little Config with the single variable and old comments.
// Let's merge it with the old Config.
conf = newLittleConfig.withFallback(conf);
if (!hideValue) {
logger.info(String.format("Configuration update in RAM. Key: %s.%s Value: %s", key, subKey, newValue));
}
needsSave = true;
}
示例4: getTokenLocation
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
@Override
public JsonLocation getTokenLocation() {
ConfigValue current = currentConfig();
if (current == null) {
return JsonLocation.NA;
}
ConfigOrigin nodeOrigin = current.origin();
return new JsonLocation(current, -1, nodeOrigin.lineNumber(), -1);
}
示例5: origin
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
@Override
public ConfigOrigin origin() {
return c.origin();
}
示例6: origin
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
@Override
public ConfigOrigin origin() {
return config.origin();
}
示例7: ValueLocationPair
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
public ValueLocationPair(Object value, ConfigOrigin loc) {
this.value = value;
this.loc = loc;
}
示例8: location
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
public static String location(ConfigOrigin loc) {
return loc.filename() + ":" + loc.lineNumber();
}
示例9: check
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object check(String propName, Object value, ConfigOrigin loc) {
return checkValue(propName, (T) value, loc);
}
示例10: cannotConvert
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
protected RuntimeException cannotConvert(ConfigOrigin loc, String propName, Object value, String toWhat) {
return new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tCannot convert value '" + value + "' for property '" +
propName + "' to " + toWhat);
}
示例11: SwiftConfigSchema
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
public SwiftConfigSchema() {
validNames = new HashSet<String>();
schema = ConfigFactory.parseResources("swift.conf.schema");
schema = schema.resolve();
if (schema.isEmpty()) {
throw new RuntimeException("Could not find swift.conf.schema");
}
info = new ConfigTree<Info>();
for (Map.Entry<String, ConfigValue> e : schema.entrySet()) {
String k = e.getKey();
String nk = k.replace("\"*\"", "*");
String type = null;
Object defaultValue = null;
String doc = null;
ConfigOrigin loc = null;
if (k.endsWith(".\"_type\"")) {
type = schema.getString(k);
nk = nk.substring(0, nk.lastIndexOf('.'));
loc = e.getValue().origin();
}
else if (k.indexOf(".\"_") == -1){
type = schema.getString(k);
loc = e.getValue().origin();
}
else if (k.endsWith(".\"_default\"")){
defaultValue = e.getValue().unwrapped();
nk = nk.substring(0, nk.lastIndexOf('.'));
}
else if (k.endsWith(".\"_doc\"")){
doc = stripDoc((String) e.getValue().unwrapped());
nk = nk.substring(0, nk.lastIndexOf('.'));
}
else if (k.indexOf(".\"_") != -1) {
continue;
}
Info i = info.get(nk);
if (i == null) {
i = new Info();
info.put(nk, i);
setValid(nk);
}
if (type != null) {
if (type.startsWith("?")) {
i.optional = true;
type = type.substring(1);
}
i.type = getTypeInstance(type, e.getValue());
i.typeSpec = type;
}
if (defaultValue != null) {
i.value = defaultValue;
}
if (doc != null) {
i.doc = doc;
}
if (loc != null) {
i.loc = loc;
}
}
}
示例12: loc
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
private String loc(ConfigOrigin o) {
return o.filename() + ":" + o.lineNumber();
}
示例13: SwiftConfigException
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
public SwiftConfigException(ConfigOrigin loc, String message) {
super((loc.filename() == null ? loc.description() : loc.filename() + ":" + loc.lineNumber()) + " " + message);
}
示例14: location
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
protected static String location(Config config, String key) {
ConfigOrigin origin = config.getValue(key).origin();
return origin.description() + ":" + origin.lineNumber();
}
示例15: fromConfigValue
import com.typesafe.config.ConfigOrigin; //导入依赖的package包/类
public static JsonLocation fromConfigValue(ConfigValue configValue) {
ConfigOrigin configOrigin = configValue.origin();
return new JsonLocation(configValue, -1, configOrigin.lineNumber(), -1);
}