javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/KOProperty.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 14 Apr 2013 11:52:36 +0200
branchfx
changeset 979 83f4aa79c130
parent 977 f5070beb03cf
child 980 1ea155524be4
permissions -rw-r--r--
Tons of in VM and in page logging
     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 import java.util.logging.Level;
    23 import java.util.logging.Logger;
    24 
    25 /**
    26  *
    27  * @author Jaroslav Tulach <jtulach@netbeans.org>
    28  */
    29 public final class KOProperty {
    30     private static final Logger LOG = Logger.getLogger(KOProperty.class.getName());
    31     private final Object obj;
    32     private final Method getter;
    33     private final Method setter;
    34     
    35     KOProperty(Object obj, String getter, String setter) throws NoSuchMethodException {
    36         this.obj = obj;
    37         this.getter = obj.getClass().getDeclaredMethod(getter);
    38         this.getter.setAccessible(true);
    39         if (setter != null) {
    40             this.setter = obj.getClass().getDeclaredMethod(setter, this.getter.getReturnType());
    41             this.setter.setAccessible(true);
    42         } else {
    43             this.setter = null;
    44         }
    45     }
    46     
    47     public Object get() throws Exception {
    48         Object v = getter.invoke(obj);
    49         LOG.log(Level.INFO, "{0} returns {1}", new Object[] { getter, v });
    50         return v;
    51     }
    52     
    53     public void set(Object value) throws Exception {
    54         LOG.log(Level.INFO, "{0} set to {1}", new Object[] { setter, value });
    55         setter.invoke(obj, value);
    56     }
    57 }