Search in sources :

Example 1 with ClassModel

use of org.platformlayer.model.ClassModel in project platformlayer by platformlayer.

the class GwtCodegenFileVisitor method processClassRequestFactory.

private void processClassRequestFactory(Class<?> clazz) throws MojoExecutionException {
    Map<String, Object> model = new HashMap<String, Object>();
    ClassModel classModel = new ClassModel();
    classModel.className = clazz.getSimpleName();
    classModel.proxyClassName = classModel.className + "Proxy";
    classModel.serviceClassName = classModel.className + "GwtService";
    classModel.editorClassName = classModel.className + "Editor";
    for (Field field : clazz.getFields()) {
        FieldModel fieldModel = new FieldModel();
        Class<?> type = field.getType();
        if (!isNativeType(type)) {
            continue;
        }
        Class<?> accessorType = type;
        if (accessorType.isPrimitive()) {
            accessorType = Utils.getBoxedType(accessorType);
        }
        String fieldName = field.getName();
        String beanName = Utils.capitalize(fieldName);
        fieldModel.type = type.getName();
        fieldModel.accessorType = accessorType.getName();
        fieldModel.beanName = beanName;
        fieldModel.name = fieldName;
        classModel.fields.add(fieldModel);
    }
    model.put("className", classModel.className);
    model.put("proxyClassName", classModel.proxyClassName);
    model.put("serviceClassName", classModel.serviceClassName);
    model.put("editorClassName", classModel.editorClassName);
    model.put("fields", classModel.fields);
    if (gwtBasePathComponents == null) {
        throw new MojoExecutionException("Did not find .gwt.xml file above " + clazz);
    }
    File gwtOutDir = new File(outDir, Joiner.on("/").join(gwtBasePathComponents));
    Utils.mkdirs(gwtOutDir);
    String gwtPackage = Joiner.on(".").join(gwtBasePathComponents);
    model.put("gwtPackage", gwtPackage);
    String modelPackage = Joiner.on(".").join(getPathComponents());
    model.put("modelPackage", modelPackage);
    String editorPackage = gwtPackage + ".client";
    model.put("editorPackage", editorPackage);
    runTemplate("requestfactory/GwtProxy.ftl", model, new File(new File(gwtOutDir, "shared"), classModel.proxyClassName + ".java"));
    runTemplate("requestfactory/GwtRequestFactory.ftl", model, new File(new File(gwtOutDir, "shared"), classModel.className + "RequestFactory.java"));
    runTemplate("requestfactory/GwtService.ftl", model, new File(new File(gwtOutDir, "server"), classModel.serviceClassName + ".java"));
}
Also used : Field(java.lang.reflect.Field) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ClassModel(org.platformlayer.model.ClassModel) FieldModel(org.platformlayer.model.FieldModel) File(java.io.File)

Aggregations

File (java.io.File)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ClassModel (org.platformlayer.model.ClassModel)1 FieldModel (org.platformlayer.model.FieldModel)1