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

net.anotheria.asg.generator.meta.MetaModule Maven / Gradle / Ivy

package net.anotheria.asg.generator.meta;

import net.anotheria.asg.generator.GenerationOptions;
import net.anotheria.asg.generator.GeneratorDataRegistry;
import net.anotheria.asg.generator.IGenerateable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Representation of a module definition.
 *
 * @author another
 * @version $Id: $Id
 */
public class MetaModule implements IGenerateable{

	/**
	 * This is a predefined module used to generate package and class names for shared stuff.
	 */
	public static final MetaModule SHARED = new MetaModule("Shared");
	
	/**
	 * This is a predefined module used to generate package and class names for user settings stuff.
	 */
	public static final MetaModule USER_SETTINGS = new MetaModule("UserSettings");
	

	/**
	 * Unique name of the module. Each module has a name which is used whenever someone refers to it.
	 */
	private String name;
	/**
	 * List of the documents in this module.
	 */
	private List documents;
	/**
	 * Module listeners which can be attached to the generated service.
	 */
	private List listeners;
	/**
	 * Type of the storge for this module.
	 */
	private StorageType storageType;
	/**
	 * The sense of this parameter is lost in the depth of the code.
	 */
	private String storageKey;
	
	private Map parameters;
	
	/**
	 * Generation options which can enable or disable generation of some artefacts.
	 */
	private GenerationOptions moduleOptions;
		 
	/**
	 * Creates a new empty module.
	 */
	public MetaModule(){
		this(null);
	}
	
	/**
	 * Creates a new module with the given name.
	 *
	 * @param name name of the module.
	 */
	public MetaModule(String name){
		this.name = name;
		documents = new ArrayList();
		listeners = new ArrayList();
		storageType = StorageType.CMS;
		parameters = new HashMap();
	}
	
	/**
	 * Adds a document definition to the module.
	 *
	 * @param aDocument a {@link net.anotheria.asg.generator.meta.MetaDocument} object.
	 */
	public void addDocument(MetaDocument aDocument){
		documents.add(aDocument);
		aDocument.setParentModule(this);
	}
	
	/**
	 * Returns true if an option is enabled. For example 'rmi' is an option which can be enabled.
	 *
	 * @param key a {@link java.lang.String} object.
	 * @return true if an option is enabled
	 */
	public boolean isEnabledByOptions(String key){
		if (moduleOptions!=null){
			if (moduleOptions.isEnabled(key))
				return true;
		}
		
		return GeneratorDataRegistry.getInstance().getOptions().isEnabled(key);
		
	}
	
	/** {@inheritDoc} */
	@Override public String toString(){
		return "module "+name+" storage: "+storageType+" documents: "+documents;
	}
	/**
	 * 

Getter for the field documents.

* * @return contained documents */ public List getDocuments() { return documents; } /** *

Getter for the field name.

* * @return name of the module */ public String getName() { return name; } /** *

getModuleClassName.

* * @return the name for the module implementation class in the cms storage */ public String getModuleClassName(){ return "Module"+getName(); } /** *

getFactoryClassName.

* * @return the class name of the generated module factory */ public String getFactoryClassName(){ return getModuleClassName()+"Factory"; } /** *

Setter for the field documents.

* * @param list a {@link java.util.List} object. */ public void setDocuments(List list) { documents = list; } /** *

Setter for the field name.

* * @param string a {@link java.lang.String} object. */ public void setName(String string) { name = string; } /** * Returns the id of the module. Id is basically name.toLowerCase(). * * @return the id of the module */ public String getId(){ return getName().toLowerCase(); } /** *

getDocumentByName.

* * @param aName a {@link java.lang.String} object. * @return a {@link net.anotheria.asg.generator.meta.MetaDocument} object. */ public MetaDocument getDocumentByName(String aName){ for (int i=0; iGetter for the field listeners.

* * @return a {@link java.util.List} object. */ public List getListeners() { return listeners; } /** *

Setter for the field listeners.

* * @param listeners a {@link java.util.List} object. */ public void setListeners(List listeners) { this.listeners = listeners; } /** *

addListener.

* * @param listenerClass a {@link java.lang.String} object. */ public void addListener(String listenerClass){ listeners.add(listenerClass); } /** *

removeListener.

* * @param listenerClass a {@link java.lang.String} object. */ public void removeListener(String listenerClass){ listeners.remove(listenerClass); } /** *

Getter for the field storageType.

* * @return a {@link net.anotheria.asg.generator.meta.StorageType} object. */ public StorageType getStorageType() { return storageType; } /** *

Setter for the field storageType.

* * @param aStorageType a {@link net.anotheria.asg.generator.meta.StorageType} object. */ public void setStorageType(StorageType aStorageType) { storageType = aStorageType; } /** *

Getter for the field storageKey.

* * @deprecated Noone knows what storagekey does. * @return a {@link java.lang.String} object. */ public String getStorageKey() { return storageKey; } /** *

Setter for the field storageKey.

* * @deprecated Noone knows what storagekey does. * @param aStorageKey a {@link java.lang.String} object. */ public void setStorageKey(String aStorageKey) { storageKey = aStorageKey; } /** *

addModuleParameter.

* * @param p a {@link net.anotheria.asg.generator.meta.ModuleParameter} object. */ public void addModuleParameter(ModuleParameter p){ parameters.put(p.getName(), p); } /** *

getModuleParameter.

* * @param aName a {@link java.lang.String} object. * @return a {@link net.anotheria.asg.generator.meta.ModuleParameter} object. */ public ModuleParameter getModuleParameter(String aName){ return parameters.get(aName); } /** *

isParameterEqual.

* * @param aName a {@link java.lang.String} object. * @param aValue a {@link java.lang.String} object. * @return a boolean. */ public boolean isParameterEqual(String aName, String aValue){ ModuleParameter p = getModuleParameter(aName); return p == null ? false : p.getValue().equals(aValue); } /** *

Getter for the field moduleOptions.

* * @return a {@link net.anotheria.asg.generator.GenerationOptions} object. */ public GenerationOptions getModuleOptions() { return moduleOptions; } /** *

Setter for the field moduleOptions.

* * @param someModuleOptions a {@link net.anotheria.asg.generator.GenerationOptions} object. */ public void setModuleOptions(GenerationOptions someModuleOptions) { moduleOptions = someModuleOptions; } /** *

isContainsAnyMultilingualDocs.

* * @return a boolean. */ public boolean isContainsAnyMultilingualDocs(){ for(MetaDocument doc:documents) if (GeneratorDataRegistry.hasLanguageCopyMethods(doc)) return true; return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy