jaroslav@975
|
1 |
/**
|
jaroslav@975
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@975
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@975
|
4 |
*
|
jaroslav@975
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@975
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@975
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@975
|
8 |
*
|
jaroslav@975
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@975
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@975
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@975
|
12 |
* GNU General Public License for more details.
|
jaroslav@975
|
13 |
*
|
jaroslav@975
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@975
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@975
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@975
|
17 |
*/
|
jaroslav@975
|
18 |
|
jaroslav@975
|
19 |
package org.apidesign.bck2brwsr.htmlpage;
|
jaroslav@975
|
20 |
|
jaroslav@975
|
21 |
import java.lang.reflect.Method;
|
jaroslav@977
|
22 |
import java.util.logging.Level;
|
jaroslav@977
|
23 |
import java.util.logging.Logger;
|
jaroslav@975
|
24 |
|
jaroslav@975
|
25 |
/**
|
jaroslav@975
|
26 |
*
|
jaroslav@975
|
27 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@975
|
28 |
*/
|
jaroslav@975
|
29 |
public final class KOProperty {
|
jaroslav@977
|
30 |
private static final Logger LOG = Logger.getLogger(KOProperty.class.getName());
|
jaroslav@975
|
31 |
private final Object obj;
|
jaroslav@975
|
32 |
private final Method getter;
|
jaroslav@975
|
33 |
private final Method setter;
|
jaroslav@975
|
34 |
|
jaroslav@975
|
35 |
KOProperty(Object obj, String getter, String setter) throws NoSuchMethodException {
|
jaroslav@975
|
36 |
this.obj = obj;
|
jaroslav@975
|
37 |
this.getter = obj.getClass().getDeclaredMethod(getter);
|
jaroslav@975
|
38 |
this.getter.setAccessible(true);
|
jaroslav@975
|
39 |
if (setter != null) {
|
jaroslav@975
|
40 |
this.setter = obj.getClass().getDeclaredMethod(setter, this.getter.getReturnType());
|
jaroslav@975
|
41 |
this.setter.setAccessible(true);
|
jaroslav@975
|
42 |
} else {
|
jaroslav@975
|
43 |
this.setter = null;
|
jaroslav@975
|
44 |
}
|
jaroslav@975
|
45 |
}
|
jaroslav@975
|
46 |
|
jaroslav@975
|
47 |
public Object get() throws Exception {
|
jaroslav@977
|
48 |
Object v = getter.invoke(obj);
|
jaroslav@977
|
49 |
LOG.log(Level.INFO, "{0} returns {1}", new Object[] { getter, v });
|
jaroslav@977
|
50 |
return v;
|
jaroslav@975
|
51 |
}
|
jaroslav@975
|
52 |
|
jaroslav@975
|
53 |
public void set(Object value) throws Exception {
|
jaroslav@979
|
54 |
LOG.log(Level.INFO, "{0} set to {1}", new Object[] { setter, value });
|
jaroslav@975
|
55 |
setter.invoke(obj, value);
|
jaroslav@975
|
56 |
}
|
jaroslav@975
|
57 |
}
|