1 package com.genimen.djeneric.tools.generator.core.nodes; 2 3 import com.genimen.djeneric.tools.generator.core.DjentelParserEngine; 4 import com.genimen.djeneric.tools.generator.core.ParseException; 5 import com.genimen.djeneric.tools.generator.core.SimpleNode; 6 import com.genimen.djeneric.tools.generator.core.util.ObjectPath; 7 import com.genimen.djeneric.tools.generator.core.util.ParseContext; 8 9 public class PropertyNode extends SimpleNode implements ValueExpression 10 { 11 private String path; 12 private boolean negated = false; 13 14 public PropertyNode(int i) 15 { 16 super(i); 17 } 18 19 public PropertyNode(DjentelParserEngine p, int i) 20 { 21 super(p, i); 22 } 23 24 public String getName() 25 { 26 return toString(); 27 } 28 29 public String toString() 30 { 31 if (isNegated()) return "!" + path; 32 return path; 33 } 34 35 public void setPath(String path) 36 { 37 this.path = path; 38 } 39 40 public String getPath() 41 { 42 return path; 43 } 44 45 public void setNegated(boolean negated) 46 { 47 this.negated = negated; 48 } 49 50 public boolean isNegated() 51 { 52 return negated; 53 } 54 55 public Object getValue(ParseContext context) throws ParseException 56 { 57 try 58 { 59 if (negated) 60 { 61 Object o = ObjectPath.evaluateProperty(getPath(), context); 62 if (!(o instanceof Boolean )) throw new ParseException("Can not negate a non-boolean value", beginLine, 63 beginColumn); 64 Boolean b = (Boolean ) o; 65 return new Boolean (!b.booleanValue()); 66 } 67 else return ObjectPath.evaluateProperty(getPath(), context); 68 } 69 catch (Exception x) 70 { 71 throw new ParseException(x, beginLine, beginColumn); 72 } 73 } 74 } | Popular Tags |