KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > oql > core > nodes > PropertyOrFunctionNode


1 package com.genimen.djeneric.repository.oql.core.nodes;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5
6 import com.genimen.djeneric.repository.oql.core.DjOqlParserEngine;
7 import com.genimen.djeneric.repository.oql.core.MatchException;
8 import com.genimen.djeneric.repository.oql.core.ParseException;
9 import com.genimen.djeneric.repository.oql.core.SimpleNode;
10
11 public class PropertyOrFunctionNode extends SimpleNode implements ValueExpression
12 {
13   boolean _isFunction = false;
14
15   public PropertyOrFunctionNode(int i)
16   {
17     super(i);
18   }
19
20   public PropertyOrFunctionNode(DjOqlParserEngine p, int i)
21   {
22     super(p, i);
23   }
24
25   public String JavaDoc getName()
26   {
27     if (_isFunction) return "function";
28     return "property";
29   }
30
31   public String JavaDoc toString()
32   {
33     return getName();
34   }
35
36   public boolean isFunction()
37   {
38     return _isFunction;
39   }
40
41   public void setFunction(boolean b)
42   {
43     _isFunction = b;
44   }
45
46   public Object JavaDoc[] getParams()
47   {
48     ArrayList JavaDoc paramList = new ArrayList JavaDoc();
49     for (int i = 1; i < getChildCount(); i++)
50     {
51       paramList.add(getChild(i));
52     }
53     return paramList.toArray(new Object JavaDoc[0]);
54   }
55
56   public void translate(StringBuffer JavaDoc result, HashMap JavaDoc path2AliasMapping) throws ParseException
57   {
58     appendOpenBrackets(result);
59     if (isFunction())
60     {
61       result.append(getChild(0).toString());
62
63       // Skip the function name
64
result.append("(");
65       for (int i = 1; i < getChildCount(); i++)
66       {
67         getChild(i).translate(result, path2AliasMapping);
68         if (i != getChildCount() - 1) result.append(", ");
69       }
70       result.append(")");
71     }
72     else super.translate(result, path2AliasMapping);
73     appendCloseBrackets(result);
74   }
75
76   public Object JavaDoc getValue(MatchingContext context) throws MatchException
77   {
78     if (isFunction())
79     {
80       throw new MatchException("Functions not supported in OQL where clause");
81     }
82     else
83     {
84       ValueExpression prop = (ValueExpression) getChild(0);
85       return prop.getValue(context);
86     }
87   }
88
89   protected Object JavaDoc evalFunction(Object JavaDoc obj, MatchingContext context) throws Exception JavaDoc
90   {
91     throw new MatchException("Functions not supported in OQL where clause");
92   }
93
94 }
Popular Tags