1 55 56 package org.jboss.axis.utils; 57 58 import java.beans.PropertyDescriptor ; 59 import java.lang.reflect.Array ; 60 import java.lang.reflect.Field ; 61 import java.lang.reflect.InvocationTargetException ; 62 63 64 67 public class FieldPropertyDescriptor extends BeanPropertyDescriptor 68 { 69 private Field field = null; 70 71 78 public FieldPropertyDescriptor(String _name, 79 Field _field) 80 { 81 field = _field; 82 try 83 { 84 myPD = new PropertyDescriptor (_name, null, null); 85 } 86 catch (Exception e) 87 { 88 } 90 if (_field == null || _name == null) 91 { 92 throw new IllegalArgumentException (Messages.getMessage(_field == null ? 93 "badField00" : "badProp03")); 94 } 95 } 96 97 public String getName() 98 { 99 return field.getName(); 100 } 101 102 107 public boolean isReadable() 108 { 109 return true; 110 } 111 112 117 public boolean isWriteable() 118 { 119 return true; 120 } 121 122 128 public boolean isIndexed() 129 { 130 return (field.getType().getComponentType() != null); 131 } 132 133 139 public Object get(Object obj) 140 throws InvocationTargetException , IllegalAccessException 141 { 142 return field.get(obj); 143 } 144 145 151 public void set(Object obj, Object newValue) 152 throws InvocationTargetException , IllegalAccessException 153 { 154 field.set(obj, newValue); 155 } 156 157 164 public Object get(Object obj, int i) 165 throws InvocationTargetException , IllegalAccessException 166 { 167 if (!isIndexed()) 168 { 169 throw new IllegalAccessException ("Not an indexed property"); 170 } 171 172 Object array = field.get(obj); 173 return Array.get(array, i); 174 } 175 176 183 public void set(Object obj, int i, Object newValue) 184 throws InvocationTargetException , IllegalAccessException 185 { 186 if (!isIndexed()) 187 { 188 throw new IllegalAccessException ("Not an indexed field!"); 189 } 190 Class componentType = field.getType().getComponentType(); 191 growArrayToSize(obj, componentType, i); 192 Array.set(get(obj), i, newValue); 193 } 194 195 200 public Class getType() 201 { 202 if (isIndexed()) 203 { 204 return field.getType().getComponentType(); 205 } 206 else 207 { 208 return field.getType(); 209 } 210 } 211 } 212 | Popular Tags |