01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.query;
12:
13: /**
14: * A literal e.g 5 or "abc".
15: */
16: public class LiteralNode extends LeafNode {
17:
18: public static final int TYPE_STRING = 1;
19: public static final int TYPE_OTHER = 2;
20:
21: public static final int TYPE_BOOLEAN = 3;
22: public static final int TYPE_CHAR = 4;
23: public static final int TYPE_LONG = 5;
24: public static final int TYPE_DOUBLE = 7;
25:
26: public static final int TYPE_NULL = 8;
27:
28: /**
29: * Type of literal.
30: */
31: public int type;
32: /**
33: * Value of literal.
34: */
35: public String value;
36:
37: public LiteralNode(Node parent, int type, String value) {
38: this .parent = parent;
39: this .type = type;
40: this .value = value;
41: }
42:
43: public Object accept(NodeVisitor visitor, Object[] results) {
44: return visitor.visitLiteralNode(this , results);
45: }
46:
47: public String toString() {
48: StringBuffer s = new StringBuffer();
49: s.append(super .toString());
50: s.append(' ');
51: s.append(value);
52: s.append(' ');
53: s.append(toTypeStr(type));
54: return s.toString();
55: }
56:
57: private static String toTypeStr(int t) {
58: switch (t) {
59: case TYPE_STRING:
60: return "STRING";
61: case TYPE_OTHER:
62: return "OTHER";
63: case TYPE_BOOLEAN:
64: return "BOOLEAN";
65: case TYPE_CHAR:
66: return "CHAR";
67: case TYPE_LONG:
68: return "LONG";
69: case TYPE_DOUBLE:
70: return "DOUBLE";
71: case TYPE_NULL:
72: return "NULL";
73: }
74: return "UNKNOWN(" + t + ")";
75: }
76:
77: public Field visit(MemVisitor visitor, Object obj) {
78: return visitor.visitLiteralNode(this , obj);
79: }
80:
81: public Object arrive(NodeVisitor v, Object msg) {
82: return v.arriveLiteralNode(this, msg);
83: }
84:
85: }
|