1 45 46 package org.exolab.jms.tools.db; 47 48 import java.lang.reflect.Field ; 49 import java.lang.reflect.Modifier ; 50 import java.sql.Types ; 51 import java.util.HashMap ; 52 53 54 61 class Descriptor { 62 63 66 private final int _type; 67 68 71 private final String _name; 72 73 76 private static HashMap TYPE_MAP = null; 77 78 81 private static HashMap NAME_MAP = null; 82 83 89 private Descriptor(int type, String name) { 90 _type = type; 91 _name = name; 92 } 93 94 100 public int getType() { 101 return _type; 102 } 103 104 107 public String getName() { 108 return _name; 109 } 110 111 117 public static Descriptor getDescriptor(int type) { 118 return (Descriptor) TYPE_MAP.get(new Integer (type)); 119 } 120 121 127 public static Descriptor getDescriptor(String name) { 128 return (Descriptor) NAME_MAP.get(name.toUpperCase()); 129 } 130 131 134 static { 135 TYPE_MAP = new HashMap (); 136 NAME_MAP = new HashMap (); 137 try { 138 Field [] fields = Types .class.getFields(); 139 for (int i = 0; i < fields.length; ++i) { 140 Field field = fields[i]; 141 if (Modifier.isStatic(field.getModifiers())) { 142 int type = ((Integer ) field.get(null)).intValue(); 143 String name = field.getName().toUpperCase(); 144 Descriptor descriptor = new Descriptor(type, name); 145 TYPE_MAP.put(new Integer (type), descriptor); 146 NAME_MAP.put(name, descriptor); 147 } 148 } 149 } catch (IllegalAccessException exception) { 150 throw new RuntimeException (exception.getMessage()); 151 } 152 } 153 154 } | Popular Tags |