1 56 57 package org.objectstyle.cayenne.access.types; 58 59 import java.util.HashMap ; 60 import java.util.Iterator ; 61 import java.util.Map ; 62 import java.util.Set ; 63 64 73 public class ExtendedTypeMap { 74 75 protected Map typeMap = new HashMap (); 76 protected DefaultType defaultType = new DefaultType(); 77 78 81 public ExtendedTypeMap() { 82 this.initDefaultTypes(); 83 } 84 85 88 protected void initDefaultTypes() { 89 Iterator it = DefaultType.defaultTypes(); 91 while (it.hasNext()) { 92 registerType(new DefaultType((String ) it.next())); 93 } 94 } 95 96 101 public void registerType(ExtendedType type) { 102 typeMap.put(type.getClassName(), type); 103 } 104 105 108 public ExtendedType getDefaultType() { 109 return defaultType; 110 } 111 112 117 public ExtendedType getRegisteredType(String javaClassName) { 118 ExtendedType type = (ExtendedType) typeMap.get(javaClassName); 119 return (type != null) ? type : defaultType; 120 } 121 122 127 public ExtendedType getRegisteredType(Class javaClass) { 128 String name = null; 129 130 if (javaClass.isArray()) { 131 name = javaClass.getComponentType() + "[]"; 133 } 134 else { 135 name = javaClass.getName(); 136 } 137 138 ExtendedType type = (ExtendedType) typeMap.get(name); 139 return (type != null) ? type : defaultType; 140 } 141 142 146 public void unregisterType(String javaClassName) { 147 typeMap.remove(javaClassName); 148 } 149 150 153 public String [] getRegisteredTypeNames() { 154 Set keys = typeMap.keySet(); 155 int len = keys.size(); 156 String [] types = new String [len]; 157 158 Iterator it = keys.iterator(); 159 for (int i = 0; i < len; i++) { 160 types[i] = (String ) it.next(); 161 } 162 163 return types; 164 } 165 } 166 | Popular Tags |