KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.genimen.djeneric.repository.oql.core.nodes;
2
3 import java.util.HashMap JavaDoc;
4
5 import com.genimen.djeneric.repository.oql.core.DjOqlParserEngine;
6 import com.genimen.djeneric.repository.oql.core.SimpleNode;
7
8 public class StringNode extends SimpleNode implements ValueExpression
9 {
10   String JavaDoc _value = null;
11
12   public StringNode(int i)
13   {
14     super(i);
15   }
16
17   public StringNode(DjOqlParserEngine p, int i)
18   {
19     super(p, i);
20   }
21
22   public String JavaDoc getName()
23   {
24     return toString();
25   }
26
27   public String JavaDoc toString()
28   {
29     return _value;
30   }
31
32   public void setValue(String JavaDoc v)
33   {
34     // Strip the quotes
35
v = v.substring(1);
36     v = v.substring(0, v.length() - 1);
37
38     _value = translateEscapes(v);
39   }
40
41   public Object JavaDoc getValue(MatchingContext context)
42   {
43     return _value;
44   }
45
46   public Object JavaDoc getValue()
47   {
48     return _value;
49   }
50
51   static String JavaDoc _froms = "ntbrf\\'\"";
52   static String JavaDoc _tos = "\n\t\b\r\f\\'\"";
53
54   public static String JavaDoc translateEscapes(String JavaDoc src)
55   {
56     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(src);
57
58     int i = 0;
59     while (i < sb.length() - 1)
60     {
61       if (sb.charAt(i) == '\\')
62       {
63         for (int x = 0; x < _froms.length(); x++)
64         {
65           if (_froms.charAt(x) == sb.charAt(i + 1))
66           {
67             sb.deleteCharAt(i);
68             sb.setCharAt(i, _tos.charAt(x));
69             break;
70           }
71         }
72       }
73       i++;
74     }
75     return sb.toString();
76   }
77
78   public void translate(StringBuffer JavaDoc result, HashMap JavaDoc path2AliasMapping)
79   {
80     appendOpenBrackets(result);
81     result.append("'" + _value + "'");
82     appendCloseBrackets(result);
83   }
84 }
Popular Tags