public static void configureInstance(Object obj, Configuration conf,
Properties properties, String configurationName) {
if (obj == null)
return;
Options opts;
if (properties instanceof Options)
opts = (Options) properties;
else {
opts = new Options();
if (properties != null)
opts.putAll(properties);
}
Configurable configurable = null;
if (conf != null && obj instanceof Configurable)
configurable = (Configurable) obj;
if (configurable != null) {
configurable.setConfiguration(conf);
configurable.startConfiguration();
}
Options invalidEntries = opts.setInto(obj);
if (obj instanceof GenericConfigurable)
((GenericConfigurable) obj).setInto(invalidEntries);
if (!invalidEntries.isEmpty() && configurationName != null) {
Localizer.Message msg = null;
String first = (String) invalidEntries.keySet().iterator().next();
if (invalidEntries.keySet().size() == 1 &&
first.indexOf('.') == -1) {
// if there's just one misspelling and this is not a
// path traversal, check for near misses.
Collection<String> options = findOptionsFor(obj.getClass());
String close = StringDistance.getClosestLevenshteinDistance
(first, options, 0.75f);
if (close != null)
msg = _loc.get("invalid-config-param-hint", new Object[]{
configurationName, obj.getClass(), first, close,
options, });
}
if (msg == null) {
msg = _loc.get("invalid-config-params", new String[]{
configurationName, obj.getClass().getName(),
invalidEntries.keySet().toString(),
findOptionsFor(obj.getClass()).toString(), });
}
throw new ParseException(msg);
}
if (configurable != null)