KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > generator > core > nodes > PropertyNode


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 JavaDoc 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 JavaDoc getName()
25   {
26     return toString();
27   }
28
29   public String JavaDoc toString()
30   {
31     if (isNegated()) return "!" + path;
32     return path;
33   }
34
35   public void setPath(String JavaDoc path)
36   {
37     this.path = path;
38   }
39
40   public String JavaDoc 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 JavaDoc getValue(ParseContext context) throws ParseException
56   {
57     try
58     {
59       if (negated)
60       {
61         Object JavaDoc o = ObjectPath.evaluateProperty(getPath(), context);
62         if (!(o instanceof Boolean JavaDoc)) throw new ParseException("Can not negate a non-boolean value", beginLine,
63             beginColumn);
64         Boolean JavaDoc b = (Boolean JavaDoc) o;
65         return new Boolean JavaDoc(!b.booleanValue());
66       }
67       else return ObjectPath.evaluateProperty(getPath(), context);
68     }
69     catch (Exception JavaDoc x)
70     {
71       throw new ParseException(x, beginLine, beginColumn);
72     }
73   }
74 }
Popular Tags