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