br.com.jarch.apt.generate.BaseCodeGenerate Maven / Gradle / Ivy
package br.com.jarch.apt.generate;
import br.com.jarch.util.FileUtils;
import br.com.jarch.util.LogUtils;
import br.com.jarch.util.ProcessorUtils;
import br.com.jarch.util.type.CodeType;
import br.com.jarch.util.type.ModuleType;
import javax.lang.model.element.Element;
import java.io.File;
import java.io.IOException;
public abstract class BaseCodeGenerate implements ICodeGenerate {
private final Element element;
private final String useCase;
private final String nameSubPackage;
private final File file;
private final boolean renameWsToWeb;
private File folder;
BaseCodeGenerate(Element element, String useCase, String nameSubPackage) {
this.element = element;
this.useCase = useCase;
this.nameSubPackage = nameSubPackage;
renameWsToWeb = !getModule().getFolder(element, "").exists();
folder = getModule().getFolder(element, nameSubPackage);
if (renameWsToWeb) {
folder = getModule().getFolder(element, nameSubPackage);
folder = new File(folder.getAbsolutePath().replace("-ws", "-web").replace(File.separator + "ws" + File.separator, File.separator + "web" + File.separator));
}
file = new File(folder.getAbsolutePath() + File.separator + getName() + getType().getPathExtension());
}
@Override
public void generate() {
if (ProcessorUtils.isFileExistsClientOrWebOrWs(file))
return;
try {
if (!folder.exists())
folder.mkdirs();
FileUtils.save(file, getContent());
ProcessorUtils.messageNote("JARCH Created ==> " + file.getAbsoluteFile(), element);
} catch (IOException e) {
LogUtils.generate(e);
}
}
@Override
public Element getElement() {
return element;
}
@Override
public String getVarName() {
return getType().getVarName(useCase);
}
@Override
public String getNamePackage() {
String namePackage = getModule().getNamePackage(element, nameSubPackage);
if (renameWsToWeb)
namePackage = namePackage.replace(".ws.", ".web.");
return namePackage;
}
@Override
public String getName() {
return getType().getName(useCase);
}
@Override
public String getFullName() {
return getType().getFullName(getNamePackage(), useCase);
}
@Override
public String getNameEntity() {
return CodeType.ENTITY.getName(useCase);
}
@Override
public String getFullNameEntity() {
return CodeType.ENTITY.getFullName(ModuleType.CLIENT.getNamePackage(element, nameSubPackage), useCase);
}
@Override
public String getNameService() {
return CodeType.SERVICE.getName(useCase);
}
@Override
public String getFullNameService() {
return CodeType.SERVICE.getFullName(ModuleType.CLIENT.getNamePackage(element, nameSubPackage), useCase);
}
@Override
public String getNameSearch() {
return CodeType.SEARCH.getName(useCase);
}
@Override
public String getFullNameSearch() {
return CodeType.SEARCH.getFullName(ModuleType.CLIENT.getNamePackage(element, nameSubPackage), useCase);
}
@Override
public String getNameRepository() {
return CodeType.REPOSITORY.getName(useCase);
}
@Override
public String getFullNameRepository() {
return CodeType.REPOSITORY.getFullName(ModuleType.CLIENT.getNamePackage(element, nameSubPackage), useCase);
}
@Override
public String getNameDao() {
return CodeType.DAO.getName(useCase);
}
@Override
public String getFullNameDao() {
return CodeType.DAO.getFullName(ModuleType.CLIENT.getNamePackage(element, nameSubPackage), useCase);
}
@Override
public boolean isRenameWsToWeb() {
return renameWsToWeb;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy