javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/KOProperty.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 13 Apr 2013 09:14:54 +0200
branchfx
changeset 975 094cd25a16d9
child 977 f5070beb03cf
permissions -rw-r--r--
Introducing KOProperty to allow us to call non-public methods and to do conversion of primitive types which is broken in WebView
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@975
    22
jaroslav@975
    23
/**
jaroslav@975
    24
 *
jaroslav@975
    25
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@975
    26
 */
jaroslav@975
    27
public final class KOProperty {
jaroslav@975
    28
    private final Object obj;
jaroslav@975
    29
    private final Method getter;
jaroslav@975
    30
    private final Method setter;
jaroslav@975
    31
    
jaroslav@975
    32
    KOProperty(Object obj, String getter, String setter) throws NoSuchMethodException {
jaroslav@975
    33
        this.obj = obj;
jaroslav@975
    34
        this.getter = obj.getClass().getDeclaredMethod(getter);
jaroslav@975
    35
        this.getter.setAccessible(true);
jaroslav@975
    36
        if (setter != null) {
jaroslav@975
    37
            this.setter = obj.getClass().getDeclaredMethod(setter, this.getter.getReturnType());
jaroslav@975
    38
            this.setter.setAccessible(true);
jaroslav@975
    39
        } else {
jaroslav@975
    40
            this.setter = null;
jaroslav@975
    41
        }
jaroslav@975
    42
    }
jaroslav@975
    43
    
jaroslav@975
    44
    public Object get() throws Exception {
jaroslav@975
    45
        return getter.invoke(obj);
jaroslav@975
    46
    }
jaroslav@975
    47
    
jaroslav@975
    48
    public void set(Object value) throws Exception {
jaroslav@975
    49
        setter.invoke(obj, value);
jaroslav@975
    50
    }
jaroslav@975
    51
}