1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import java.lang.reflect.Field ; 21 import java.lang.reflect.Modifier ; 22 23 import org.apache.geronimo.interop.SystemException; 24 25 public class ValueTypeField 26 { 27 public final Field javaField; 28 29 public final int primitive; 30 31 public final ValueType type; 32 33 private final boolean isFinal; 34 35 private FinalFieldSetter finalFieldSetter; 36 37 public ValueTypeField(Field field) 38 { 39 javaField = field; 40 if (field.getType().isPrimitive()) 41 { 42 primitive = PrimitiveType.get(field.getType()); 43 type = null; 44 } 45 else 46 { 47 primitive = 0; 48 type = ValueType.getInstance(field.getType()); 49 } 50 if(Modifier.isFinal(field.getModifiers())) 51 { 52 isFinal = true; 53 finalFieldSetter = FinalFieldSetter.getInstance(field); 54 } 55 else 56 { 57 isFinal = false; 58 } 59 } 60 61 public boolean getBoolean(Object that) 62 { 63 try 64 { 65 return javaField.getBoolean(that); 66 } 67 catch (Exception ex) 68 { 69 throw new SystemException(ex); 70 } 71 } 72 73 public byte getByte(Object that) 74 { 75 try 76 { 77 return javaField.getByte(that); 78 } 79 catch (Exception ex) 80 { 81 throw new SystemException(ex); 82 } 83 } 84 85 public char getChar(Object that) 86 { 87 try 88 { 89 return javaField.getChar(that); 90 } 91 catch (Exception ex) 92 { 93 throw new SystemException(ex); 94 } 95 } 96 97 public double getDouble(Object that) 98 { 99 try 100 { 101 return javaField.getDouble(that); 102 } 103 catch (Exception ex) 104 { 105 throw new SystemException(ex); 106 } 107 } 108 109 public float getFloat(Object that) 110 { 111 try 112 { 113 return javaField.getFloat(that); 114 } 115 catch (Exception ex) 116 { 117 throw new SystemException(ex); 118 } 119 } 120 121 public int getInt(Object that) 122 { 123 try 124 { 125 return javaField.getInt(that); 126 } 127 catch (Exception ex) 128 { 129 throw new SystemException(ex); 130 } 131 } 132 133 public long getLong(Object that) 134 { 135 try 136 { 137 return javaField.getLong(that); 138 } 139 catch (Exception ex) 140 { 141 throw new SystemException(ex); 142 } 143 } 144 145 public short getShort(Object that) 146 { 147 try 148 { 149 return javaField.getShort(that); 150 } 151 catch (Exception ex) 152 { 153 throw new SystemException(ex); 154 } 155 } 156 157 public Object get(Object that) 158 { 159 try 160 { 161 return javaField.get(that); 162 } 163 catch (Exception ex) 164 { 165 throw new SystemException(ex); 166 } 167 } 168 169 public void setBoolean(Object that, boolean value) 170 { 171 try 172 { 173 if(isFinal) 174 { 175 finalFieldSetter.setBoolean(that, value); 176 } 177 else 178 { 179 javaField.setBoolean(that, value); 180 } 181 } 182 catch (Exception ex) 183 { 184 throw new SystemException(ex); 185 } 186 } 187 188 public void setByte(Object that, byte value) 189 { 190 try 191 { 192 if(isFinal) 193 { 194 finalFieldSetter.setByte(that, value); 195 } 196 else 197 { 198 javaField.setByte(that, value); 199 } 200 } 201 catch (Exception ex) 202 { 203 throw new SystemException(ex); 204 } 205 } 206 207 public void setChar(Object that, char value) 208 { 209 try 210 { 211 if(isFinal) 212 { 213 finalFieldSetter.setChar(that, value); 214 } 215 else 216 { 217 javaField.setChar(that, value); 218 } 219 } 220 catch (Exception ex) 221 { 222 throw new SystemException(ex); 223 } 224 } 225 226 public void setDouble(Object that, double value) 227 { 228 try 229 { 230 if(isFinal) 231 { 232 finalFieldSetter.setDouble(that, value); 233 } 234 else 235 { 236 javaField.setDouble(that, value); 237 } 238 } 239 catch (Exception ex) 240 { 241 throw new SystemException(ex); 242 } 243 } 244 245 public void setFloat(Object that, float value) 246 { 247 try 248 { 249 if(isFinal) 250 { 251 finalFieldSetter.setFloat(that, value); 252 } 253 else 254 { 255 javaField.setFloat(that, value); 256 } 257 } 258 catch (Exception ex) 259 { 260 throw new SystemException(ex); 261 } 262 } 263 264 public void setInt(Object that, int value) 265 { 266 try 267 { 268 if(isFinal) 269 { 270 finalFieldSetter.setInt(that, value); 271 } 272 else 273 { 274 javaField.setInt(that, value); 275 } 276 } 277 catch (Exception ex) 278 { 279 throw new SystemException(ex); 280 } 281 } 282 283 public void setLong(Object that, long value) 284 { 285 try 286 { 287 if(isFinal) 288 { 289 finalFieldSetter.setLong(that, value); 290 } 291 else 292 { 293 javaField.setLong(that, value); 294 } 295 } 296 catch (Exception ex) 297 { 298 throw new SystemException(ex); 299 } 300 } 301 302 public void setShort(Object that, short value) 303 { 304 try 305 { 306 if(isFinal) 307 { 308 finalFieldSetter.setShort(that, value); 309 } 310 else 311 { 312 javaField.setShort(that, value); 313 } 314 } 315 catch (Exception ex) 316 { 317 throw new SystemException(ex); 318 } 319 } 320 321 public void set(Object that, Object value) 322 { 323 try 324 { 325 if(isFinal) 326 { 327 finalFieldSetter.set(that, value); 328 } 329 else 330 { 331 javaField.set(that, value); 332 } 333 } 334 catch (Exception ex) 335 { 336 throw new SystemException(ex); 337 } 338 } 339 } 340 | Popular Tags |