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

net.anotheria.asg.generator.model.federation.FederationVOGenerator Maven / Gradle / Ivy

package net.anotheria.asg.generator.model.federation;

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

import net.anotheria.asg.generator.Context;
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.MetaContainerProperty;
import net.anotheria.asg.generator.meta.MetaDocument;
import net.anotheria.asg.generator.meta.MetaListProperty;
import net.anotheria.asg.generator.meta.MetaProperty;
import net.anotheria.asg.generator.meta.MetaTableProperty;
import net.anotheria.asg.generator.model.AbstractDataObjectGenerator;
import net.anotheria.util.StringUtils;

/**
 * This generator generates VO objects for a Module Federation.
 * @author another
 */
public class FederationVOGenerator extends AbstractDataObjectGenerator
	implements IGenerator{

	/**
	 * Id property. Most documents do not include id properties, but its required by the application and has to be added here.
	 */
	private final MetaProperty id = new MetaProperty("id",MetaProperty.Type.STRING);
	/**
	 * Last update timestamp property.
	 */
	private final MetaProperty lastUpdate = new MetaProperty("lastUpdateTimestamp", MetaProperty.Type.LONG);
	
	public List generate(IGenerateable gdoc){
		MetaDocument doc = (MetaDocument)gdoc;
		id.setReadonly(true);
		
		
		//System.out.println(ret);
		List ret = new ArrayList();
		ret.add(new FileEntry(generateDocument(doc)));
		ret.add(new FileEntry(generateDocumentFactory(doc)));
		return ret;
	}
	
	public String getDataObjectImplName(MetaDocument doc){
		return getDocumentImplName(doc);
	}
	
	public static String getDocumentImplName(MetaDocument doc){
		return doc.getName()+"VO";
	}
	

	/**
	 * Generates the federated VO.
	 * @param doc
	 * @return
	 */
	private GeneratedClass generateDocument(MetaDocument doc){
		GeneratedClass clazz = new GeneratedClass();
		startNewJob(clazz);
		
		clazz.setPackageName(getPackageName(doc));
		
		for (int i=0; i propertyList){
		for (int i=0; i columns = ((MetaTableProperty)p).getColumns();
				for (int t=0; t lastUpdList = new ArrayList();
		lastUpdList.add(lastUpdate);
		generatePropertyAccessMethods(lastUpdList);
		generatePropertyAccessMethods(doc.getProperties());
		generatePropertyAccessMethods(doc.getLinks());
	}
	
	private void generatePropertyAccessMethods(List properties){
		
		for (int i=0; i columns = p.getColumns();
		for (int t=0; t columns = p.getColumns();
		for (int t=0; t props = doc.getProperties();
		for (int i=0; i columns = ((MetaTableProperty)p).getColumns();
				for (int t=0; t properties = doc.getProperties();
		for (MetaProperty p : properties){
			if (p instanceof MetaContainerProperty)
				generateContainerMethods((MetaContainerProperty)p);
			if (p instanceof MetaTableProperty)
				generateTableMethods((MetaTableProperty)p);
			if (p instanceof MetaListProperty)
				generateListMethods((MetaListProperty)p);
		}
		
		appendString("public XMLNode toXMLNode(){");
		increaseIdent();
		appendStatement("return new XMLNode("+quote("not_imlpemented_fed_vo")+")");
		closeBlockNEW();
	}
	
	private void generateContainerMethods(MetaContainerProperty container){
		appendString("public int "+getContainerSizeGetterName(container)+"(){");
		increaseIdent();
		MetaProperty pr = container instanceof MetaTableProperty ? 
			(MetaProperty) ((MetaTableProperty)container).getColumns().get(0) :
			container;
		appendStatement("return getList("+pr.toNameConstant()+").size()"); 
		closeBlockNEW();
		emptyline();
		
	}
	
	private void generateListMethods(MetaListProperty list){
		MetaProperty c = list.getContainedProperty();

		String decl = "public void "+getContainerEntryAdderName(list)+"(";
		decl += c.toJavaType()+" "+c.getName();
		decl += "){";
		appendString(decl);
		increaseIdent();
		
		appendStatement(c.toJavaType()+"Property p = new "+c.toJavaType()+"Property("+c.getName()+", "+c.getName()+")");
		appendStatement("List tmp = get"+list.getAccesserName()+"()");
		appendStatement("tmp.add(p)");
		appendStatement("set"+list.getAccesserName()+"(tmp)");
		closeBlockNEW();
		emptyline();
		
		
		appendString("public void "+getContainerEntryDeleterName(list)+"(int index){");
		increaseIdent();
		appendStatement("getListProperty("+list.toNameConstant()+").remove(index)"); 
		closeBlockNEW();
		emptyline();
		
		appendString("public void "+getContainerEntrySwapperName(list)+"(int index1, int index2){");
		increaseIdent();
		appendStatement(c.toJavaType()+" tmp1, tmp2");
		appendStatement("tmp1 = (("+c.toJavaType()+"Property"+")getList("+list.toNameConstant()+").get(index1)).get"+c.toJavaType()+"()");
		appendStatement("tmp2 = (("+c.toJavaType()+"Property"+")getList("+list.toNameConstant()+").get(index2)).get"+c.toJavaType()+"()");
		appendStatement("(("+c.toJavaType()+"Property"+")getList("+list.toNameConstant()+").get(index1)).set"+c.toJavaType()+"(tmp2)");
		appendStatement("(("+c.toJavaType()+"Property"+")getList("+list.toNameConstant()+").get(index2)).set"+c.toJavaType()+"(tmp1)");
		closeBlockNEW();
		emptyline();

		appendString("public "+c.toJavaType()+ " "+getListElementGetterName(list)+"(int index){");
		increaseIdent();
		appendStatement(c.toJavaType()+"Property p = ("+c.toJavaType()+"Property"+")getList("+list.toNameConstant()+").get(index)");
		appendStatement("return p.get"+c.toJavaType()+"()");
		closeBlockNEW();
		emptyline();
	}
	
	private void generateTableMethods(MetaTableProperty table){
		List columns = table.getColumns();
		
		String decl = "public void "+getContainerEntryAdderName(table)+"(";
		for (int i =0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy