1.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Mon Dec 23 09:30:10 2013 +0100
1.2 +++ b/json/src/main/java/org/apidesign/html/json/spi/Proto.java Mon Dec 23 15:06:51 2013 +0100
1.3 @@ -83,6 +83,8 @@
1.4 package org.apidesign.html.json.spi;
1.5
1.6 import net.java.html.BrwsrCtx;
1.7 +import org.netbeans.html.json.impl.Bindings;
1.8 +import org.netbeans.html.json.impl.JSON;
1.9
1.10 /**
1.11 *
1.12 @@ -90,12 +92,14 @@
1.13 * @since 0.7
1.14 */
1.15 public final class Proto {
1.16 + private final Object obj;
1.17 private final Type type;
1.18 private final net.java.html.BrwsrCtx context;
1.19 private boolean locked;
1.20 - private org.netbeans.html.json.impl.Bindings[] ko = { null };
1.21 + private org.netbeans.html.json.impl.Bindings ko;
1.22
1.23 - Proto(Type type, BrwsrCtx context) {
1.24 + Proto(Object obj, Type type, BrwsrCtx context) {
1.25 + this.obj = obj;
1.26 this.type = type;
1.27 this.context = context;
1.28 }
1.29 @@ -118,10 +122,38 @@
1.30 }
1.31
1.32 public void valueHasMutated(String propName) {
1.33 -
1.34 + if (ko != null) {
1.35 + ko.valueHasMutated(propName);
1.36 + }
1.37 }
1.38
1.39 public void applyBindings() {
1.40 + initBindings().applyBindings();
1.41 + }
1.42 +
1.43 + private Bindings initBindings() {
1.44 + if (ko == null) {
1.45 + Bindings b = Bindings.apply(context, obj);
1.46 + PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length];
1.47 + for (int i = 0; i < pb.length; i++) {
1.48 + pb[i] = b.registerProperty(
1.49 + type.propertyNames[i], i, obj, type, type.propertyReadOnly[i]
1.50 + );
1.51 + }
1.52 + FunctionBinding[] fb = new FunctionBinding[type.functions.length];
1.53 + for (int i = 0; i < fb.length; i++) {
1.54 + fb[i] = b.registerFunction(
1.55 + type.functions[i], i, obj, type
1.56 + );
1.57 + }
1.58 + b.finish(obj, pb, fb);
1.59 + ko = b;
1.60 + }
1.61 + return ko;
1.62 + }
1.63 +
1.64 + public Bindings getBindings() {
1.65 + return ko;
1.66 }
1.67
1.68
1.69 @@ -140,12 +172,13 @@
1.70 protected Type(
1.71 Class<Model> clazz, Class<?> modelFor, int properties, int functions
1.72 ) {
1.73 - assert clazz.getName().endsWith("$Html4JavaType");
1.74 - assert clazz.getDeclaringClass() == clazz;
1.75 + assert getClass().getName().endsWith("$Html4JavaType");
1.76 + assert getClass().getDeclaringClass() == clazz;
1.77 this.clazz = clazz;
1.78 this.propertyNames = new String[properties];
1.79 this.propertyReadOnly = new boolean[properties];
1.80 this.functions = new String[functions];
1.81 + JSON.register(clazz, this);
1.82 }
1.83
1.84 protected final void registerProperty(String name, int index, boolean readOnly) {
1.85 @@ -159,12 +192,15 @@
1.86 functions[index] = name;
1.87 }
1.88
1.89 - public Proto protoFor(BrwsrCtx context) {
1.90 - return new Proto(this, context);
1.91 + public Proto protoFor(Object obj, BrwsrCtx context) {
1.92 + return new Proto(obj, this, context);
1.93 }
1.94
1.95 - protected abstract void setValue(Model model, int index, Object value);
1.96 - protected abstract Object getValue(Model model, int index);
1.97 - protected abstract void call(Model model, int index, Object data, Object event);
1.98 + // XXX: should be protected
1.99 + public abstract void setValue(Model model, int index, Object value);
1.100 + public abstract Object getValue(Model model, int index);
1.101 + public abstract void call(Model model, int index, Object data, Object event);
1.102 + public abstract Model cloneTo(Object model, BrwsrCtx ctx);
1.103 + public abstract Model read(BrwsrCtx c, Object json);
1.104 }
1.105 }
2.1 --- a/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Mon Dec 23 09:30:10 2013 +0100
2.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Mon Dec 23 15:06:51 2013 +0100
2.3 @@ -42,12 +42,13 @@
2.4 */
2.5 package org.netbeans.html.json.impl;
2.6
2.7 +import net.java.html.BrwsrCtx;
2.8 +import org.apidesign.html.json.spi.FunctionBinding;
2.9 import org.apidesign.html.json.spi.PropertyBinding;
2.10 -import net.java.html.BrwsrCtx;
2.11 +import org.apidesign.html.json.spi.Proto;
2.12 +import org.apidesign.html.json.spi.Technology;
2.13 import org.netbeans.html.json.impl.PropertyBindingAccessor.FBData;
2.14 import org.netbeans.html.json.impl.PropertyBindingAccessor.PBData;
2.15 -import org.apidesign.html.json.spi.FunctionBinding;
2.16 -import org.apidesign.html.json.spi.Technology;
2.17
2.18 /**
2.19 *
2.20 @@ -61,12 +62,12 @@
2.21 this.bp = bp;
2.22 }
2.23
2.24 - public <M> PropertyBinding registerProperty(String propName, M model, SetAndGet<M> access, boolean readOnly) {
2.25 - return PropertyBindingAccessor.create(new PBData<M>(this, propName, model, access, readOnly));
2.26 + public <M> PropertyBinding registerProperty(String propName, int index, M model, Proto.Type<M> access, boolean readOnly) {
2.27 + return PropertyBindingAccessor.create(new PBData<M>(this, propName, index, model, access, readOnly));
2.28 }
2.29
2.30 - public <M> FunctionBinding registerFunction(String name, M model, Callback<M> access) {
2.31 - return PropertyBindingAccessor.createFunction(new FBData<M>(name, model, access));
2.32 + public <M> FunctionBinding registerFunction(String name, int index, M model, Proto.Type<M> access) {
2.33 + return PropertyBindingAccessor.createFunction(new FBData<M>(name, index, model, access));
2.34 }
2.35
2.36 public static Bindings<?> apply(BrwsrCtx c, Object model) {
3.1 --- a/json/src/main/java/org/netbeans/html/json/impl/Callback.java Mon Dec 23 09:30:10 2013 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,51 +0,0 @@
3.4 -/**
3.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.6 - *
3.7 - * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
3.8 - *
3.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.10 - * Other names may be trademarks of their respective owners.
3.11 - *
3.12 - * The contents of this file are subject to the terms of either the GNU
3.13 - * General Public License Version 2 only ("GPL") or the Common
3.14 - * Development and Distribution License("CDDL") (collectively, the
3.15 - * "License"). You may not use this file except in compliance with the
3.16 - * License. You can obtain a copy of the License at
3.17 - * http://www.netbeans.org/cddl-gplv2.html
3.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.19 - * specific language governing permissions and limitations under the
3.20 - * License. When distributing the software, include this License Header
3.21 - * Notice in each file and include the License file at
3.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.23 - * particular file as subject to the "Classpath" exception as provided
3.24 - * by Oracle in the GPL Version 2 section of the License file that
3.25 - * accompanied this code. If applicable, add the following below the
3.26 - * License Header, with the fields enclosed by brackets [] replaced by
3.27 - * your own identifying information:
3.28 - * "Portions Copyrighted [year] [name of copyright owner]"
3.29 - *
3.30 - * Contributor(s):
3.31 - *
3.32 - * The Original Software is NetBeans. The Initial Developer of the Original
3.33 - * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
3.34 - *
3.35 - * If you wish your version of this file to be governed by only the CDDL
3.36 - * or only the GPL Version 2, indicate your decision by adding
3.37 - * "[Contributor] elects to include this software in this distribution
3.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.39 - * single choice of license, a recipient has the option to distribute
3.40 - * your version of this file under either the CDDL, the GPL Version 2 or
3.41 - * to extend the choice of license to its licensees as provided above.
3.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
3.43 - * Version 2 license, then the option applies only if the new code is
3.44 - * made subject to such option by the copyright holder.
3.45 - */
3.46 -package org.netbeans.html.json.impl;
3.47 -
3.48 -/**
3.49 - *
3.50 - * @author Jaroslav Tulach <jtulach@netbeans.org>
3.51 - */
3.52 -public interface Callback<Data> {
3.53 - public void call(Data model, Object data, Object ev);
3.54 -}
4.1 --- a/json/src/main/java/org/netbeans/html/json/impl/FromJSON.java Mon Dec 23 09:30:10 2013 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,55 +0,0 @@
4.4 -/**
4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 - *
4.7 - * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
4.8 - *
4.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
4.10 - * Other names may be trademarks of their respective owners.
4.11 - *
4.12 - * The contents of this file are subject to the terms of either the GNU
4.13 - * General Public License Version 2 only ("GPL") or the Common
4.14 - * Development and Distribution License("CDDL") (collectively, the
4.15 - * "License"). You may not use this file except in compliance with the
4.16 - * License. You can obtain a copy of the License at
4.17 - * http://www.netbeans.org/cddl-gplv2.html
4.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.19 - * specific language governing permissions and limitations under the
4.20 - * License. When distributing the software, include this License Header
4.21 - * Notice in each file and include the License file at
4.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
4.23 - * particular file as subject to the "Classpath" exception as provided
4.24 - * by Oracle in the GPL Version 2 section of the License file that
4.25 - * accompanied this code. If applicable, add the following below the
4.26 - * License Header, with the fields enclosed by brackets [] replaced by
4.27 - * your own identifying information:
4.28 - * "Portions Copyrighted [year] [name of copyright owner]"
4.29 - *
4.30 - * Contributor(s):
4.31 - *
4.32 - * The Original Software is NetBeans. The Initial Developer of the Original
4.33 - * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
4.34 - *
4.35 - * If you wish your version of this file to be governed by only the CDDL
4.36 - * or only the GPL Version 2, indicate your decision by adding
4.37 - * "[Contributor] elects to include this software in this distribution
4.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.39 - * single choice of license, a recipient has the option to distribute
4.40 - * your version of this file under either the CDDL, the GPL Version 2 or
4.41 - * to extend the choice of license to its licensees as provided above.
4.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
4.43 - * Version 2 license, then the option applies only if the new code is
4.44 - * made subject to such option by the copyright holder.
4.45 - */
4.46 -package org.netbeans.html.json.impl;
4.47 -
4.48 -import net.java.html.BrwsrCtx;
4.49 -
4.50 -/**
4.51 - *
4.52 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.53 - */
4.54 -public interface FromJSON<Data> {
4.55 - public Class<Data> factoryFor();
4.56 - public Data read(BrwsrCtx c, Object d);
4.57 - public Data cloneTo(Object d, BrwsrCtx c);
4.58 -}
5.1 --- a/json/src/main/java/org/netbeans/html/json/impl/JSON.java Mon Dec 23 09:30:10 2013 +0100
5.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSON.java Mon Dec 23 15:06:51 2013 +0100
5.3 @@ -51,6 +51,7 @@
5.4 import org.apidesign.html.json.spi.FunctionBinding;
5.5 import org.apidesign.html.json.spi.JSONCall;
5.6 import org.apidesign.html.json.spi.PropertyBinding;
5.7 +import org.apidesign.html.json.spi.Proto;
5.8 import org.apidesign.html.json.spi.Technology;
5.9 import org.apidesign.html.json.spi.Transfer;
5.10 import org.apidesign.html.json.spi.WSTransfer;
5.11 @@ -326,22 +327,21 @@
5.12
5.13 }
5.14
5.15 - private static final Map<Class,FromJSON<?>> froms;
5.16 + private static final Map<Class,Proto.Type<?>> modelTypes;
5.17 static {
5.18 - Map<Class,FromJSON<?>> m = new HashMap<Class,FromJSON<?>>();
5.19 - froms = m;
5.20 + modelTypes = new HashMap<Class, Proto.Type<?>>();
5.21 }
5.22 - public static void register(FromJSON<?> from) {
5.23 - froms.put(from.factoryFor(), from);
5.24 + public static void register(Class c, Proto.Type<?> type) {
5.25 + modelTypes.put(c, type);
5.26 }
5.27
5.28 public static boolean isModel(Class<?> clazz) {
5.29 - return findFrom(clazz) != null;
5.30 + return findType(clazz) != null;
5.31 }
5.32
5.33 - private static FromJSON<?> findFrom(Class<?> clazz) {
5.34 + private static Proto.Type<?> findType(Class<?> clazz) {
5.35 for (int i = 0; i < 2; i++) {
5.36 - FromJSON<?> from = froms.get(clazz);
5.37 + Proto.Type<?> from = modelTypes.get(clazz);
5.38 if (from == null) {
5.39 initClass(clazz);
5.40 } else {
5.41 @@ -352,7 +352,7 @@
5.42 }
5.43
5.44 public static <Model> Model bindTo(Model model, BrwsrCtx c) {
5.45 - FromJSON<?> from = findFrom(model.getClass());
5.46 + Proto.Type<?> from = findType(model.getClass());
5.47 if (from == null) {
5.48 throw new IllegalArgumentException();
5.49 }
5.50 @@ -372,7 +372,7 @@
5.51 return modelClazz.cast(data.toString());
5.52 }
5.53 for (int i = 0; i < 2; i++) {
5.54 - FromJSON<?> from = froms.get(modelClazz);
5.55 + Proto.Type<?> from = modelTypes.get(modelClazz);
5.56 if (from == null) {
5.57 initClass(modelClazz);
5.58 } else {
6.1 --- a/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Mon Dec 23 09:30:10 2013 +0100
6.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/JSONList.java Mon Dec 23 15:06:51 2013 +0100
6.3 @@ -49,6 +49,7 @@
6.4 import java.util.Iterator;
6.5 import java.util.List;
6.6 import net.java.html.BrwsrCtx;
6.7 +import org.apidesign.html.json.spi.Proto;
6.8
6.9 /**
6.10 *
6.11 @@ -57,12 +58,11 @@
6.12 public final class JSONList<T> extends ArrayList<T> {
6.13 private final String name;
6.14 private final String[] deps;
6.15 - private Bindings[] model;
6.16 + private Proto proto;
6.17 private Runnable onchange;
6.18
6.19 - public JSONList(Bindings[] model, String name, String... deps) {
6.20 - assert model.length == 1;
6.21 - this.model = model;
6.22 + public JSONList(Proto proto, String name, String... deps) {
6.23 + this.proto = proto;
6.24 this.name = name;
6.25 this.deps = deps;
6.26 }
6.27 @@ -71,9 +71,9 @@
6.28 if (values == null || values.length == 0) {
6.29 return;
6.30 }
6.31 - if (this.model[0] != null || !isEmpty()) {
6.32 - throw new IllegalStateException();
6.33 - }
6.34 +// if (this.model[0] != null || !isEmpty()) {
6.35 +// throw new IllegalStateException();
6.36 +// }
6.37 super.addAll(Arrays.asList(values));
6.38 }
6.39
6.40 @@ -82,9 +82,9 @@
6.41 if (values == null || (len = Array.getLength(values)) == 0) {
6.42 return;
6.43 }
6.44 - if (this.model[0] != null || !isEmpty()) {
6.45 - throw new IllegalStateException();
6.46 - }
6.47 +// if (this.model[0] != null || !isEmpty()) {
6.48 +// throw new IllegalStateException();
6.49 +// }
6.50 for (int i = 0; i < len; i++) {
6.51 Object data = Array.get(values, i);
6.52 super.add((T)data);
6.53 @@ -187,7 +187,7 @@
6.54 }
6.55
6.56 private void notifyChange() {
6.57 - Bindings m = model[0];
6.58 + Bindings m = proto.getBindings();
6.59 if (m != null) {
6.60 m.valueHasMutated(name);
6.61 for (String dependant : deps) {
6.62 @@ -231,6 +231,6 @@
6.63 }
6.64
6.65 final Object koData() {
6.66 - return koData(this, model[0]);
6.67 + return koData(this, proto.getBindings());
6.68 }
6.69 }
7.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Mon Dec 23 09:30:10 2013 +0100
7.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Mon Dec 23 15:06:51 2013 +0100
7.3 @@ -218,22 +218,46 @@
7.4 w.append(body.toString());
7.5 w.append(" private static Class<" + inPckName(e) + "> modelFor() { return null; }\n");
7.6 w.append(" private ").append(className).append("(net.java.html.BrwsrCtx context) {\n");
7.7 - w.append(" this.proto = TYPE.protoFor(context);\n");
7.8 + w.append(" this.proto = TYPE.protoFor(this, context);\n");
7.9 + for (Prprt p : props) {
7.10 + if (p.array()) {
7.11 + final String tn = typeName(e, p);
7.12 + String[] gs = toGetSet(p.name(), tn, p.array());
7.13 + w.write(" this.prop_" + p.name() + " = new org.netbeans.html.json.impl.JSONList<" + tn + ">(proto, \""
7.14 + + p.name() + "\"");
7.15 + Collection<String> dependants = propsDeps.get(p.name());
7.16 + if (dependants != null) {
7.17 + for (String depProp : dependants) {
7.18 + w.write(", ");
7.19 + w.write('\"');
7.20 + w.write(depProp);
7.21 + w.write('\"');
7.22 + }
7.23 + }
7.24 + w.write(")");
7.25 +
7.26 + dependants = functionDeps.get(p.name());
7.27 + if (dependants != null) {
7.28 + w.write(".onChange(new Runnable() { public void run() {\n");
7.29 + for (String call : dependants) {
7.30 + w.append(" ").append(call);
7.31 + }
7.32 + w.write(" }})");
7.33 + }
7.34 + w.write(";\n");
7.35 + } else {
7.36 + boolean[] isModel = {false};
7.37 + boolean[] isEnum = {false};
7.38 + boolean isPrimitive[] = {false};
7.39 + String tn = checkType(p, isModel, isEnum, isPrimitive);
7.40 + if (isModel[0]) {
7.41 + w.write(" prop_" + p.name() + " = new " + tn + "();\n");
7.42 + }
7.43 + }
7.44 + }
7.45 w.append(" };\n");
7.46 w.append(" public ").append(className).append("() {\n");
7.47 w.append(" this(net.java.html.BrwsrCtx.findDefault(").append(className).append(".class));\n");
7.48 - for (Prprt p : props) {
7.49 - if (p.array()) {
7.50 - continue;
7.51 - }
7.52 - boolean[] isModel = {false};
7.53 - boolean[] isEnum = {false};
7.54 - boolean isPrimitive[] = {false};
7.55 - String tn = checkType(p, isModel, isEnum, isPrimitive);
7.56 - if (isModel[0]) {
7.57 - w.write(" prop_" + p.name() + " = new " + tn + "();\n");
7.58 - }
7.59 - }
7.60 w.append(" };\n");
7.61 if (props.length > 0) {
7.62 w.append(" public ").append(className).append("(");
7.63 @@ -292,7 +316,7 @@
7.64 }
7.65 }
7.66 w.append(" }\n");
7.67 - w.append(" @Override protected void setValue(" + className + " data, int type, Object value) {\n");
7.68 + w.append(" @Override public void setValue(" + className + " data, int type, Object value) {\n");
7.69 w.append(" switch (type) {\n");
7.70 for (int i = 0; i < propsGetSet.size(); i += 5) {
7.71 final String set = propsGetSet.get(i + 2);
7.72 @@ -307,7 +331,7 @@
7.73 }
7.74 w.append(" }\n");
7.75 w.append(" }\n");
7.76 - w.append(" @Override protected Object getValue(" + className + " data, int type) {\n");
7.77 + w.append(" @Override public Object getValue(" + className + " data, int type) {\n");
7.78 w.append(" switch (type) {\n");
7.79 for (int i = 0; i < propsGetSet.size(); i += 5) {
7.80 final String get = propsGetSet.get(i + 1);
7.81 @@ -318,7 +342,7 @@
7.82 w.append(" }\n");
7.83 w.append(" throw new UnsupportedOperationException();\n");
7.84 w.append(" }\n");
7.85 - w.append(" @Override protected void call(" + className + " model, int type, Object data, Object ev) {\n");
7.86 + w.append(" @Override public void call(" + className + " model, int type, Object data, Object ev) {\n");
7.87 w.append(" switch (type) {\n");
7.88 for (int i = 0; i < functions.size(); i += 2) {
7.89 final String name = functions.get(i);
7.90 @@ -327,8 +351,8 @@
7.91 w.append(" }\n");
7.92 w.append(" throw new UnsupportedOperationException();\n");
7.93 w.append(" }\n");
7.94 - w.append(" protected " + className + " read(net.java.html.BrwsrCtx c, Object json) { return new " + className + "(c, json); }\n");
7.95 - w.append(" protected " + className + " cloneTo(Object o, net.java.html.BrwsrCtx c) { return ((" + className + ")o).clone(c); }\n");
7.96 + w.append(" @Override public " + className + " read(net.java.html.BrwsrCtx c, Object json) { return new " + className + "(c, json); }\n");
7.97 + w.append(" @Override public " + className + " cloneTo(Object o, net.java.html.BrwsrCtx c) { return ((" + className + ")o).clone(c); }\n");
7.98 w.append(" }\n");
7.99 w.append(" private ").append(className).append("(net.java.html.BrwsrCtx c, Object json) {\n");
7.100 w.append(" this(c);\n");
7.101 @@ -431,7 +455,7 @@
7.102 w.write(" public boolean equals(Object o) {\n");
7.103 w.write(" if (o == this) return true;\n");
7.104 w.write(" if (o instanceof org.netbeans.html.json.impl.WrapperObject) {\n");
7.105 - w.write(" ((org.netbeans.html.json.impl.WrapperObject)o).setRealObject(intKnckt().koData());\n");
7.106 +// w.write(" ((org.netbeans.html.json.impl.WrapperObject)o).setRealObject(intKnckt().koData());\n");
7.107 w.write(" return false;\n");
7.108 w.write(" }\n");
7.109 w.write(" if (!(o instanceof " + className + ")) return false;\n");
7.110 @@ -474,28 +498,7 @@
7.111 String castTo;
7.112
7.113 if (p.array()) {
7.114 - w.write(" private org.netbeans.html.json.impl.JSONList<" + tn + "> prop_" + p.name() + " = new org.netbeans.html.json.impl.JSONList<" + tn + ">(ko, \""
7.115 - + p.name() + "\"");
7.116 - Collection<String> dependants = deps.get(p.name());
7.117 - if (dependants != null) {
7.118 - for (String depProp : dependants) {
7.119 - w.write(", ");
7.120 - w.write('\"');
7.121 - w.write(depProp);
7.122 - w.write('\"');
7.123 - }
7.124 - }
7.125 - w.write(")");
7.126 -
7.127 - dependants = functionDeps.get(p.name());
7.128 - if (dependants != null) {
7.129 - w.write(".onChange(new Runnable() { public void run() {\n");
7.130 - for (String call : dependants) {
7.131 - w.append(" ").append(call);
7.132 - }
7.133 - w.write(" }})");
7.134 - }
7.135 - w.write(";\n");
7.136 + w.write(" private final org.netbeans.html.json.impl.JSONList<" + tn + "> prop_" + p.name() + ";\n");
7.137
7.138 castTo = "java.util.List";
7.139 w.write(" public java.util.List<" + tn + "> " + gs[0] + "() {\n");
8.1 --- a/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Mon Dec 23 09:30:10 2013 +0100
8.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java Mon Dec 23 15:06:51 2013 +0100
8.3 @@ -46,6 +46,7 @@
8.4 import org.apidesign.html.json.spi.FunctionBinding;
8.5 import org.apidesign.html.json.spi.JSONCall;
8.6 import org.apidesign.html.json.spi.PropertyBinding;
8.7 +import org.apidesign.html.json.spi.Proto;
8.8
8.9 /**
8.10 *
8.11 @@ -88,23 +89,25 @@
8.12 public final String name;
8.13 public final boolean readOnly;
8.14 private final M model;
8.15 - private final SetAndGet<M> access;
8.16 + private final Proto.Type<M> access;
8.17 private final Bindings<?> bindings;
8.18 + private final int index;
8.19
8.20 - public PBData(Bindings<?> bindings, String name, M model, SetAndGet<M> access, boolean readOnly) {
8.21 + public PBData(Bindings<?> bindings, String name, int index, M model, Proto.Type<M> access, boolean readOnly) {
8.22 this.bindings = bindings;
8.23 this.name = name;
8.24 + this.index = index;
8.25 this.model = model;
8.26 this.access = access;
8.27 this.readOnly = readOnly;
8.28 }
8.29
8.30 public void setValue(Object v) {
8.31 - access.setValue(model, v);
8.32 + access.setValue(model, index, v);
8.33 }
8.34
8.35 public Object getValue() {
8.36 - return access.getValue(model);
8.37 + return access.getValue(model, index);
8.38 }
8.39
8.40 public boolean isReadOnly() {
8.41 @@ -119,17 +122,19 @@
8.42 public static final class FBData<M> {
8.43 public final String name;
8.44 private final M model;
8.45 - private final Callback<M> access;
8.46 + private final Proto.Type<M> access;
8.47 + private final int index;
8.48
8.49 - public FBData(String name, M model, Callback<M> access) {
8.50 + public FBData(String name, int index, M model, Proto.Type<M> access) {
8.51 this.name = name;
8.52 + this.index = index;
8.53 this.model = model;
8.54 this.access = access;
8.55 }
8.56
8.57
8.58 public void call(Object data, Object ev) {
8.59 - access.call(model, data, ev);
8.60 + access.call(model, index, data, ev);
8.61 }
8.62 } // end of FBData
8.63 }
9.1 --- a/json/src/main/java/org/netbeans/html/json/impl/SetAndGet.java Mon Dec 23 09:30:10 2013 +0100
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,54 +0,0 @@
9.4 -/**
9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9.6 - *
9.7 - * Copyright 2013-2013 Oracle and/or its affiliates. All rights reserved.
9.8 - *
9.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9.10 - * Other names may be trademarks of their respective owners.
9.11 - *
9.12 - * The contents of this file are subject to the terms of either the GNU
9.13 - * General Public License Version 2 only ("GPL") or the Common
9.14 - * Development and Distribution License("CDDL") (collectively, the
9.15 - * "License"). You may not use this file except in compliance with the
9.16 - * License. You can obtain a copy of the License at
9.17 - * http://www.netbeans.org/cddl-gplv2.html
9.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
9.19 - * specific language governing permissions and limitations under the
9.20 - * License. When distributing the software, include this License Header
9.21 - * Notice in each file and include the License file at
9.22 - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
9.23 - * particular file as subject to the "Classpath" exception as provided
9.24 - * by Oracle in the GPL Version 2 section of the License file that
9.25 - * accompanied this code. If applicable, add the following below the
9.26 - * License Header, with the fields enclosed by brackets [] replaced by
9.27 - * your own identifying information:
9.28 - * "Portions Copyrighted [year] [name of copyright owner]"
9.29 - *
9.30 - * Contributor(s):
9.31 - *
9.32 - * The Original Software is NetBeans. The Initial Developer of the Original
9.33 - * Software is Oracle. Portions Copyright 2013-2013 Oracle. All Rights Reserved.
9.34 - *
9.35 - * If you wish your version of this file to be governed by only the CDDL
9.36 - * or only the GPL Version 2, indicate your decision by adding
9.37 - * "[Contributor] elects to include this software in this distribution
9.38 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
9.39 - * single choice of license, a recipient has the option to distribute
9.40 - * your version of this file under either the CDDL, the GPL Version 2 or
9.41 - * to extend the choice of license to its licensees as provided above.
9.42 - * However, if you add GPL Version 2 code and therefore, elected the GPL
9.43 - * Version 2 license, then the option applies only if the new code is
9.44 - * made subject to such option by the copyright holder.
9.45 - */
9.46 -package org.netbeans.html.json.impl;
9.47 -
9.48 -import org.apidesign.html.json.spi.PropertyBinding;
9.49 -
9.50 -/** A way to implement a {@link PropertyBinding}.
9.51 - *
9.52 - * @author Jaroslav Tulach <jtulach@netbeans.org>
9.53 - */
9.54 -public interface SetAndGet<Data> {
9.55 - public void setValue(Data data, Object value);
9.56 - public Object getValue(Data data);
9.57 -}