1 22 package org.jboss.util; 23 24 import java.lang.reflect.Field ; 25 26 32 public class FieldInstance 33 { 34 35 protected final Field field; 36 37 38 protected final Object instance; 39 40 49 public FieldInstance(final Object instance, final String fieldName) 50 throws NoSuchFieldException 51 { 52 if (instance == null) 53 throw new NullArgumentException("instance"); 54 if (fieldName == null) 55 throw new NullArgumentException("fieldName"); 56 57 field = instance.getClass().getField(fieldName); 59 60 if (! field.getDeclaringClass().isAssignableFrom(instance.getClass())) 62 throw new IllegalArgumentException 63 ("field does not belong to instance class"); 64 65 this.instance = instance; 66 } 67 68 73 public final Field getField() { 74 return field; 75 } 76 77 82 public final Object getInstance() { 83 return instance; 84 } 85 86 93 public final Object get() throws IllegalAccessException { 94 return field.get(instance); 95 } 96 97 104 public final void set(final Object value) throws IllegalAccessException { 105 field.set(instance, value); 106 } 107 } 108 | Popular Tags |