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

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

package net.anotheria.asg.generator.meta;

import net.anotheria.util.StringUtils;


/**
 * Represents a single property of a document. A property may be basic, like int, boolean, long, or complex, like list or table.
 * This class defines single one typed property mainly.
 * @author another
 */
public class MetaProperty implements Cloneable{
	
	public static enum Type{
		STRING("string"),
        PASSWORD("password"),
		TEXT("text"),
		BOOLEAN("boolean"),
		INT("int"),
		LONG("long"),
		DOUBLE("double"),
		FLOAT("float"),
		LIST("list"),
		IMAGE("image");
		

		String name;
		Type(String aName){
			name = aName;
		}
		
		public String getName(){
			return name;
		}
		
		public static Type findTypeByName(String name){
			for(Type t: values())
				if(t.getName().equals(name))
					return t;
			return null;
		}

		@Override
		public String toString() {
			return "Type{" +
					"name='" + name + '\'' +
					'}';
		}
	}
	
	/**
	 * The type of the property as string.
	 */
	private Type type;
	/**
	 * Name of the property.
	 */
	private String name;
	/**
	 * Resolved property type.
	 */
	private IMetaType metaType;
	/**
	 * True if the property is multilingual.
	 */
	private boolean multilingual;
	/**
	 * True if the property is readonly. For example id is a readonly property. Basically this is only used by the view, 
	 * the application itself still free to change a readonly property.
	 */
	private boolean readonly;
	/**
	 * Creates a new MetaProperty with given name and type description. 
	 * @param aName
	 * @param aType
	 */
	public MetaProperty(String aName, Type aType){
		this(aName, aType, false);
	}
	
	public MetaProperty(String aName, Type aType, boolean aMultilingual){
		name = aName;
		type = aType;
		metaType = TypeFactory.createType(aType);
		multilingual = aMultilingual;
		
		if (name==null)
			throw new IllegalArgumentException("name is null");
	}
	
	public MetaProperty(String aName, IMetaType aType){
		name = aName;
		metaType = aType;
		multilingual = false;

		if (name==null)
			throw new IllegalArgumentException("name is null");
	}


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

	/**
	 * Returns the internal name of the property for language variant.
	 * @param language
	 * @return
	 */
	public String getName(String language) {
		return language == null || !isMultilingual()? getName() : name+StringUtils.capitalize(language);
	}

	public String getName(String addOn, String language) {
		return language == null ? getName()+addOn : name+addOn+StringUtils.capitalize(language);
	}

	/**
	 * @return
	 */
	public Type getType() {
		return type;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		name = string;
	}

	public String toNameConstant(){
		return "PROP_"+getNameConstantBase();
	}
	
	public String toNameConstant(String language){
		return "PROP_"+getNameConstantBase()+"_"+language.toUpperCase();
	}
	
	private String getNameConstantBase(){
		String ret = "";
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy