This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 248917
Collapse All | Expand All

(-)a/json/src/main/java/org/netbeans/html/json/impl/Bindings.java (-2 / +5 lines)
Lines 60-67 Link Here
60
        this.bp = bp;
60
        this.bp = bp;
61
    }
61
    }
62
    
62
    
63
    public <M> PropertyBinding registerProperty(String propName, int index, M model, Proto.Type<M> access, boolean readOnly) {
63
    public <M> PropertyBinding registerProperty(
64
        return PropertyBindingAccessor.create(access, this, propName, index, model, readOnly);
64
            String propName, int index, M model,
65
            Proto.Type<M> access, boolean readOnly, Class<?> type
66
    ) {
67
        return PropertyBindingAccessor.create(access, this, propName, index, model, readOnly, type);
65
    }
68
    }
66
69
67
    public static Bindings<?> apply(BrwsrCtx c, Object model) {
70
    public static Bindings<?> apply(BrwsrCtx c, Object model) {
(-)a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java (+1 lines)
Lines 320-325 Link Here
320
                {
320
                {
321
                    for (int i = 0; i < propsGetSet.size(); i++) {
321
                    for (int i = 0; i < propsGetSet.size(); i++) {
322
                        w.append("      registerProperty(\"").append(propsGetSet.get(i).name).append("\", ");
322
                        w.append("      registerProperty(\"").append(propsGetSet.get(i).name).append("\", ");
323
                        w.append(propsGetSet.get(i).type).append(".class, ");
323
                        w.append((i) + ", " + propsGetSet.get(i).readOnly + ");\n");
324
                        w.append((i) + ", " + propsGetSet.get(i).readOnly + ");\n");
324
                    }
325
                    }
325
                }
326
                }
(-)a/json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java (-3 / +6 lines)
Lines 65-72 Link Here
65
    }
65
    }
66
66
67
    protected abstract <M> PropertyBinding newBinding(
67
    protected abstract <M> PropertyBinding newBinding(
68
        Proto.Type<M> access, Bindings<?> bindings, String name, int index, M model, boolean readOnly
68
            Proto.Type<M> access, Bindings<?> bindings, String name, 
69
            int index, M model, boolean readOnly, Class<?> type
69
    );
70
    );
71
    
70
    protected abstract JSONCall newCall(
72
    protected abstract JSONCall newCall(
71
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter,
73
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter,
72
        String method, Object data
74
        String method, Object data
Lines 87-95 Link Here
87
    }
89
    }
88
    
90
    
89
    static <M> PropertyBinding create(
91
    static <M> PropertyBinding create(
90
        Proto.Type<M> access, Bindings<?> bindings, String name, int index, M model , boolean readOnly
92
            Proto.Type<M> access, Bindings<?> bindings, String name,
93
            int index, M model, boolean readOnly, Class<?> type
91
    ) {
94
    ) {
92
        return DEFAULT.newBinding(access, bindings, name, index, model, readOnly);
95
        return DEFAULT.newBinding(access, bindings, name, index, model, readOnly, type);
93
    }
96
    }
94
    static JSONCall createCall(
97
    static JSONCall createCall(
95
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, 
98
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, 
(-)a/json/src/main/java/org/netbeans/html/json/spi/PropertyBinding.java (-4 / +22 lines)
Lines 91-100 Link Here
91
91
92
            @Override
92
            @Override
93
            protected <M> PropertyBinding newBinding(
93
            protected <M> PropertyBinding newBinding(
94
                Proto.Type<M> access, Bindings<?> bindings, String name,
94
                    Proto.Type<M> access, Bindings<?> bindings,
95
                int index, M model, boolean readOnly
95
                    String name, int index, M model, boolean readOnly, Class<?> type
96
            ) {
96
            ) {
97
                return new Impl(bindings, name, index, model, access, readOnly);
97
                return new Impl(bindings, name, index, model, access, readOnly, type);
98
            }
98
            }
99
        };
99
        };
100
    }
100
    }
Lines 125-130 Link Here
125
     */
125
     */
126
    public abstract boolean isReadOnly();
126
    public abstract boolean isReadOnly();
127
    
127
    
128
    /** The type of the property. This is the type one can expect
129
     * when {@link #getValue() getValue} method is called. In case the type
130
     * is not known, return {@link Object}.
131
     * @return a class of the type of the property
132
     * @since 1.1
133
     */
134
    public abstract Class<?> type();
135
    
128
    private static final class Impl<M> extends PropertyBinding {
136
    private static final class Impl<M> extends PropertyBinding {
129
        public final String name;
137
        public final String name;
130
        public final boolean readOnly;
138
        public final boolean readOnly;
Lines 132-145 Link Here
132
        private final Proto.Type<M> access;
140
        private final Proto.Type<M> access;
133
        private final Bindings<?> bindings;
141
        private final Bindings<?> bindings;
134
        private final int index;
142
        private final int index;
143
        private final Class<?> type;
135
144
136
        public Impl(Bindings<?> bindings, String name, int index, M model, Proto.Type<M> access, boolean readOnly) {
145
        public Impl(
146
            Bindings<?> bindings, String name, int index, 
147
            M model, Proto.Type<M> access, boolean readOnly, Class<?> type
148
        ) {
137
            this.bindings = bindings;
149
            this.bindings = bindings;
138
            this.name = name;
150
            this.name = name;
139
            this.index = index;
151
            this.index = index;
140
            this.model = model;
152
            this.model = model;
141
            this.access = access;
153
            this.access = access;
142
            this.readOnly = readOnly;
154
            this.readOnly = readOnly;
155
            this.type = type;
143
        }
156
        }
144
157
145
        @Override
158
        @Override
Lines 163-168 Link Here
163
        public String getPropertyName() {
176
        public String getPropertyName() {
164
            return name;
177
            return name;
165
        }
178
        }
179
180
        @Override
181
        public Class<?> type() {
182
            return type;
183
        }
166
    } // end of PBData
184
    } // end of PBData
167
    
185
    
168
}
186
}
(-)a/json/src/main/java/org/netbeans/html/json/spi/Proto.java (-1 / +21 lines)
Lines 461-467 Link Here
461
            PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length];
461
            PropertyBinding[] pb = new PropertyBinding[type.propertyNames.length];
462
            for (int i = 0; i < pb.length; i++) {
462
            for (int i = 0; i < pb.length; i++) {
463
                pb[i] = b.registerProperty(
463
                pb[i] = b.registerProperty(
464
                    type.propertyNames[i], i, obj, type, type.propertyReadOnly[i]
464
                    type.propertyNames[i], i, obj, type, 
465
                    type.propertyReadOnly[i],
466
                    type.propertyTypes[i]
465
                );
467
                );
466
            }
468
            }
467
            FunctionBinding[] fb = new FunctionBinding[type.functions.length];
469
            FunctionBinding[] fb = new FunctionBinding[type.functions.length];
Lines 500-505 Link Here
500
    public static abstract class Type<Model> {
502
    public static abstract class Type<Model> {
501
        private final Class<Model> clazz;
503
        private final Class<Model> clazz;
502
        private final String[] propertyNames;
504
        private final String[] propertyNames;
505
        private final Class[] propertyTypes;
503
        private final boolean[] propertyReadOnly;
506
        private final boolean[] propertyReadOnly;
504
        private final String[] functions;
507
        private final String[] functions;
505
508
Lines 522-527 Link Here
522
            }
525
            }
523
            this.clazz = clazz;
526
            this.clazz = clazz;
524
            this.propertyNames = new String[properties];
527
            this.propertyNames = new String[properties];
528
            this.propertyTypes = new Class[properties];
525
            this.propertyReadOnly = new boolean[properties];
529
            this.propertyReadOnly = new boolean[properties];
526
            this.functions = new String[functions];
530
            this.functions = new String[functions];
527
            JSON.register(clazz, this);
531
            JSON.register(clazz, this);
Lines 535-542 Link Here
535
         * @param readOnly is the property read only?
539
         * @param readOnly is the property read only?
536
         */
540
         */
537
        protected final void registerProperty(String name, int index, boolean readOnly) {
541
        protected final void registerProperty(String name, int index, boolean readOnly) {
542
            registerProperty(name, Object.class, index, readOnly);
543
        }
544
        
545
        /** Registers property for the type. It is expected each index
546
         * is initialized only once.
547
         * 
548
         * @param name name of the property
549
         * @param type class type of the property
550
         * @param index index of the property
551
         * @param readOnly is the property read only?
552
         * @since 1.1
553
         */
554
        protected final void registerProperty(
555
            String name, Class<?> type, int index, boolean readOnly
556
        ) {
538
            assert propertyNames[index] == null;
557
            assert propertyNames[index] == null;
539
            propertyNames[index] = name;
558
            propertyNames[index] = name;
559
            propertyTypes[index] = type;
540
            propertyReadOnly[index] = readOnly;
560
            propertyReadOnly[index] = readOnly;
541
        }
561
        }
542
562
(-)a/json/src/test/java/net/java/html/json/MapModelTest.java (+2 lines)
Lines 85-90 Link Here
85
        One o = (One)v;
85
        One o = (One)v;
86
        assertEquals(o.changes, 1, "One change so far");
86
        assertEquals(o.changes, 1, "One change so far");
87
        assertFalse(o.pb.isReadOnly(), "Mutable property");
87
        assertFalse(o.pb.isReadOnly(), "Mutable property");
88
        assertEquals(o.pb.type(), String.class, "Type is string");
88
        
89
        
89
        assertEquals(o.get(), "Jarda", "Value should be in the map");
90
        assertEquals(o.get(), "Jarda", "Value should be in the map");
90
        
91
        
Lines 132-137 Link Here
132
        One o = (One)v;
133
        One o = (One)v;
133
        
134
        
134
        o.set("FEMALE");
135
        o.set("FEMALE");
136
        assertEquals(o.pb.type(), Sex.class, "enum type");
135
137
136
        assertEquals(p.getSex(), Sex.FEMALE, "Changed to female");
138
        assertEquals(p.getSex(), Sex.FEMALE, "Changed to female");
137
    }
139
    }

Return to bug 248917