| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.ini4j; |
| 17 | |
|
| 18 | |
import org.ini4j.spi.AbstractBeanInvocationHandler; |
| 19 | |
|
| 20 | |
import java.lang.reflect.Proxy; |
| 21 | |
|
| 22 | |
import java.util.prefs.Preferences; |
| 23 | |
|
| 24 | |
public final class PreferencesBean |
| 25 | |
{ |
| 26 | |
private PreferencesBean() |
| 27 | 0 | { |
| 28 | 0 | } |
| 29 | |
|
| 30 | |
public static <T> T newInstance(Class<T> clazz, final Preferences prefs) |
| 31 | |
{ |
| 32 | 6 | return clazz.cast(Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, new Handler(prefs))); |
| 33 | |
} |
| 34 | |
|
| 35 | |
private static class Handler extends AbstractBeanInvocationHandler |
| 36 | |
{ |
| 37 | |
private final Preferences _prefs; |
| 38 | |
|
| 39 | |
public Handler(Preferences prefs) |
| 40 | 6 | { |
| 41 | 6 | _prefs = prefs; |
| 42 | 6 | } |
| 43 | |
|
| 44 | |
@Override protected Object getPropertySpi(String property, Class<?> clazz) |
| 45 | |
{ |
| 46 | 26 | return _prefs.get(property, null); |
| 47 | |
} |
| 48 | |
|
| 49 | |
@Override protected void setPropertySpi(String property, Object value, Class<?> clazz) |
| 50 | |
{ |
| 51 | 1 | _prefs.put(property, value.toString()); |
| 52 | 1 | } |
| 53 | |
|
| 54 | |
@Override protected boolean hasPropertySpi(String property) |
| 55 | |
{ |
| 56 | 22 | return _prefs.get(property, null) != null; |
| 57 | |
} |
| 58 | |
} |
| 59 | |
} |