Package org.slim3.gen.desc

Examples of org.slim3.gen.desc.JsonAnnotation


     *            the prnter
     */
    protected void printIncrementVersionMethod(final Printer printer) {
        printer.println("@Override");
        printer.println("protected void incrementVersion(Object model) {");
        final AttributeMetaDesc attr =
            modelMetaDesc.getVersionAttributeMetaDesc();
        if (attr != null) {
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            DataType dataType = attr.getDataType();
            dataType.accept(
                new SimpleDataTypeVisitor<Void, Void, RuntimeException>() {

                    @Override
                    protected Void defaultAction(DataType type, Void p)
                            throws RuntimeException {
                        printer
                            .println(
                                "    throw new IllegalStateException(\"The version property of the model(%1$s) is not defined.\");",
                                modelMetaDesc.getModelClassName());
                        return null;
                    }

                    @Override
                    public Void visitPrimitiveLongType(PrimitiveLongType type,
                            Void p) throws RuntimeException {
                        printer.println(
                            "    m.%1$s(m.%2$s() + 1L);",
                            attr.getWriteMethodName(),
                            attr.getReadMethodName());
                        return null;
                    }

                    @Override
                    public Void visitLongType(LongType type, Void p)
                            throws RuntimeException {
                        printer
                            .println(
                                "    long version = m.%1$s() != null ? m.%1$s().longValue() : 0L;",
                                attr.getReadMethodName());
                        printer.println(
                            "    m.%1$s(Long.valueOf(version + 1L));",
                            attr.getWriteMethodName());
                        return null;
                    }

                },
                null);
View Full Code Here


     */
    protected void printGetKeyMethod(final Printer printer) {
        printer.println("@Override");
        printer
            .println("protected com.google.appengine.api.datastore.Key getKey(Object model) {");
        final AttributeMetaDesc attr = modelMetaDesc.getKeyAttributeMetaDesc();
        if (attr == null) {
            printer
                .println(
                    "    throw new IllegalStateException(\"The key property of the model(%1$s) is not defined.\");",
                    modelMetaDesc.getModelClassName());
        } else {
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            printer.println("    return m.%1$s();", attr.getReadMethodName());
        }
        printer.println("}");
        printer.println();
    }
View Full Code Here

     */
    protected void printSetKeyMethod(final Printer printer) {
        printer.println("@Override");
        printer
            .println("protected void setKey(Object model, com.google.appengine.api.datastore.Key key) {");
        final AttributeMetaDesc attr = modelMetaDesc.getKeyAttributeMetaDesc();
        if (attr == null) {
            printer
                .println(
                    "    throw new IllegalStateException(\"The key property of the model(%1$s) is not defined.\");",
                    modelMetaDesc.getModelClassName());
        } else {
            printer.println("    validateKey(key);");
            printer.println(
                "    %1$s m = (%1$s) model;",
                modelMetaDesc.getModelClassName());
            printer.println("    m.%1$s(key);", attr.getWriteMethodName());
        }
        printer.println("}");
        printer.println();
    }
View Full Code Here

                    .getAttributeMetaDescList()) {
                    if (attr.getReadMethodName() == null)
                        continue;
                    valueExp = "m." + attr.getReadMethodName() + "()";
                    indent = 0;
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dataType = attr.getDataType();
                    if(dataType instanceof InverseModelRefType && !ja.hasIgnore()){
                        continue;
                    }
                    String cn = ja.getCoderClassName();
                    coderExp = encoders.get(cn);
                    if (coderExp == null) {
                        String vn = "encoder" + encoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
                        encoders.put(cn, vn);
                    }
                    if (!(dataType instanceof CorePrimitiveType)
                        && ja.isIgnoreNull()) {
                        printer.print("if(%s != null", valueExp);
                        if (dataType instanceof TextType) {
                            printer.printWithoutIndent(
                                " && %s.getValue() != null",
                                valueExp);
                        } else if (dataType instanceof BlobType) {
                            printer.printWithoutIndent(
                                " && %s.getBytes() != null",
                                valueExp);
                        } else if (dataType instanceof ModelRefType) {
                            printer.printWithoutIndent(
                                " && %s.getKey() != null",
                                valueExp);
                        } else if (dataType instanceof InverseModelRefType) {
                            printer.printWithoutIndent(
                                " && getKey(m) != null"
                                );
                        }
                        printer.printlnWithoutIndent("){");
                        printer.indent();
                        indent++;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "writer.setNextPropertyName(\"%1$s\");",
View Full Code Here

                    "%s decoder0 = new %1$s();",
                    "org.slim3.datastore.json.Default");
                decoders.put("org.slim3.datastore.json.Default", "decoder0");
                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dt = attr.getDataType();
                    if(dt instanceof InverseModelRefType)
                        continue;
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "reader = rootReader.newObjectReader(\"%s\");",
                        name);
                    String cn = ja.getCoderClassName();
                    coderExp = decoders.get(cn);
                    if (coderExp == null) {
                        String vn = "decoder" + decoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
View Full Code Here

                printer.println("%s encoder = null;", JsonCoder);
                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    valueExp = "m." + attr.getReadMethodName() + "()";
                    indent = 0;
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dataType = attr.getDataType();
                    if (!isSupportedForJson(dataType)) {
                        printer.println("// %s is not supported.", dataType
                            .getClassName());
                        continue;
                    }
                    if (!(dataType instanceof CorePrimitiveType)
                        && ja.isIgnoreNull()) {
                        printer.print("if(%s != null", valueExp);
                        if (dataType instanceof TextType) {
                            printer.printWithoutIndent(
                                " && %s.getValue() != null",
                                valueExp);
                        } else if (dataType instanceof BlobType) {
                            printer.printWithoutIndent(
                                " && %s.getBytes() != null",
                                valueExp);
                        } else if (dataType instanceof ModelRefType) {
                            printer.printWithoutIndent(
                                " && %s.getKey() != null",
                                valueExp);
                        }
                        printer.printlnWithoutIndent("){");
                        printer.indent();
                        indent++;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer
                        .println("writer.setNextPropertyName(\"%1$s\");", name);
                    printer.println("encoder = new %s();", ja
                        .getCoderClassName());
                    dataType.accept(this, attr);
                    for (int i = 0; i < indent; i++) {
                        printer.unindent();
                        printer.println("}");
View Full Code Here

                    .getModelClassName());
                printer.println("%s reader = null;", JsonReader);
                printer.println("%s decoder = null;", JsonCoder);
                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dt = attr.getDataType();
                    if (!isSupportedForJson(dt)) {
                        printer.println("// %s is not supported.", dt
                            .getClassName());
                        continue;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "reader = rootReader.newObjectReader(\"%s\");",
                        name);
                    printer.println("decoder = new %s();", ja
                        .getCoderClassName());
                    setterExp = "m." + attr.getWriteMethodName();
                    getterExp = "m." + attr.getReadMethodName() + "()";
                    dt.accept(this, attr);
                }
View Full Code Here

                    .getJsonAttributeMetaDescList()) {
                    if (attr.getReadMethodName() == null)
                        continue;
                    valueExp = "m." + attr.getReadMethodName() + "()";
                    indent = 0;
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dataType = attr.getDataType();
                    if(dataType instanceof InverseModelRefType && !ja.hasIgnore()){
                        continue;
                    }
                    String cn = ja.getCoderClassName();
                    coderExp = encoders.get(cn);
                    if (coderExp == null) {
                        String vn = "encoder" + encoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
                        encoders.put(cn, vn);
                    }
                    if (!(dataType instanceof CorePrimitiveType)
                        && ja.isIgnoreNull()) {
                        printer.print("if(%s != null", valueExp);
                        if (dataType instanceof TextType) {
                            printer.printWithoutIndent(
                                " && %s.getValue() != null",
                                valueExp);
                        } else if (dataType instanceof BlobType) {
                            printer.printWithoutIndent(
                                " && %s.getBytes() != null",
                                valueExp);
                        } else if (dataType instanceof ModelRefType) {
                            printer.printWithoutIndent(
                                " && %s.getKey() != null",
                                valueExp);
                        } else if (dataType instanceof InverseModelRefType) {
                            printer.printWithoutIndent(
                                " && getKey(m) != null"
                                );
                        }
                        printer.printlnWithoutIndent("){");
                        printer.indent();
                        indent++;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "writer.setNextPropertyName(\"%1$s\");",
View Full Code Here

                    .getAttributeMetaDescList()) {
                    if (attr.getReadMethodName() == null)
                        continue;
                    valueExp = "m." + attr.getReadMethodName() + "()";
                    indent = 0;
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    String cn = ja.getCoderClassName();
                    coderExp = encoders.get(cn);
                    if (coderExp == null) {
                        String vn = "encoder" + encoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
                        encoders.put(cn, vn);
                    }
                    DataType dataType = attr.getDataType();
                    if (!(dataType instanceof CorePrimitiveType)
                        && ja.isIgnoreNull()) {
                        printer.print("if(%s != null", valueExp);
                        if (dataType instanceof TextType) {
                            printer.printWithoutIndent(
                                " && %s.getValue() != null",
                                valueExp);
                        } else if (dataType instanceof BlobType) {
                            printer.printWithoutIndent(
                                " && %s.getBytes() != null",
                                valueExp);
                        } else if (dataType instanceof ModelRefType) {
                            printer.printWithoutIndent(
                                " && %s.getKey() != null",
                                valueExp);
                        }
                        printer.printlnWithoutIndent("){");
                        printer.indent();
                        indent++;
                    }
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "writer.setNextPropertyName(\"%1$s\");",
View Full Code Here

                    "%s decoder0 = new %1$s();",
                    "org.slim3.datastore.json.Default");
                decoders.put("org.slim3.datastore.json.Default", "decoder0");
                for (AttributeMetaDesc attr : modelMetaDesc
                    .getAttributeMetaDescList()) {
                    JsonAnnotation ja = attr.getJson();
                    if (ja.isIgnore())
                        continue;
                    DataType dt = attr.getDataType();
                    String name = ja.getAlias();
                    if (name.length() == 0) {
                        name = attr.getAttributeName();
                    }
                    printer.println(
                        "reader = rootReader.newObjectReader(\"%s\");",
                        name);
                    String cn = ja.getCoderClassName();
                    coderExp = decoders.get(cn);
                    if (coderExp == null) {
                        String vn = "decoder" + decoders.size();
                        coderExp = vn;
                        printer.println("%s %s = new %1$s();", cn, vn);
View Full Code Here

TOP

Related Classes of org.slim3.gen.desc.JsonAnnotation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.