1 2 12 package com.versant.core.metadata; 13 14 import com.versant.core.util.IntObjectHashMap; 15 16 import java.math.BigDecimal ; 17 import java.math.BigInteger ; 18 import java.util.*; 19 20 21 24 public class MDStaticUtils implements MDStatics { 25 26 public static final int[] primToNumberMapping = new int[]{ 27 -1, 28 BOOLEANW, 29 BYTEW, 30 SHORTW, 31 INTW, 32 LONGW, 33 FLOATW, 34 DOUBLEW, 35 CHAR, 36 BOOLEANW, 37 BYTEW, 38 SHORTW, 39 INTW, 40 LONGW, 41 FLOATW, 42 DOUBLEW, 43 CHARW, 44 STRING, 45 BIGDECIMAL, 46 BIGINTEGER, 47 DATE, 48 LOCALE, 49 }; 50 51 protected static final Map TYPE_MAP = new HashMap(); 52 protected static final Map TYPE_CODE_MAP = new HashMap(); 53 private static final IntObjectHashMap CODE_TYPE_MAP = new IntObjectHashMap(); 54 private static final Map TYPE_NAME_MAP = new HashMap(); 55 56 private static void put(String name, Class t, int code) { 57 TYPE_MAP.put(name, t); 58 TYPE_NAME_MAP.put(t, name); 59 TYPE_CODE_MAP.put(t, new Integer (code)); 60 CODE_TYPE_MAP.put(code, name); 61 } 62 63 private static void put(String name, String name2, Class t, int code) { 64 TYPE_MAP.put(name2, t); 65 put(name, t, code); 66 } 67 68 static { 69 put("boolean", Boolean.TYPE, BOOLEAN); 70 put("Boolean", "java.lang.Boolean", Boolean .class, BOOLEANW); 71 put("byte", Byte.TYPE, BYTE); 72 put("Byte", "java.lang.Byte", Byte .class, BYTEW); 73 put("short", Short.TYPE, SHORT); 74 put("Short", "java.lang.Short", Short .class, SHORTW); 75 put("int", Integer.TYPE, INT); 76 put("Integer", "java.lang.Integer", Integer .class, INTW); 77 put("long", Long.TYPE, LONG); 78 put("Long", "java.lang.Long", Long .class, LONGW); 79 put("float", Float.TYPE, FLOAT); 80 put("Float", "java.lang.Float", Float .class, FLOATW); 81 put("double", Double.TYPE, DOUBLE); 82 put("Double", "java.lang.Double", Double .class, DOUBLEW); 83 put("char", Character.TYPE, CHAR); 84 put("Character", "java.lang.Character", Character .class, CHARW); 85 86 put("String", "java.lang.String", String .class, STRING); 87 put("BigDecimal", "java.math.BigDecimal", BigDecimal .class, BIGDECIMAL); 88 put("BigInteger", "java.math.BigInteger", BigInteger .class, BIGINTEGER); 89 put("Date", "java.util.Date", Date.class, DATE); 90 put("Locale", "java.util.Locale", Locale.class, LOCALE); 91 92 put("Collection", "java.util.Collection", java.util.Collection .class, 94 COLLECTION); 95 put("List", "java.util.List", java.util.List .class, LIST); 96 put("ArrayList", "java.util.ArrayList", java.util.ArrayList .class, 97 ARRAYLIST); 98 put("LinkedList", "java.util.LinkedList", java.util.LinkedList .class, 99 LINKEDLIST); 100 put("Vector", "java.util.Vector", java.util.Vector .class, VECTOR); 101 102 put("Set", "java.util.Set", java.util.Set .class, SET); 103 put("HashSet", "java.util.HashSet", java.util.HashSet .class, HASHSET); 104 put("TreeSet", "java.util.TreeSet", java.util.TreeSet .class, TREESET); 105 put("SortedSet", "java.util.SortedSet", java.util.SortedSet .class, 106 SORTEDSET); 107 108 109 110 put("Map", "java.util.Map", java.util.Map .class, MAP); 112 put("HashMap", "java.util.HashMap", java.util.HashMap .class, HASHMAP); 113 put("TreeMap", "java.util.TreeMap", java.util.TreeMap .class, TREEMAP); 114 put("SortedMap", "java.util.SortedMap", java.util.SortedMap .class, 115 SORTEDMAP); 116 put("Hashtable", "java.util.Hashtable", java.util.Hashtable .class, 117 HASHTABLE); 118 } 119 120 protected MDStaticUtils() { 121 } 122 123 127 public static final Class toSimpleClass(String name) { 128 return (Class )TYPE_MAP.get(name); 129 } 130 131 135 public static final int toTypeCode(Class cls) { 136 137 Integer i = (Integer )TYPE_CODE_MAP.get(cls); 138 return i == null ? -1 : i.intValue(); 139 } 140 141 public static String toSimpleName(Class cls) { 142 return (String )TYPE_NAME_MAP.get(cls); 143 } 144 145 151 public static String toSimpleName(int code) { 152 String name = (String )CODE_TYPE_MAP.get(code); 153 return name; 154 } 155 156 public static String toTriStateString(int t) { 157 switch (t) { 158 case NOT_SET: 159 return "notset"; 160 case TRUE: 161 return "true"; 162 case FALSE: 163 return "false"; 164 } 165 return "unknown(" + t + ")"; 166 } 167 168 public static String toIdentityTypeString(int identityType) { 169 switch (identityType) { 170 case IDENTITY_TYPE_APPLICATION: 171 return "application"; 172 case IDENTITY_TYPE_DATASTORE: 173 return "datastore"; 174 case IDENTITY_TYPE_NONDURABLE: 175 return "none"; 176 } 177 return "unknown(" + identityType + ")"; 178 } 179 180 public static String toPersistenceModifierString(int pm) { 181 switch (pm) { 182 case PERSISTENCE_MODIFIER_PERSISTENT: 183 return "persistent"; 184 case PERSISTENCE_MODIFIER_TRANSACTIONAL: 185 return "transactional"; 186 case PERSISTENCE_MODIFIER_NONE: 187 return "none"; 188 case NOT_SET: 189 return ""; 190 } 191 return "unknown(" + pm + ")"; 192 } 193 194 public static String toNullValueString(int nullValue) { 195 switch (nullValue) { 196 case NULL_VALUE_EXCEPTION: 197 return "exception"; 198 case NULL_VALUE_DEFAULT: 199 return "default"; 200 case NULL_VALUE_NONE: 201 return "none"; 202 } 203 return "unknown(" + nullValue + ")"; 204 } 205 206 public static String toCategoryString(int category) { 207 switch (category) { 208 case CATEGORY_SIMPLE: 209 return "Simple"; 210 case CATEGORY_REF: 211 return "Ref"; 212 case CATEGORY_POLYREF: 213 return "PolyRef"; 214 case CATEGORY_COLLECTION: 215 return "Collection"; 216 case CATEGORY_ARRAY: 217 return "Array"; 218 case CATEGORY_MAP: 219 return "Map"; 220 case CATEGORY_TRANSACTIONAL: 221 return "Transactional"; 222 case CATEGORY_NONE: 223 return "None"; 224 case CATEGORY_DATASTORE_PK: 225 return "Datastore Pk"; 226 case CATEGORY_OPT_LOCKING: 227 return "Opt Locking"; 228 case CATEGORY_CLASS_ID: 229 return "Class Id"; 230 case CATEGORY_EXTERNALIZED: 231 return "Externalized"; 232 } 233 return "unknown(" + category + ")"; 234 } 235 236 public static String toAutoSetString(int autoSet) { 237 switch (autoSet) { 238 case AUTOSET_NO: 239 return "NONE"; 240 case AUTOSET_CREATED: 241 return "CREATED"; 242 case AUTOSET_MODIFIED: 243 return "MODIFIED"; 244 case AUTOSET_BOTH: 245 return "BOTH"; 246 } 247 return "unknown(" + autoSet + ")"; 248 } 249 250 public static String toCacheString(int cache) { 251 switch (cache) { 252 case CACHE_STRATEGY_NO: 253 return "no"; 254 case CACHE_STRATEGY_YES: 255 return "yes"; 256 case CACHE_STRATEGY_ALL: 257 return "all"; 258 } 259 return "unknown(" + cache + ")"; 260 } 261 262 public static final boolean isIntegerType(int type) { 263 return isSignedIntegerType(type) 264 265 ; 266 } 267 268 public static final boolean isSignedIntegerType(int type) { 269 if ((type >= BOOLEAN && type <= LONGW) 270 || type == CHARW 271 ) { 272 return true; 273 } else { 274 return false; 275 } 276 } 277 278 279 280 } 281 282 | Popular Tags |