01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.js;
15:
16: import org.itsnat.core.script.ScriptExpr;
17: import org.itsnat.impl.core.js.domrender.node.JSNodeRenderImpl;
18:
19: /**
20: *
21: * @author jmarranz
22: */
23: public class JScriptExprImpl implements ScriptExpr {
24: protected JScriptUtilImpl scriptUtil;
25: protected Object value;
26:
27: /** Creates a new instance of CodeValueImpl */
28: public JScriptExprImpl(Object value, JScriptUtilImpl scriptUtil) {
29: this .value = value;
30: this .scriptUtil = scriptUtil;
31: }
32:
33: public String toString() {
34: return getCode();
35: }
36:
37: public String getCode() {
38: if (value instanceof String)
39: return (String) value; // No convertimos en cadena porque consideramos value como una expresión literal, javaToJS lo convertiría en cadena
40: else {
41: // Llamamos repetidas veces porque en el caso de un Node
42: // la primera vez se genera una referencia con path pero
43: // la segunda puede usar el id del caché lo cual acelera
44: return scriptUtil.toScript(value);
45: }
46: }
47:
48: public String getSetPropertyCode(String propName, Object newValue,
49: boolean endSentence) {
50: return scriptUtil.getSetPropertyCode(this , propName, newValue,
51: endSentence);
52: }
53:
54: public String getSetPropertyCode(String propName, Object newValue) {
55: return scriptUtil.getSetPropertyCode(this , propName, newValue);
56: }
57:
58: public String getGetPropertyCode(String propName,
59: boolean endSentence) {
60: return scriptUtil.getGetPropertyCode(this , propName,
61: endSentence);
62: }
63:
64: public String getGetPropertyCode(String propName) {
65: return scriptUtil.getGetPropertyCode(this , propName);
66: }
67:
68: public String getCallMethodCode(String methodName, Object[] params,
69: boolean endSentence) {
70: return scriptUtil.getCallMethodCode(this , methodName, params,
71: endSentence);
72: }
73:
74: public String getCallMethodCode(String methodName, Object[] params) {
75: return scriptUtil.getCallMethodCode(this, methodName, params);
76: }
77: }
|