jaroslav@813: /** jaroslav@813: * Back 2 Browser Bytecode Translator jaroslav@813: * Copyright (C) 2012 Jaroslav Tulach jaroslav@813: * jaroslav@813: * This program is free software: you can redistribute it and/or modify jaroslav@813: * it under the terms of the GNU General Public License as published by jaroslav@813: * the Free Software Foundation, version 2 of the License. jaroslav@813: * jaroslav@813: * This program is distributed in the hope that it will be useful, jaroslav@813: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@813: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@813: * GNU General Public License for more details. jaroslav@813: * jaroslav@813: * You should have received a copy of the GNU General Public License jaroslav@813: * along with this program. Look for COPYING file in the top folder. jaroslav@813: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@813: */ jaroslav@813: package org.apidesign.bck2brwsr.htmlpage; jaroslav@813: jaroslav@813: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@813: jaroslav@813: /** jaroslav@813: * jaroslav@813: * @author Jaroslav Tulach jaroslav@813: */ jaroslav@813: public final class ConvertTypes { jaroslav@813: ConvertTypes() { jaroslav@813: } jaroslav@813: jaroslav@813: public static String toString(Object object, String property) { jaroslav@813: Object ret = getProperty(object, property); jaroslav@813: return ret == null ? null : ret.toString(); jaroslav@813: } jaroslav@813: jaroslav@813: public static double toDouble(Object object, String property) { jaroslav@813: Object ret = getProperty(object, property); jaroslav@813: return ret instanceof Number ? ((Number)ret).doubleValue() : Double.NaN; jaroslav@813: } jaroslav@813: jaroslav@813: public static int toInt(Object object, String property) { jaroslav@813: Object ret = getProperty(object, property); jaroslav@813: return ret instanceof Number ? ((Number)ret).intValue() : Integer.MIN_VALUE; jaroslav@813: } jaroslav@813: jaroslav@813: @JavaScriptBody(args = { "object", "property" }, jaroslav@813: body = "var p = object[property]; return p ? p : null;" jaroslav@813: ) jaroslav@813: private static Object getProperty(Object object, String property) { jaroslav@813: return null; jaroslav@813: } jaroslav@813: }