All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.apt.generate.ObserverCodeGenerate Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.apt.generate;

import br.com.jarch.util.type.CodeType;
import br.com.jarch.util.type.ModuleType;

import javax.lang.model.element.Element;

import static br.com.jarch.util.ProcessorUtils.addCode;
import static br.com.jarch.util.ProcessorUtils.addLineBlank;

public class ObserverCodeGenerate extends BaseCodeGenerate {

    public static void generate(Element element, String useCase, String nameSubPackage) {
        new ObserverCodeGenerate(element, useCase, nameSubPackage).generate();
    }

    ObserverCodeGenerate(Element element, String useCase, String nameSubPackage) {
        super(element, useCase, nameSubPackage);
    }

    @Override
    public ModuleType getModule() {
        return ModuleType.CLIENT;
    }

    @Override
    public CodeType getType() {
        return CodeType.OBSERVER;
    }

    @Override
    public String getContent() {
        StringBuilder sbListCode = new StringBuilder();
        addPackage(sbListCode);
        addImports(sbListCode);
        addBody(sbListCode);
        return sbListCode.toString();
    }

    private void addPackage(StringBuilder sbListCode) {
        addCode(sbListCode, "package " + getNamePackage() + ";");
        addLineBlank(sbListCode);
    }

    private void addImports(StringBuilder sbListCode) {
        addCode(sbListCode, "import br.com.jarch.annotation.JArchEventLoadCrud;");
        addCode(sbListCode, "import br.com.jarch.crud.util.InitializeUtils;");
        addLineBlank(sbListCode);
        addCode(sbListCode, "import javax.enterprise.event.Observes;");
        addLineBlank(sbListCode);
    }

    private void addBody(StringBuilder sbListCode) {
        addCode(sbListCode, "public class " + getName() + " {");
        addLineBlank(sbListCode);
        addCode(sbListCode, "\tprivate void loadCrud(@Observes @JArchEventLoadCrud " + getNameEntity() + " entity) {");
        addCode(sbListCode, "\t\tInitializeUtils.initializeCollectionLazy(entity);");
        addCode(sbListCode, "\t}");
        addCode(sbListCode, "}");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy