1 18 package org.objectweb.jorm.naming.lib; 19 20 import org.objectweb.jorm.naming.api.PNameGetter; 21 import org.objectweb.jorm.api.PException; 22 23 import java.util.Date ; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import java.math.BigInteger ; 27 import java.math.BigDecimal ; 28 29 33 public class MapPNameGetter implements PNameGetter { 34 35 Map field2value; 36 37 public MapPNameGetter(String [] fieldNames, Object [] fieldValues) { 38 field2value = new HashMap (); 39 for(int i=fieldNames.length-1; i>=0; i--) { 40 field2value.put(fieldNames[i], fieldValues[i]); 41 } 42 } 43 public MapPNameGetter(Map field2value) { 44 this.field2value = field2value; 45 } 46 47 public byte pngetByteField(String fn, Object ctxt) throws PException { 48 Object value = field2value.get(fn); 49 if (value == null) { 50 throw new PException("No field " + fn + " found among " 51 + field2value.keySet()); 52 } 53 if (value instanceof Byte ) { 54 return ((Byte ) value).byteValue(); 55 } 56 throw new PException("Bad type: expected " + value.getClass().getName()); 57 } 58 59 public Byte pngetObyteField(String fn, Object ctxt) throws PException { 60 Object value = field2value.get(fn); 61 if (value == null) { 62 if (field2value.containsKey(fn)) { 63 return null; 64 } else { 65 throw new PException("No field " + fn + " found among " 66 + field2value.keySet()); 67 } 68 } 69 if (value instanceof Byte ) { 70 return (Byte ) value; 71 } 72 throw new PException("Bad type: expected " + value.getClass().getName()); 73 } 74 75 public char pngetCharField(String fn, Object ctxt) throws PException { 76 Object value = field2value.get(fn); 77 if (value == null) { 78 throw new PException("No field " + fn + " found among " 79 + field2value.keySet()); 80 } 81 if (value instanceof Character ) { 82 return ((Character ) value).charValue(); 83 } 84 throw new PException("Bad type: expected " + value.getClass().getName()); 85 } 86 87 public Character pngetOcharField(String fn, Object ctxt) throws PException { 88 Object value = field2value.get(fn); 89 if (value == null) { 90 if (field2value.containsKey(fn)) { 91 return null; 92 } else { 93 throw new PException("No field " + fn + " found among " 94 + field2value.keySet()); 95 } 96 } 97 if (value instanceof Character ) { 98 return (Character ) value; 99 } 100 throw new PException("Bad type: expected " + value.getClass().getName()); 101 } 102 103 public short pngetShortField(String fn, Object ctxt) throws PException { 104 Object value = field2value.get(fn); 105 if (value == null) { 106 throw new PException("No field " + fn + " found among " 107 + field2value.keySet()); 108 } 109 if (value instanceof Short ) { 110 return ((Short ) value).shortValue(); 111 } 112 throw new PException("Bad type: expected " + value.getClass().getName()); 113 } 114 115 public Short pngetOshortField(String fn, Object ctxt) throws PException { 116 Object value = field2value.get(fn); 117 if (value == null) { 118 if (field2value.containsKey(fn)) { 119 return null; 120 } else { 121 throw new PException("No field " + fn + " found among " 122 + field2value.keySet()); 123 } 124 } 125 if (value instanceof Short ) { 126 return (Short ) value; 127 } 128 throw new PException("Bad type: expected " + value.getClass().getName()); 129 } 130 131 public int pngetIntField(String fn, Object ctxt) throws PException { 132 Object value = field2value.get(fn); 133 if (value == null) { 134 throw new PException("No field " + fn + " found among " 135 + field2value.keySet()); 136 } 137 if (value instanceof Integer ) { 138 return ((Integer ) value).intValue(); 139 } 140 throw new PException("Bad type: expected " + value.getClass().getName()); 141 } 142 143 public Integer pngetOintField(String fn, Object ctxt) throws PException { 144 Object value = field2value.get(fn); 145 if (value == null) { 146 if (field2value.containsKey(fn)) { 147 return null; 148 } else { 149 throw new PException("No field " + fn + " found among " 150 + field2value.keySet()); 151 } 152 } 153 if (value instanceof Integer ) { 154 return (Integer ) value; 155 } 156 throw new PException("Bad type: expected " + value.getClass().getName()); 157 } 158 159 public long pngetLongField(String fn, Object ctxt) throws PException { 160 Object value = field2value.get(fn); 161 if (value == null) { 162 throw new PException("No field " + fn + " found among " 163 + field2value.keySet()); 164 } 165 if (value instanceof Long ) { 166 return ((Long ) value).longValue(); 167 } 168 throw new PException("Bad type: expected " + value.getClass().getName()); 169 } 170 171 public Long pngetOlongField(String fn, Object ctxt) throws PException { 172 Object value = field2value.get(fn); 173 if (value == null) { 174 if (field2value.containsKey(fn)) { 175 return null; 176 } else { 177 throw new PException("No field " + fn + " found among " 178 + field2value.keySet()); 179 } 180 } 181 if (value instanceof Long ) { 182 return (Long ) value; 183 } 184 throw new PException("Bad type: expected " + value.getClass().getName()); 185 } 186 187 public String pngetStringField(String fn, Object ctxt) throws PException { 188 Object value = field2value.get(fn); 189 if (value == null) { 190 if (field2value.containsKey(fn)) { 191 return null; 192 } else { 193 throw new PException("No field " + fn + " found among " 194 + field2value.keySet()); 195 } 196 } 197 if (value instanceof String ) { 198 return (String ) value; 199 } 200 throw new PException("Bad type: expected " + value.getClass().getName()); 201 } 202 203 public byte[] pngetByteArrayField(String fn, Object ctxt) throws PException { 204 Object value = field2value.get(fn); 205 if (value == null) { 206 if (field2value.containsKey(fn)) { 207 return null; 208 } else { 209 throw new PException("No field " + fn + " found among " 210 + field2value.keySet()); 211 } 212 } 213 if (value instanceof byte[]) { 214 return (byte[]) value; 215 } 216 throw new PException("Bad type: expected " + value.getClass().getName()); 217 } 218 219 public char[] pngetCharArrayField(String fn, Object ctxt) throws PException { 220 Object value = field2value.get(fn); 221 if (value == null) { 222 if (field2value.containsKey(fn)) { 223 return null; 224 } else { 225 throw new PException("No field " + fn + " found among " 226 + field2value.keySet()); 227 } 228 } 229 if (value instanceof char[]) { 230 return (char[]) value; 231 } 232 throw new PException("Bad type: expected " + value.getClass().getName()); 233 } 234 235 public Date pngetDateField(String fn, Object ctxt) throws PException { 236 Object value = field2value.get(fn); 237 if (value == null) { 238 if (field2value.containsKey(fn)) { 239 return null; 240 } else { 241 throw new PException("No field " + fn + " found among " 242 + field2value.keySet()); 243 } 244 } 245 if (value instanceof Date ) { 246 return (Date ) value; 247 } 248 throw new PException("Bad type: expected " + value.getClass().getName()); 249 } 250 251 public BigInteger pngetBigIntegerField(String fn, Object ctxt) throws PException { 252 Object value = field2value.get(fn); 253 if (value == null) { 254 if (field2value.containsKey(fn)) { 255 return null; 256 } else { 257 throw new PException("No field " + fn + " found among " 258 + field2value.keySet()); 259 } 260 } 261 if (value instanceof BigInteger ) { 262 return (BigInteger ) value; 263 } 264 throw new PException("Bad type: expected " + value.getClass().getName()); 265 } 266 267 public BigDecimal pngetBigDecimalField(String fn, Object ctxt) throws PException { 268 Object value = field2value.get(fn); 269 if (value == null) { 270 if (field2value.containsKey(fn)) { 271 return null; 272 } else { 273 throw new PException("No field " + fn + " found among " 274 + field2value.keySet()); 275 } 276 } 277 if (value instanceof BigDecimal ) { 278 return (BigDecimal ) value; 279 } 280 throw new PException("Bad type: expected " + value.getClass().getName()); 281 } 282 } 283 | Popular Tags |