1 18 package org.apache.beehive.netui.script.el.tokens; 19 20 import java.util.List ; 21 22 import org.apache.beehive.netui.util.logging.Logger; 23 24 27 public class ArrayIndexToken 28 extends ExpressionToken { 29 30 private static final Logger LOGGER = Logger.getInstance(ArrayIndexToken.class); 31 32 private int _index; 33 34 public ArrayIndexToken(String identifier) { 35 _index = Integer.parseInt(identifier); 36 } 37 38 public void update(Object root, Object newValue) { 39 if(root instanceof List ) 40 listUpdate((List )root, _index, newValue); 41 else if(root.getClass().isArray()) 42 arrayUpdate(root, _index, newValue); 43 else { 44 RuntimeException re = new RuntimeException ("The _index \"" + _index + "\" can not be used to look-up the type of a property" + 45 " on an object that is not an array or list."); 46 LOGGER.error("", re); 47 throw re; 48 } 49 } 50 51 public Object evaluate(Object value) { 52 if(value instanceof List ) 53 return listLookup((List )value, _index); 54 else if(value.getClass().isArray()) 55 return arrayLookup(value, _index); 56 else { 57 RuntimeException re = new RuntimeException ("The _index \"" + _index + "\" can not be used to look-up a property on an object that is not an array or list."); 58 LOGGER.error("", re); 59 throw re; 60 } 61 } 62 63 public String getTokenString() { 64 return "[" + _index + "]"; 65 } 66 67 public String toString() { 68 return "" + _index; 69 } 70 } 71 | Popular Tags |