1 package jfun.yan.xml.nuts; 2 3 import java.beans.IntrospectionException ; 4 5 import jfun.yan.Component; 6 import jfun.yan.xml.NutsUtils; 7 15 public class GetterNut extends DelegatingNut { 16 private String name; 17 private int ind = -1; 18 19 public int getInd() { 20 return ind; 21 } 22 public void setInd(int ind) { 23 if(ind < 0) 24 raise("invalid property index "+ind); 25 this.ind = ind; 26 } 27 public String getName() { 28 return name; 29 } 30 public void setName(String name) { 31 this.name = name.trim(); 32 } 33 private static Component getGetter1(Component c, String name, int ind) 34 throws IntrospectionException { 35 if(ind < 0) 36 return c.getter(name.trim()); 37 else 38 return c.getter(name.trim(), ind); 39 } 40 private static Component getGetterComponent(Component c, String name, int ind) 41 throws IntrospectionException { 42 if(name.indexOf('.')<0) return getGetter1(c, name, ind); 43 final String [] parts = NutsUtils.split(name, "."); 44 for(int i=0; i<parts.length-1; i++){ 45 c = c.getter(parts[i].trim()); 46 } 47 final String last = parts[parts.length-1]; 48 return getGetter1(c, last, ind); 49 } 50 public Component eval() 51 throws IntrospectionException { 52 final Component component = getComponent(); 53 checkMandatory("component", component); 54 checkMandatory("name", name); 55 return getGetterComponent(component, name, ind); 56 } 57 58 } 59 | Popular Tags |