1.1 --- a/json/src/main/java/org/apidesign/html/json/impl/ModelProcessor.java Fri Aug 09 11:22:21 2013 +0200
1.2 +++ b/json/src/main/java/org/apidesign/html/json/impl/ModelProcessor.java Fri Aug 09 13:08:36 2013 +0200
1.3 @@ -196,6 +196,18 @@
1.4 w.append(" };\n");
1.5 w.append(" public ").append(className).append("() {\n");
1.6 w.append(" this(net.java.html.BrwsrCtx.findDefault(").append(className).append(".class));\n");
1.7 + for (Prprt p : props) {
1.8 + if (p.array()) {
1.9 + continue;
1.10 + }
1.11 + boolean[] isModel = {false};
1.12 + boolean[] isEnum = {false};
1.13 + boolean isPrimitive[] = {false};
1.14 + String tn = checkType(p, isModel, isEnum, isPrimitive);
1.15 + if (isModel[0]) {
1.16 + w.write(" prop_" + p.name() + " = new " + tn + "();\n");
1.17 + }
1.18 + }
1.19 w.append(" };\n");
1.20 w.append(" private org.apidesign.html.json.impl.Bindings intKnckt() {\n");
1.21 w.append(" if (ko != null) return ko;\n");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/json/src/test/java/org/apidesign/html/json/impl/ConstructorTest.java Fri Aug 09 13:08:36 2013 +0200
2.3 @@ -0,0 +1,49 @@
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 +import net.java.html.json.Model;
2.27 +import net.java.html.json.Property;
2.28 +import static org.testng.Assert.assertNotNull;
2.29 +import org.testng.annotations.Test;
2.30 +
2.31 +/**
2.32 + *
2.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.34 + */
2.35 +@Model(className="Man", properties={
2.36 + @Property(name = "name", type = String.class),
2.37 + @Property(name = "other", type = Address.class, array = true),
2.38 + @Property(name = "primary", type = Address.class),
2.39 + @Property(name = "childrenNames", type = String.class, array = true)
2.40 +})
2.41 +public class ConstructorTest {
2.42 + @Model(className = "Address", properties = {
2.43 + @Property(name = "town", type = String.class)
2.44 + })
2.45 + static final class AddressModel {
2.46 + }
2.47 +
2.48 + @Test public void initializedByDefault() {
2.49 + Man m = new Man();
2.50 + assertNotNull(m.getPrimary(), "Single subobjects are initialized");
2.51 + }
2.52 +}