Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lviggiano/owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi R. Viggiano committed Sep 2, 2019
2 parents 18e26d0 + 3164f0a commit 1acb314
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions owner/src/main/java/org/aeonbits/owner/Converters.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Object tryConvert(Method targetMethod, Class<?> targetType, String text) {
if (!canUsePropertyEditors())
return SKIP;

PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
PropertyEditor editor = findEditor(targetType);
if (editor == null) return SKIP;
try {
editor.setAsText(text);
Expand All @@ -151,17 +151,19 @@ Object tryConvert(Method targetMethod, Class<?> targetType, String text) {
throw unsupportedConversion(e, targetType, text);
}
}

private boolean canUsePropertyEditors() {
return isPropertyEditorAvailable() && !isPropertyEditorDisabled();

private PropertyEditor findEditor(Class<?> targetType) {
PropertyEditor editor = PROPERTY_BY_CLASS.get(targetType);
if (editor == null) {
editor = PropertyEditorManager.findEditor(targetType);
if (editor != null)
PROPERTY_BY_CLASS.put(targetType, editor);
}
return editor;
}

private boolean isPropertyEditorAvailable() {
return isClassAvailable("java.beans.PropertyEditorManager");
}

private boolean isPropertyEditorDisabled() {
return Boolean.getBoolean("org.aeonbits.owner.property.editor.disabled");
private boolean canUsePropertyEditors() {
return isPropertyEditorAvailable && !isPropertyEditorDisabled;
}
},

Expand Down Expand Up @@ -265,6 +267,12 @@ private static Object convertWithConverterClass(Method targetMethod, String text
}

private static final Map<Class<?>, Class<? extends Converter<?>>> converterRegistry = new ConcurrentHashMap<Class<?>, Class<? extends Converter<?>>>();

private static final boolean isPropertyEditorAvailable = isClassAvailable("java.beans.PropertyEditorManager");

private static final boolean isPropertyEditorDisabled = Boolean.getBoolean("org.aeonbits.owner.property.editor.disabled");

private static final Map<Class<?>, PropertyEditor> PROPERTY_BY_CLASS = new WeakHashMap<Class<?>, PropertyEditor>();

abstract Object tryConvert(Method targetMethod, Class<?> targetType, String text);

Expand Down

0 comments on commit 1acb314

Please sign in to comment.