1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/Bindings.java Fri Apr 19 10:25:57 2013 +0200
1.3 @@ -0,0 +1,39 @@
1.4 +/**
1.5 + * HTML via Java(tm) Language Bindings
1.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, version 2 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details. apidesign.org
1.16 + * designates this particular file as subject to the
1.17 + * "Classpath" exception as provided by apidesign.org
1.18 + * in the License file that accompanied this code.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program. Look for COPYING file in the top folder.
1.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
1.23 + */
1.24 +package org.apidesign.html.json.impl;
1.25 +
1.26 +/**
1.27 + *
1.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.29 + */
1.30 +public final class Bindings {
1.31 + public static Bindings apply(Object model, String[] propsAndGetters, String[] functions) {
1.32 + return null;
1.33 + }
1.34 +
1.35 + public Object koData() {
1.36 + return this;
1.37 + }
1.38 +
1.39 + public void valueHasMutated(String firstName) {
1.40 + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1.41 + }
1.42 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/JSON.java Fri Apr 19 10:25:57 2013 +0200
2.3 @@ -0,0 +1,38 @@
2.4 +/**
2.5 + * HTML via Java(tm) Language Bindings
2.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details. apidesign.org
2.16 + * designates this particular file as subject to the
2.17 + * "Classpath" exception as provided by apidesign.org
2.18 + * in the License file that accompanied this code.
2.19 + *
2.20 + * You should have received a copy of the GNU General Public License
2.21 + * along with this program. Look for COPYING file in the top folder.
2.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
2.23 + */
2.24 +package org.apidesign.html.json.impl;
2.25 +
2.26 +/**
2.27 + *
2.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.29 + */
2.30 +public final class JSON {
2.31 +
2.32 + private JSON() {
2.33 + }
2.34 +
2.35 + public static void extract(Object value, String[] props, Object[] values) {
2.36 + }
2.37 +
2.38 + public static Object toJSON(Object prop_firstName) {
2.39 + return null;
2.40 + }
2.41 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/JSONList.java Fri Apr 19 10:25:57 2013 +0200
3.3 @@ -0,0 +1,46 @@
3.4 +/**
3.5 + * HTML via Java(tm) Language Bindings
3.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details. apidesign.org
3.16 + * designates this particular file as subject to the
3.17 + * "Classpath" exception as provided by apidesign.org
3.18 + * in the License file that accompanied this code.
3.19 + *
3.20 + * You should have received a copy of the GNU General Public License
3.21 + * along with this program. Look for COPYING file in the top folder.
3.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
3.23 + */
3.24 +package org.apidesign.html.json.impl;
3.25 +
3.26 +import java.util.ArrayList;
3.27 +
3.28 +/**
3.29 + *
3.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.31 + */
3.32 +public final class JSONList<T> extends ArrayList<T> {
3.33 +
3.34 + public JSONList(String prop) {
3.35 + }
3.36 +
3.37 + public JSONList<T> onChange(Runnable r) {
3.38 + return this;
3.39 + }
3.40 +
3.41 + public JSONList<T> assign(Bindings ko) {
3.42 + return this;
3.43 + }
3.44 +
3.45 + @Override
3.46 + public JSONList<T> clone() {
3.47 + return this;
3.48 + }
3.49 +}
4.1 --- a/json/src/main/java/org/apidesign/html/json/impl/PageProcessor.java Fri Apr 19 10:04:54 2013 +0200
4.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/PageProcessor.java Fri Apr 19 10:25:57 2013 +0200
4.3 @@ -179,19 +179,17 @@
4.4 w = new OutputStreamWriter(java.openOutputStream());
4.5 try {
4.6 w.append("package " + pkg + ";\n");
4.7 - w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
4.8 - w.append("import org.apidesign.bck2brwsr.htmlpage.KOList;\n");
4.9 - w.append("import org.apidesign.bck2brwsr.core.JavaScriptOnly;\n");
4.10 + w.append("import net.java.html.json.*;\n");
4.11 w.append("public final class ").append(className).append(" implements Cloneable {\n");
4.12 w.append(" private boolean locked;\n");
4.13 - w.append(" private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
4.14 + w.append(" private org.apidesign.html.json.impl.Bindings ko;\n");
4.15 w.append(body.toString());
4.16 w.append(" private static Class<" + inPckName(e) + "> modelFor() { return null; }\n");
4.17 w.append(" public ").append(className).append("() {\n");
4.18 w.append(" };\n");
4.19 - w.append(" private org.apidesign.bck2brwsr.htmlpage.Knockout intKnckt() {\n");
4.20 + w.append(" private org.apidesign.html.json.impl.Bindings intKnckt() {\n");
4.21 w.append(" if (ko != null) return ko;\n");
4.22 - w.append(" return ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(this, ");
4.23 + w.append(" return ko = org.apidesign.html.json.impl.Bindings.apply(this, ");
4.24 writeStringArray(propsGetSet, w);
4.25 w.append(", ");
4.26 writeStringArray(functions, w);
4.27 @@ -207,7 +205,7 @@
4.28 values++;
4.29 }
4.30 w.append(" Object[] ret = new Object[" + values + "];\n");
4.31 - w.append(" org.apidesign.bck2brwsr.htmlpage.ConvertTypes.extractJSON(json, new String[] {\n");
4.32 + w.append(" org.apidesign.html.json.impl.JSON.extract(json, new String[] {\n");
4.33 for (int i = 0; i < propsGetSet.size(); i += 4) {
4.34 Prprt p = findPrprt(props, propsGetSet.get(i));
4.35 if (p == null) {
4.36 @@ -281,25 +279,6 @@
4.37 return ok;
4.38 }
4.39
4.40 - private static String type(String tag) {
4.41 - if (tag.equals("title")) {
4.42 - return "Title";
4.43 - }
4.44 - if (tag.equals("button")) {
4.45 - return "Button";
4.46 - }
4.47 - if (tag.equals("input")) {
4.48 - return "Input";
4.49 - }
4.50 - if (tag.equals("canvas")) {
4.51 - return "Canvas";
4.52 - }
4.53 - if (tag.equals("img")) {
4.54 - return "Image";
4.55 - }
4.56 - return "Element";
4.57 - }
4.58 -
4.59 private boolean generateProperties(
4.60 Element where,
4.61 Writer w, Prprt[] properties,
4.62 @@ -314,7 +293,7 @@
4.63 String[] gs = toGetSet(p.name(), tn, p.array());
4.64
4.65 if (p.array()) {
4.66 - w.write("private KOList<" + tn + "> prop_" + p.name() + " = new KOList<" + tn + ">(\""
4.67 + w.write("private org.apidesign.html.json.impl.JSONList<" + tn + "> prop_" + p.name() + " = new org.apidesign.html.json.impl.JSONList<" + tn + ">(\""
4.68 + p.name() + "\"");
4.69 Collection<String> dependants = deps.get(p.name());
4.70 if (dependants != null) {
4.71 @@ -767,9 +746,9 @@
4.72 body.append(" ProcessResult pr = new ProcessResult();\n");
4.73 if (jsonpVarName != null) {
4.74 body.append(" String ").append(jsonpVarName).
4.75 - append(" = org.apidesign.bck2brwsr.htmlpage.ConvertTypes.createJSONP(result, pr);\n");
4.76 + append(" = org.apidesign.html.json.impl.JSON.createJSONP(result, pr);\n");
4.77 }
4.78 - body.append(" org.apidesign.bck2brwsr.htmlpage.ConvertTypes.loadJSON(\n ");
4.79 + body.append(" org.apidesign.html.json.impl.JSON.loadJSON(\n ");
4.80 body.append(assembleURL);
4.81 body.append(", result, pr, ").append(jsonpVarName).append("\n );\n");
4.82 // body.append(" ").append(clazz.getSimpleName()).append(".").append(n).append("(");
4.83 @@ -797,16 +776,16 @@
4.84 params.append('"').append(id).append('"');
4.85 continue;
4.86 }
4.87 - toCall = "org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toString(";
4.88 + toCall = "org.apidesign.html.json.impl.JSON.toString(";
4.89 }
4.90 if (ve.asType().getKind() == TypeKind.DOUBLE) {
4.91 - toCall = "org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toDouble(";
4.92 + toCall = "org.apidesign.html.json.impl.JSON.toDouble(";
4.93 }
4.94 if (ve.asType().getKind() == TypeKind.INT) {
4.95 - toCall = "org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toInt(";
4.96 + toCall = "org.apidesign.html.json.impl.JSON.toInt(";
4.97 }
4.98 if (dataName != null && ve.getSimpleName().contentEquals(dataName) && isModel(ve.asType())) {
4.99 - toCall = "org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toModel(" + ve.asType() + ".class, ";
4.100 + toCall = "org.apidesign.html.json.impl.JSON.toModel(" + ve.asType() + ".class, ";
4.101 }
4.102
4.103 if (toCall != null) {
4.104 @@ -923,7 +902,7 @@
4.105 for (Prprt p : props) {
4.106 w.write(sep);
4.107 w.append(" sb.append(\"" + p.name() + ": \");\n");
4.108 - w.append(" sb.append(org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toJSON(prop_");
4.109 + w.append(" sb.append(org.apidesign.html.json.impl.JSON.toJSON(prop_");
4.110 w.append(p.name()).append("));\n");
4.111 sep = " sb.append(',');\n";
4.112 }