1 18 package org.apache.beehive.netui.script.el.tokens; 19 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.apache.beehive.netui.util.logging.Logger; 24 25 28 public class IdentifierToken 29 extends ExpressionToken { 30 31 private static final Logger LOGGER = Logger.getInstance(IdentifierToken.class); 32 private static final boolean DEBUG_ENABLED = LOGGER.isDebugEnabled(); 33 34 private String _identifier = null; 35 36 public IdentifierToken(String identifier) { 37 _identifier = identifier; 38 } 39 40 public Object evaluate(Object value) { 41 42 if(value == null) { 43 String msg = "Can not evaluate the identifier \"" + _identifier + "\" on a null value object."; 44 if(LOGGER.isErrorEnabled()) 45 LOGGER.error(msg); 46 throw new RuntimeException (msg); 47 } 48 49 if(DEBUG_ENABLED) { 50 LOGGER.debug("evaluate: " + _identifier); 51 LOGGER.debug("value type: " + value.getClass().getName()); 52 } 53 54 if(value instanceof Map ) { 55 return mapLookup((Map )value, _identifier); 56 } else if(value instanceof List ) { 57 int i = parseIndex(_identifier); 58 return listLookup((List )value, i); 59 } else if(value.getClass().isArray()) { 60 int i = parseIndex(_identifier); 61 return arrayLookup(value, i); 62 } else 63 return beanLookup(value, _identifier); 64 } 65 66 public void update(Object root, Object newValue) { 67 68 if(root == null) { 69 String msg = "Can not update the identifier \"" + _identifier + "\" on a null value object."; 70 if(LOGGER.isErrorEnabled()) 71 LOGGER.error(msg); 72 throw new RuntimeException (msg); 73 } 74 75 if(DEBUG_ENABLED) 76 LOGGER.debug("Update _identifier \"" + _identifier + "\" on object of type: \"" + root.getClass().getName() + "\""); 77 78 if(root instanceof Map ) 79 mapUpdate((Map )root, _identifier, newValue); 80 else if(root instanceof List ) { 81 int i = parseIndex(_identifier); 82 listUpdate((List )root, i, newValue); 83 } else if(root.getClass().isArray()) { 84 int i = parseIndex(_identifier); 85 arrayUpdate(root, i, newValue); 86 } else 87 beanUpdate(root, _identifier, newValue); 88 } 89 90 public String getTokenString() { 91 return "." + _identifier; 92 } 93 94 public String toString() { 95 return _identifier; 96 } 97 } 98 | Popular Tags |