1 package jfun.yan.xml.nuts.optional; 2 3 import java.util.List ; 4 5 import jfun.util.Misc; 6 import jfun.yan.Component; 7 import jfun.yan.Components; 8 import jfun.yan.xml.nuts.DelegatingNut; 9 16 public class SubscriptNut extends DelegatingNut { 17 private int ind = -1; 18 19 public int getInd() { 20 return ind; 21 } 22 23 public void setInd(int ind) { 24 checkIndex(ind); 25 this.ind = ind; 26 } 27 private void checkIndex(int ind){ 28 if(ind<0){ 29 raise("invalid subscript: "+ind); 30 } 31 } 32 public Component eval(){ 33 final Component cc = getComponent(); 34 checkMandatory("component", cc); 35 checkIndex(ind); 36 final Class type = cc.getType(); 37 if(type!=null && !type.isArray() && 38 !jfun.yan.util.Utils.isCompatible(List .class, cc) 39 ){ 40 throw raise("cannot apply subscript against " + 41 Misc.getTypeName(type)); 42 } 43 return Components.subscript(cc, ind); 44 } 45 46 } 47 | Popular Tags |