KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > ejb > query > StringFunctionNode


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.ejb.query;
13
14 /**
15  * Functions that return strings.
16  */

17 public class StringFunctionNode extends Node {
18
19     public static final int CONCAT = 1;
20     public static final int SUBSTRING = 2;
21     public static final int TRIM = 3;
22     public static final int LOWER = 4;
23     public static final int UPPER = 5;
24
25     public static final int TRIM_LEADING = 1;
26     public static final int TRIM_TRAILING = 2;
27     public static final int TRIM_BOTH = 3;
28
29     private int function;
30     private Node argList;
31     private int trimSpec;
32     private LiteralNode trimChar;
33
34     public StringFunctionNode(int function, Node argList) {
35         this.function = function;
36         this.argList = argList;
37     }
38
39     public StringFunctionNode(int trimSpec, LiteralNode trimChar, Node argList) {
40         this(TRIM, argList);
41         this.trimSpec = trimSpec;
42         this.trimChar = trimChar;
43     }
44
45     public int getFunction() {
46         return function;
47     }
48
49     public Node getArgList() {
50         return argList;
51     }
52
53     public int getTrimSpec() {
54         return trimSpec;
55     }
56
57     public LiteralNode getTrimChar() {
58         return trimChar;
59     }
60
61     public String JavaDoc getFunctionStr() {
62         switch (function) {
63             case CONCAT: return "CONCAT";
64             case SUBSTRING: return "SUBSTRING";
65             case TRIM: return "TRIM";
66             case LOWER: return "LOWER";
67             case UPPER: return "UPPER";
68         }
69         return "<? function " + function + " ?>";
70     }
71
72     public String JavaDoc getTrimSpecStr() {
73         switch (trimSpec) {
74             case TRIM_LEADING: return "LEADING";
75             case TRIM_TRAILING: return "TRAILING";
76             case TRIM_BOTH: return "BOTH";
77         }
78         return "<? trimSpec " + trimSpec + "?>";
79     }
80
81     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
82         return v.arriveStringFunctionNode(this, msg);
83     }
84
85     public String JavaDoc toStringImp() {
86         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
87         s.append(getFunctionStr());
88         s.append('(');
89         if (function == TRIM) {
90             if (trimChar != null) {
91                 s.append(getTrimSpecStr());
92                 s.append(' ');
93                 s.append(trimChar);
94                 s.append(" FROM ");
95             }
96         }
97         if (argList != null) {
98             argList.appendList(s);
99         }
100         s.append(')');
101         return s.toString();
102     }
103
104     public void resolve(ResolveContext rc) {
105         resolve(argList, rc);
106     }
107
108 }
109
110
Popular Tags