1 16 17 package org.apache.axis.utils; 18 19 import java.beans.PropertyDescriptor ; 20 import java.lang.reflect.Array ; 21 import java.lang.reflect.Field ; 22 import java.lang.reflect.InvocationTargetException ; 23 24 25 29 public class FieldPropertyDescriptor extends BeanPropertyDescriptor { 30 private Field field = null; 31 32 38 public FieldPropertyDescriptor(String _name, 39 Field _field) { 40 field = _field; 41 try { 42 myPD = new PropertyDescriptor (_name, null, null); 43 } catch (Exception e) { 44 } 46 if (_field == null || _name == null) { 47 throw new IllegalArgumentException ( 48 Messages.getMessage(_field == null ? 49 "badField00" : "badProp03")); 50 } 51 } 52 53 public String getName() { 54 return field.getName(); 55 } 56 57 61 public boolean isReadable() { 62 return true; 63 } 64 65 69 public boolean isWriteable() { 70 return true; 71 } 72 73 78 public boolean isIndexed() { 79 return (field.getType().getComponentType() != null); 80 } 81 82 87 public Object get(Object obj) 88 throws InvocationTargetException , IllegalAccessException { 89 return field.get(obj); 90 } 91 92 97 public void set(Object obj, Object newValue) 98 throws InvocationTargetException , IllegalAccessException { 99 field.set(obj, newValue); 100 } 101 102 108 public Object get(Object obj, int i) 109 throws InvocationTargetException , IllegalAccessException { 110 if (!isIndexed()) { 111 throw new IllegalAccessException ("Not an indexed property"); 112 } 113 114 Object array = field.get(obj); 115 return Array.get(array, i); 116 } 117 118 124 public void set(Object obj, int i, Object newValue) 125 throws InvocationTargetException , IllegalAccessException { 126 if (!isIndexed()) { 127 throw new IllegalAccessException ("Not an indexed field!"); 128 } 129 Class componentType = field.getType().getComponentType(); 130 growArrayToSize(obj, componentType, i); 131 Array.set(get(obj), i, newValue); 132 } 133 134 138 public Class getType() { 139 if (isIndexed()) { 140 return field.getType().getComponentType(); 141 } else { 142 return field.getType(); 143 } 144 } 145 146 public Class getActualType() { 147 return field.getType(); 148 } 149 150 public Field getField() { 151 return field; 152 } 153 } 154 | Popular Tags |