jaroslav@975: /** jaroslav@975: * Back 2 Browser Bytecode Translator jaroslav@975: * Copyright (C) 2012 Jaroslav Tulach jaroslav@975: * jaroslav@975: * This program is free software: you can redistribute it and/or modify jaroslav@975: * it under the terms of the GNU General Public License as published by jaroslav@975: * the Free Software Foundation, version 2 of the License. jaroslav@975: * jaroslav@975: * This program is distributed in the hope that it will be useful, jaroslav@975: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@975: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@975: * GNU General Public License for more details. jaroslav@975: * jaroslav@975: * You should have received a copy of the GNU General Public License jaroslav@975: * along with this program. Look for COPYING file in the top folder. jaroslav@975: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@975: */ jaroslav@975: jaroslav@975: package org.apidesign.bck2brwsr.htmlpage; jaroslav@975: jaroslav@975: import java.lang.reflect.Method; jaroslav@977: import java.util.logging.Level; jaroslav@977: import java.util.logging.Logger; jaroslav@975: jaroslav@975: /** jaroslav@975: * jaroslav@975: * @author Jaroslav Tulach jaroslav@975: */ jaroslav@975: public final class KOProperty { jaroslav@977: private static final Logger LOG = Logger.getLogger(KOProperty.class.getName()); jaroslav@975: private final Object obj; jaroslav@975: private final Method getter; jaroslav@975: private final Method setter; jaroslav@975: jaroslav@975: KOProperty(Object obj, String getter, String setter) throws NoSuchMethodException { jaroslav@975: this.obj = obj; jaroslav@975: this.getter = obj.getClass().getDeclaredMethod(getter); jaroslav@975: this.getter.setAccessible(true); jaroslav@975: if (setter != null) { jaroslav@975: this.setter = obj.getClass().getDeclaredMethod(setter, this.getter.getReturnType()); jaroslav@975: this.setter.setAccessible(true); jaroslav@975: } else { jaroslav@975: this.setter = null; jaroslav@975: } jaroslav@975: } jaroslav@975: jaroslav@975: public Object get() throws Exception { jaroslav@977: Object v = getter.invoke(obj); jaroslav@977: LOG.log(Level.INFO, "{0} returns {1}", new Object[] { getter, v }); jaroslav@977: return v; jaroslav@975: } jaroslav@975: jaroslav@975: public void set(Object value) throws Exception { jaroslav@975: setter.invoke(obj, value); jaroslav@975: } jaroslav@975: }