package com.jxml.quick;

import java.util.Hashtable;

/**
 * Central repository for knowledge about Quick's built-in support for various
 * oft-used element-content and attribute types.
 * <p>by Pavel Curtis--Quick 1.1
 */
public class TypeManager 
{
    public static class Entry
    {
        public String type;
	public String target;
	public String editor;
	public String genClass;
	public Object targetEditor=null;

        Entry(String type, String target, String editor, String genClass)
	{
	    this.type=type;
	    this.target=target;
	    this.editor=editor;
	    this.genClass=genClass;
	}
    }

    public static Hashtable edInfoByType;
    public static String[] typeNames;

    static 
    {
            Entry[] knownTypes = 
	    {
		new Entry(
		 "boolean",    
	         "java.lang.Boolean",
	         "sun.beans.editors.BoolEditor",
		 "boolean"),
		new Entry(
		 "int",        
	         "java.lang.Integer",
		 "sun.beans.editors.IntEditor",
		 "int"),
		new Entry(
		 "long",       
	         "java.lang.Long",
		 "sun.beans.editors.LongEditor",
		 "long"),
		new Entry(
		 "short",      
		 "java.lang.Short",
		 "sun.beans.editors.ShortEditor",
		 "short"),
		new Entry(
		 "float",      
		 "java.lang.Float",
		 "sun.beans.editors.FloatEditor",
		 "float"),
		new Entry(
		 "byte",       
		 "java.lang.Byte",
		 "sun.beans.editors.ByteEditor",
		 "byte"),
		new Entry(
		 "double",     
		 "java.lang.Double",
		 "sun.beans.editors.DoubleEditor",
		 "double"),
		new Entry(
		 "url",        
		 "java.net.URL",
		 "com.jxml.quick.editors.URLEditor",
		 "java.net.URL"),
		new Entry(
		 "base64",     
		 "[B",
		 "com.jxml.quick.editors.Base64Editor",
		 "byte[]"),
		new Entry(
		 "char",       
		 "java.lang.Character",
		 "com.jxml.quick.editors.CharEditor",
		 "char"),
		new Entry(
		 "BigDecimal", 
		 "java.math.BigDecimal",
		 "com.jxml.quick.editors.BigDecimalEditor",
		 "java.math.BigDecimal")
	    };

	    edInfoByType = new Hashtable();
	    typeNames = new String[knownTypes.length];
	    for (int i = 0; i < knownTypes.length; i++) 
            {
		Entry e = knownTypes[i];
		edInfoByType.put(e.type, e);
                typeNames[i] = e.type;
	    }
    }

    public static String[] getTypeNames() 
    {
	return typeNames;
    }

    public static Entry getEntry(String type)
    {
	return (Entry)edInfoByType.get(type);
    }

    public static String getTarget(String type)
    {
	Entry ei = (Entry)edInfoByType.get(type);
	return (ei == null) ? null : ei.target;
    }

    public static String getGenClass(String type)
    {
	Entry ei = (Entry)edInfoByType.get(type);
	return (ei == null) ? null : ei.genClass;
    }
}
