1 16 package com.ibatis.common.beans; 17 18 import java.util.List ; 19 20 23 public abstract class BaseProbe implements Probe { 24 25 protected abstract void setProperty(Object object, String property, Object value); 26 27 protected abstract Object getProperty(Object object, String property); 28 29 35 public abstract String [] getReadablePropertyNames(Object object); 36 37 43 public abstract String [] getWriteablePropertyNames(Object object); 44 45 protected Object getIndexedProperty(Object object, String indexedName) { 46 47 Object value = null; 48 49 try { 50 String name = indexedName.substring(0, indexedName.indexOf("[")); 51 int i = Integer.parseInt(indexedName.substring(indexedName.indexOf("[") + 1, indexedName.indexOf("]"))); 52 Object list = getProperty(object, name); 53 if (list instanceof List ) { 54 value = ((List ) list).get(i); 55 } else if (list instanceof Object []) { 56 value = ((Object []) list)[i]; 57 } else if (list instanceof char[]) { 58 value = new Character (((char[]) list)[i]); 59 } else if (list instanceof boolean[]) { 60 value = new Boolean (((boolean[]) list)[i]); 61 } else if (list instanceof byte[]) { 62 value = new Byte (((byte[]) list)[i]); 63 } else if (list instanceof double[]) { 64 value = new Double (((double[]) list)[i]); 65 } else if (list instanceof float[]) { 66 value = new Float (((float[]) list)[i]); 67 } else if (list instanceof int[]) { 68 value = new Integer (((int[]) list)[i]); 69 } else if (list instanceof long[]) { 70 value = new Long (((long[]) list)[i]); 71 } else if (list instanceof short[]) { 72 value = new Short (((short[]) list)[i]); 73 } else { 74 throw new ProbeException("The '" + name + "' property of the " + object.getClass().getName() + " class is not a List or Array."); 75 } 76 77 } catch (ProbeException e) { 78 throw e; 79 } catch (Exception e) { 80 throw new ProbeException("Error getting ordinal list from JavaBean. Cause " + e, e); 81 } 82 83 return value; 84 } 85 86 protected void setIndexedProperty(Object object, String indexedName, Object value) { 87 88 try { 89 String name = indexedName.substring(0, indexedName.indexOf("[")); 90 int i = Integer.parseInt(indexedName.substring(indexedName.indexOf("[") + 1, indexedName.indexOf("]"))); 91 Object list = getProperty(object, name); 92 if (list instanceof List ) { 93 ((List ) list).set(i, value); 94 } else if (list instanceof Object []) { 95 ((Object []) list)[i] = value; 96 } else if (list instanceof char[]) { 97 ((char[]) list)[i] = ((Character ) value).charValue(); 98 } else if (list instanceof boolean[]) { 99 ((boolean[]) list)[i] = ((Boolean ) value).booleanValue(); 100 } else if (list instanceof byte[]) { 101 ((byte[]) list)[i] = ((Byte ) value).byteValue(); 102 } else if (list instanceof double[]) { 103 ((double[]) list)[i] = ((Double ) value).doubleValue(); 104 } else if (list instanceof float[]) { 105 ((float[]) list)[i] = ((Float ) value).floatValue(); 106 } else if (list instanceof int[]) { 107 ((int[]) list)[i] = ((Integer ) value).intValue(); 108 } else if (list instanceof long[]) { 109 ((long[]) list)[i] = ((Long ) value).longValue(); 110 } else if (list instanceof short[]) { 111 ((short[]) list)[i] = ((Short ) value).shortValue(); 112 } else { 113 throw new ProbeException("The '" + name + "' property of the " + object.getClass().getName() + " class is not a List or Array."); 114 } 115 } catch (ProbeException e) { 116 throw e; 117 } catch (Exception e) { 118 throw new ProbeException("Error getting ordinal value from JavaBean. Cause " + e, e); 119 } 120 } 121 122 123 } 124 | Popular Tags |