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