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

net.anotheria.asg.generator.view.action.BaseViewActionGenerator Maven / Gradle / Ivy

package net.anotheria.asg.generator.view.action;

import java.util.ArrayList;
import java.util.Arrays;
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.meta.MetaModule;
import net.anotheria.asg.generator.view.CMSMappingsConfiguratorGenerator;
import net.anotheria.asg.generator.view.meta.MetaCustomSection;
import net.anotheria.asg.generator.view.meta.MetaModuleSection;
import net.anotheria.asg.generator.view.meta.MetaSection;
import net.anotheria.asg.generator.view.meta.MetaView;
import net.anotheria.util.StringUtils;

/**
 * This generator generates the base action for a view.
 * @author another
 */
public class BaseViewActionGenerator extends AbstractGenerator {

	/* (non-Javadoc)
	 * @see net.anotheria.anodoc.generator.IGenerator#generate(net.anotheria.anodoc.generator.IGenerateable, net.anotheria.anodoc.generator.Context)
	 */
	public FileEntry generate(IGenerateable g) {
		
		MetaView view = (MetaView)g;
		return new FileEntry(generateViewAction(view));
	}
	
	public static String getViewActionName(MetaView view){
		return "Base"+StringUtils.capitalize(view.getName())+"Action";
	}
	
	public GeneratedClass generateViewAction(MetaView view){

		GeneratedClass clazz = new GeneratedClass();
		startNewJob(clazz);
		clazz.setPackageName(GeneratorDataRegistry.getInstance().getContext().getPackageName(MetaModule.SHARED)+".action");
		
		List sections = view.getSections();
		List modules = new ArrayList();
		
		for (int i=0; i0){
			clazz.addImport(Arrays.class);
			String roles = "";
			for (String r : view.getRequiredRoles()){
				if (roles.length()>0)
					roles += ", ";
				roles += quote(r);
			}
			appendStatement("private static final List MY_ROLES = Arrays.asList(new String[]{"+roles+"})");
			appendString("protected List getRequiredRoles(){");
			appendIncreasedStatement("return MY_ROLES");
			appendString("}");
		}
			
		emptyline();		
			appendStatement("protected List getSubNavigation(){");
			appendStatement("List subNavi = new ArrayList()");
			increaseIdent();		
				for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy