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

net.anotheria.asg.generator.model.AbstractDataObjectGenerator 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.Context;
import net.anotheria.asg.generator.GeneratedClass;
import net.anotheria.asg.generator.GeneratorDataRegistry;
import net.anotheria.asg.generator.meta.MetaContainerProperty;
import net.anotheria.asg.generator.meta.MetaDocument;
import net.anotheria.asg.generator.meta.MetaModule;
import net.anotheria.asg.generator.meta.MetaProperty;
import net.anotheria.util.StringUtils;
/**
 * Base class for the data objects generators (documents, VOs and more).
 * @author lrosenberg
 *
 */
public abstract class AbstractDataObjectGenerator extends AbstractGenerator{
	
	/**
	 * Returns the implementation name of this abstract data object flavour.
	 * @param doc
	 * @return
	 */
	protected abstract String getDataObjectImplName(MetaDocument doc);
	/**
	 * Returns the package name for the given document.
	 * @param doc
	 * @return
	 */
	protected String getPackageName(MetaDocument doc){
		return GeneratorDataRegistry.getInstance().getContext().getDataPackageName(doc);
	}
	
	public static String getPackageName(MetaModule module){
		return GeneratorDataRegistry.getInstance().getContext().getPackageName(module);
	}
	
	
	/**
	 * Generates getFootprint method. 
	 * @param doc 
	 * @return
	 */
	protected void generateGetFootprintMethod(MetaDocument doc){
		appendString("public String getFootprint(){");
		increaseIdent();
		appendStatement("StringBuilder footprint = new StringBuilder()");

		generatePropertyListFootprint(doc.getProperties());
		generatePropertyListFootprint(doc.getLinks());
		
		appendStatement("return MD5Util.getMD5Hash(footprint)");
		append(closeBlock());
	}
	
	protected void generatePropertyListFootprint(List properties){
		Context c = GeneratorDataRegistry.getInstance().getContext();

		for (MetaProperty p : properties){
			if (c.areLanguagesSupported() && p.isMultilingual()){
				for (String l : c.getLanguages())
					appendStatement("footprint.append(get"+p.getAccesserName(l)+"())");
			}else{
				appendStatement("footprint.append(get"+p.getAccesserName()+"())");
			}
		}
	}

	protected void generateCompareMethod(MetaDocument doc){
		appendString("public int compareTo("+doc.getName()+" comparable){");
		appendIncreasedStatement("return compareTo(comparable, "+getSortTypeName(doc)+".SORT_BY_DEFAULT)");
		appendString("}");
		emptyline();

		appendString("public int compareTo(IComparable anotherComparable, int method){");
		increaseIdent();

		appendStatement(getDataObjectImplName(doc)+" anotherDoc = ("+getDataObjectImplName(doc)+") anotherComparable");
		appendString("switch(method){");
		increaseIdent();
		List properties = extractSortableProperties(doc);

		for (int i=0; i extractSortableProperties(MetaDocument doc){
		List properties = new ArrayList();
		properties.add(new MetaProperty("id",MetaProperty.Type.STRING));
		properties.addAll(doc.getProperties());
		properties.addAll(doc.getLinks());

		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy