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

net.anotheria.asg.generator.model.ModuleGenerator Maven / Gradle / Ivy

package net.anotheria.asg.generator.model;

import java.util.ArrayList;
import java.util.List;

import net.anotheria.asg.generator.AbstractGenerator;
import net.anotheria.asg.generator.FileEntry;
import net.anotheria.asg.generator.GeneratedClass;
import net.anotheria.asg.generator.GeneratorDataRegistry;
import net.anotheria.asg.generator.IGenerateable;
import net.anotheria.asg.generator.IGenerator;
import net.anotheria.asg.generator.meta.MetaDocument;
import net.anotheria.asg.generator.meta.MetaModule;
import net.anotheria.asg.generator.meta.StorageType;
import net.anotheria.asg.generator.model.db.VOGenerator;
import net.anotheria.asg.generator.model.docs.DocumentGenerator;
import net.anotheria.asg.generator.model.federation.FederationVOGenerator;

/**
 * TODO please remined another to comment this class
 * @author another
 */
public class ModuleGenerator extends AbstractGenerator implements IGenerator{
	
	
	public List generate(IGenerateable gmodule){
		
		MetaModule mod = (MetaModule)gmodule;
		
		List ret = new ArrayList();
		
		if (mod.getStorageType()==StorageType.CMS)
			ret.add(new FileEntry(generateModule(mod)));
		for (int i=0; i documents = module.getDocuments();
		for (int i=0; i _get"+doc.getMultiple()+"(){");
		increaseIdent();
		appendString("try{");
		increaseIdent();
		appendStatement("return getList("+doc.getListName()+")");
		decreaseIdent();
		appendString("}catch(NoSuchDocumentListException e){");
		increaseIdent();
		appendStatement("return new DocumentList<"+DocumentGenerator.getDocumentName(doc)+">("+doc.getListName()+")");
		append(closeBlock());
		append(closeBlock());
		emptyline();
		
		appendString("private void _update"+doc.getMultiple()+"(DocumentList<"+DocumentGenerator.getDocumentName(doc)+"> list){");
		increaseIdent();
		appendString("putList(list);");
		append(closeBlock());
		emptyline();

		appendString("public List<"+DocumentGenerator.getDocumentName(doc)+"> get"+doc.getMultiple()+"(){");
		increaseIdent();
		appendString("return _get"+doc.getMultiple()+"().getList();");
		append(closeBlock());
		emptyline();

		appendString("public "+DocumentGenerator.getDocumentName(doc)+" get"+doc.getName()+"(String id){");
		increaseIdent();
		appendStatement("return _get"+doc.getMultiple()+"().getDocumentById(id)");
		append(closeBlock());
		emptyline();
		
		appendString("public void update"+doc.getName()+"("+DocumentGenerator.getDocumentName(doc)+" "+doc.getVariableName()+"){");
		increaseIdent();
		appendString("DocumentList<"+DocumentGenerator.getDocumentName(doc)+"> "+doc.getMultiple().toLowerCase()+" = _get"+doc.getMultiple()+"();");
		appendString(doc.getMultiple().toLowerCase()+".removeDocumentById("+doc.getVariableName()+".getId());");
		appendStatement(doc.getVariableName()+".setLastUpdateNow()");
		appendStatement(doc.getVariableName()+".setCallContextAuthor()");
		appendString(doc.getMultiple().toLowerCase()+".addDocument("+doc.getVariableName()+");");
		appendString("_update"+doc.getMultiple()+"("+doc.getMultiple().toLowerCase()+");");
		append(closeBlock());
		emptyline();
		
		appendString("public void delete"+doc.getName()+"(String id){");
		increaseIdent();
		appendStatement("DocumentList<"+DocumentGenerator.getDocumentName(doc)+"> entries = _get"+doc.getMultiple()+"()");
		appendStatement("entries.removeDocumentById(id)");
		appendStatement("_update"+doc.getMultiple()+"(entries)");
		append(closeBlock());
		emptyline();
		
		appendString("public "+DocumentGenerator.getDocumentName(doc)+" create"+doc.getName()+"("+DocumentGenerator.getDocumentName(doc)+" "+doc.getVariableName()+" ){");
		increaseIdent();
		appendStatement("IDHolder idh = _getIdHolder("+doc.getIdHolderName()+")");
		appendStatement("int id = idh.getNextIdInt()");
		appendStatement(doc.getVariableName()+".renameTo(\"\"+id)");
		appendStatement("putDocument(idh)");
		emptyline();
		appendStatement("DocumentList<"+DocumentGenerator.getDocumentName(doc)+"> entries = _get"+doc.getMultiple()+"()");
		appendStatement(doc.getVariableName()+".setLastUpdateNow()");
		appendStatement(doc.getVariableName()+".setCallContextAuthor()");
		appendStatement("entries.addDocument("+doc.getVariableName()+")");
		appendStatement("_update"+doc.getMultiple()+"(entries)");
		appendStatement("return "+doc.getVariableName());
		append(closeBlock());
		emptyline();

		appendString("public "+DocumentGenerator.getDocumentName(doc)+" import"+doc.getName()+"("+DocumentGenerator.getDocumentName(doc)+" "+doc.getVariableName()+" ){");
		increaseIdent();
		appendStatement("IDHolder idh = _getIdHolder("+doc.getIdHolderName()+")");
		appendStatement("idh.adjustTill("+doc.getVariableName()+".getId())");
		appendStatement("putDocument(idh)");
		emptyline();
		appendStatement("DocumentList<"+DocumentGenerator.getDocumentName(doc)+"> entries = _get"+doc.getMultiple()+"()");
		appendStatement(doc.getVariableName()+".setLastUpdateNow()");
		appendStatement(doc.getVariableName()+".setCallContextAuthor()");
		appendStatement("entries.addDocument("+doc.getVariableName()+")");
		appendStatement("_update"+doc.getMultiple()+"(entries)");
		appendStatement("return "+doc.getVariableName());
		append(closeBlock());
		emptyline();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy