KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > LiteralNode


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 /**
15  * A literal e.g 5 or "abc".
16  */

17 public class LiteralNode extends LeafNode {
18
19     public static final int TYPE_STRING = 1;
20     public static final int TYPE_OTHER = 2;
21
22     public static final int TYPE_BOOLEAN = 3;
23     public static final int TYPE_CHAR = 4;
24     public static final int TYPE_LONG = 5;
25     public static final int TYPE_DOUBLE = 7;
26
27     public static final int TYPE_NULL = 8;
28
29     /**
30      * Type of literal.
31      */

32     public int type;
33     /**
34      * Value of literal.
35      */

36     public String JavaDoc value;
37
38     public LiteralNode(Node parent, int type, String JavaDoc value) {
39         this.parent = parent;
40         this.type = type;
41         this.value = value;
42     }
43
44     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
45       return visitor.visitLiteralNode(this, results);
46     }
47
48     public String JavaDoc toString() {
49         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
50         s.append(super.toString());
51         s.append(' ');
52         s.append(value);
53         s.append(' ');
54         s.append(toTypeStr(type));
55         return s.toString();
56     }
57
58     private static String JavaDoc toTypeStr(int t) {
59         switch (t) {
60             case TYPE_STRING: return "STRING";
61             case TYPE_OTHER: return "OTHER";
62             case TYPE_BOOLEAN: return "BOOLEAN";
63             case TYPE_CHAR: return "CHAR";
64             case TYPE_LONG: return "LONG";
65             case TYPE_DOUBLE: return "DOUBLE";
66             case TYPE_NULL: return "NULL";
67         }
68         return "UNKNOWN(" + t + ")";
69     }
70
71     public Field visit(MemVisitor visitor, Object JavaDoc obj) {
72         return visitor.visitLiteralNode(this, obj);
73     }
74
75     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
76         return v.arriveLiteralNode(this, msg);
77     }
78
79 }
80
81
Popular Tags