1 package jfun.yan.xml.nuts; 2 3 4 5 import java.util.ArrayList ; 6 7 import java.util.List ; 8 9 10 import jfun.util.Misc; 11 import jfun.util.StringUtils; 12 import jfun.yan.Component; 13 import jfun.yan.Components; 14 import jfun.yan.SimpleComponent; 15 import jfun.yan.util.Utils; 16 22 public class ListNut extends CollectionNut { 23 public void setType(Class type){ 24 if(List .class.isAssignableFrom(type)){ 25 super.setType(type); 26 } 27 else{ 28 raise(Misc.getTypeName(type) + 29 " is not a sub-type of java.util.List"); 30 } 31 } 32 private List createList(int sz){ 33 try{ 34 return Utils.createList(getType(), sz); 35 } 36 catch(Exception e){ 37 throw raise(e); 38 } 39 } 40 public Component eval(){ 41 final Component[] elements = getMandatoryElements(); 42 final Class ltype = getType(ArrayList .class); 43 final Component step1 = new SimpleComponent(ltype){ 44 public Object create(){ 45 return createList(elements.length); 46 } 47 public String toString(){ 48 return "list"+StringUtils.listArray("[",",","]",elements); 49 } 50 }; 51 return Components.storeList(step1, elements); 52 61 } 62 63 } 64 | Popular Tags |