jaroslav@813
|
1 |
/**
|
jaroslav@813
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@813
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@813
|
4 |
*
|
jaroslav@813
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@813
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@813
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@813
|
8 |
*
|
jaroslav@813
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@813
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@813
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@813
|
12 |
* GNU General Public License for more details.
|
jaroslav@813
|
13 |
*
|
jaroslav@813
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@813
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@813
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@813
|
17 |
*/
|
jaroslav@813
|
18 |
package org.apidesign.bck2brwsr.htmlpage;
|
jaroslav@813
|
19 |
|
jaroslav@813
|
20 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
jaroslav@813
|
21 |
|
jaroslav@813
|
22 |
/**
|
jaroslav@813
|
23 |
*
|
jaroslav@813
|
24 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@813
|
25 |
*/
|
jaroslav@813
|
26 |
public final class ConvertTypes {
|
jaroslav@813
|
27 |
ConvertTypes() {
|
jaroslav@813
|
28 |
}
|
jaroslav@813
|
29 |
|
jaroslav@813
|
30 |
public static String toString(Object object, String property) {
|
jaroslav@813
|
31 |
Object ret = getProperty(object, property);
|
jaroslav@813
|
32 |
return ret == null ? null : ret.toString();
|
jaroslav@813
|
33 |
}
|
jaroslav@813
|
34 |
|
jaroslav@813
|
35 |
public static double toDouble(Object object, String property) {
|
jaroslav@813
|
36 |
Object ret = getProperty(object, property);
|
jaroslav@813
|
37 |
return ret instanceof Number ? ((Number)ret).doubleValue() : Double.NaN;
|
jaroslav@813
|
38 |
}
|
jaroslav@813
|
39 |
|
jaroslav@813
|
40 |
public static int toInt(Object object, String property) {
|
jaroslav@813
|
41 |
Object ret = getProperty(object, property);
|
jaroslav@813
|
42 |
return ret instanceof Number ? ((Number)ret).intValue() : Integer.MIN_VALUE;
|
jaroslav@813
|
43 |
}
|
jaroslav@813
|
44 |
|
jaroslav@813
|
45 |
@JavaScriptBody(args = { "object", "property" },
|
jaroslav@879
|
46 |
body = "if (property === null) return object;\n"
|
jaroslav@879
|
47 |
+ "var p = object[property]; return p ? p : null;"
|
jaroslav@813
|
48 |
)
|
jaroslav@813
|
49 |
private static Object getProperty(Object object, String property) {
|
jaroslav@813
|
50 |
return null;
|
jaroslav@813
|
51 |
}
|
jaroslav@813
|
52 |
}
|