com.typesafe.config.ConfigOrigin Java Examples
The following examples show how to use
com.typesafe.config.ConfigOrigin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 6 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException e) { throw cannotConvert(loc, propName, value, "number"); } } else if (value instanceof Double) { return value; } else { throw cannotConvert(loc, propName, value, "number"); } }
Example #2
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 6 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { if ("off".equals(value)) { return Integer.MAX_VALUE; } else if (value instanceof String) { try { return Integer.parseInt((String) value); } catch (NumberFormatException e) { throw cannotConvert(loc, propName, value, "integer"); } } else if (value instanceof Integer) { Integer i = (Integer) value; if (i > 0) { return i; } } throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be an " + toString()); }
Example #3
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 6 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { if (value instanceof List) { List<?> l = (List<?>) value; boolean allStrings = true; for (Object o : l) { if (!(o instanceof String)) { allStrings = false; } } if (allStrings) { return value; } } else if (value instanceof String) { // also allow comma separated strings in a string return Arrays.asList(((String) value).split(",\\s*")); } throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); }
Example #4
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 6 votes |
@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"); } }
Example #5
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { File f = new File(value); if (!f.exists()) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. File does not exist."); } return value; }
Example #6
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { String[] els = value.split(",\\s*"); if (els.length == 2) { try { Integer.parseInt(els[0]); Integer.parseInt(els[1]); return value; } catch (NumberFormatException e) { } } throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); }
Example #7
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { try { WallTime.timeToSeconds(value); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid time value '" + value + "' for property '" + propName + "'. Mist be a " + toString()); } return value; }
Example #8
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { Double dvalue = (Double) super.checkValue(propName, value, loc); if (dvalue < l || dvalue > h) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); } return dvalue; }
Example #9
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { Double dvalue = (Double) super.checkValue(propName, value, loc); if (dvalue < 0) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); } return dvalue; }
Example #10
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { Integer ivalue = (Integer) super.checkValue(propName, value, loc); if (ivalue < 0) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); } return ivalue; }
Example #11
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { Integer ivalue = (Integer) super.checkValue(propName, value, loc); if (ivalue <= 0) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Must be a " + toString()); } return ivalue; }
Example #12
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { if (value instanceof String) { return Boolean.valueOf((String) value); } else if (value instanceof Boolean) { return value; } else { throw cannotConvert(loc, propName, value, "boolean"); } }
Example #13
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { try { URI u = new URI(value); return value; } catch (Exception e) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'"); } }
Example #14
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 5 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { if (!choices.contains(value)) { throw new IllegalArgumentException(SwiftConfig.location(loc) + ":\n\tInvalid value '" + value + "' for property '" + propName + "'. Valid values are: " + pp(choices)); } return value; }
Example #15
Source File: HoconJsonLocation.java From jackson-dataformat-hocon with Apache License 2.0 | 4 votes |
@Override public ConfigOrigin withLineNumber(int i) { return origin.withLineNumber(i); }
Example #16
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 4 votes |
@Override public Object checkValue(String propName, Object value, ConfigOrigin loc) { return value; }
Example #17
Source File: SwiftConfigSchema.java From swift-k with Apache License 2.0 | 4 votes |
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; } } }
Example #18
Source File: SwiftConfigSchema.java From swift-k with Apache License 2.0 | 4 votes |
private String loc(ConfigOrigin o) { return o.filename() + ":" + o.lineNumber(); }
Example #19
Source File: SwiftConfigException.java From swift-k with Apache License 2.0 | 4 votes |
public SwiftConfigException(ConfigOrigin loc, String message) { super((loc.filename() == null ? loc.description() : loc.filename() + ":" + loc.lineNumber()) + " " + message); }
Example #20
Source File: RouteConfig.java From xio with Apache License 2.0 | 4 votes |
protected static String location(Config config, String key) { ConfigOrigin origin = config.getValue(key).origin(); return origin.description() + ":" + origin.lineNumber(); }
Example #21
Source File: HoconJsonLocation.java From jackson-dataformat-hocon with Apache License 2.0 | 4 votes |
public HoconJsonLocation(final ConfigOrigin origin) { super(origin.description(), -1L, origin.lineNumber(), -1); this.origin = origin; }
Example #22
Source File: HoconJsonLocation.java From jackson-dataformat-hocon with Apache License 2.0 | 4 votes |
@Override public ConfigOrigin withComments(List<String> comments) { return origin.withComments(comments); }
Example #23
Source File: NestedConfig.java From Bats with Apache License 2.0 | 4 votes |
@Override public ConfigOrigin origin() { return c.origin(); }
Example #24
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 4 votes |
@Override public Object checkValue(String propName, String value, ConfigOrigin loc) { // all values accepted return value; }
Example #25
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 4 votes |
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); }
Example #26
Source File: ConfigPropertyType.java From swift-k with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public Object check(String propName, Object value, ConfigOrigin loc) { return checkValue(propName, (T) value, loc); }
Example #27
Source File: SwiftConfig.java From swift-k with Apache License 2.0 | 4 votes |
public static String location(ConfigOrigin loc) { return loc.filename() + ":" + loc.lineNumber(); }
Example #28
Source File: SwiftConfig.java From swift-k with Apache License 2.0 | 4 votes |
public ValueLocationPair(Object value, ConfigOrigin loc) { this.value = value; this.loc = loc; }
Example #29
Source File: NestedConfig.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public ConfigOrigin origin() { return config.origin(); }
Example #30
Source File: ConfigWithFallback.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Override public ConfigOrigin origin() { return baseConfig.origin(); }