2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
19 package org.apidesign.bck2brwsr.htmlpage;
21 import net.java.html.json.Context;
22 import org.apidesign.html.json.spi.ContextBuilder;
23 import org.apidesign.html.json.spi.FunctionBinding;
24 import org.apidesign.html.json.spi.JSONCall;
25 import org.apidesign.html.json.spi.PropertyBinding;
26 import org.apidesign.html.json.spi.Technology;
27 import org.apidesign.html.json.spi.Transfer;
31 * @author Jaroslav Tulach <jtulach@netbeans.org>
33 public final class BrwsrCntxt implements Technology<Object>, Transfer {
34 private BrwsrCntxt() {}
36 public static final Context DEFAULT;
38 BrwsrCntxt c = new BrwsrCntxt();
39 DEFAULT = ContextBuilder.create().withTechnology(c).withTransfer(c).build();
43 public void extract(Object obj, String[] props, Object[] values) {
44 ConvertTypes.extractJSON(obj, props, values);
48 public void loadJSON(final JSONCall call) {
49 class R implements Runnable {
50 Object[] arr = { null };
53 call.notifySuccess(arr[0]);
58 String me = ConvertTypes.createJSONP(r.arr, r);
59 ConvertTypes.loadJSON(call.composeURL(me), r.arr, r, me);
61 ConvertTypes.loadJSON(call.composeURL(null), r.arr, r, null);
66 public Object wrapModel(Object model) {
71 public void bind(PropertyBinding b, Object model, Object data) {
72 Knockout.bind(data, b, b.getPropertyName(),
73 "getValue__Ljava_lang_Object_2",
74 b.isReadOnly() ? null : "setValue__VLjava_lang_Object_2",
80 public void valueHasMutated(Object data, String propertyName) {
81 Knockout.valueHasMutated(data, propertyName);
85 public void expose(FunctionBinding fb, Object model, Object d) {
86 Knockout.expose(d, fb, fb.getFunctionName(), "call__VLjava_lang_Object_2Ljava_lang_Object_2");
90 public void applyBindings(Object data) {
91 Knockout.applyBindings(data);
95 public Object wrapArray(Object[] arr) {
100 public <M> M toModel(Class<M> modelClass, Object data) {
101 return modelClass.cast(data);