001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.ejb.query;
012:
013: /**
014: * Functions that return strings.
015: */
016: public class StringFunctionNode extends Node {
017:
018: public static final int CONCAT = 1;
019: public static final int SUBSTRING = 2;
020: public static final int TRIM = 3;
021: public static final int LOWER = 4;
022: public static final int UPPER = 5;
023:
024: public static final int TRIM_LEADING = 1;
025: public static final int TRIM_TRAILING = 2;
026: public static final int TRIM_BOTH = 3;
027:
028: private int function;
029: private Node argList;
030: private int trimSpec;
031: private LiteralNode trimChar;
032:
033: public StringFunctionNode(int function, Node argList) {
034: this .function = function;
035: this .argList = argList;
036: }
037:
038: public StringFunctionNode(int trimSpec, LiteralNode trimChar,
039: Node argList) {
040: this (TRIM, argList);
041: this .trimSpec = trimSpec;
042: this .trimChar = trimChar;
043: }
044:
045: public int getFunction() {
046: return function;
047: }
048:
049: public Node getArgList() {
050: return argList;
051: }
052:
053: public int getTrimSpec() {
054: return trimSpec;
055: }
056:
057: public LiteralNode getTrimChar() {
058: return trimChar;
059: }
060:
061: public String getFunctionStr() {
062: switch (function) {
063: case CONCAT:
064: return "CONCAT";
065: case SUBSTRING:
066: return "SUBSTRING";
067: case TRIM:
068: return "TRIM";
069: case LOWER:
070: return "LOWER";
071: case UPPER:
072: return "UPPER";
073: }
074: return "<? function " + function + " ?>";
075: }
076:
077: public String getTrimSpecStr() {
078: switch (trimSpec) {
079: case TRIM_LEADING:
080: return "LEADING";
081: case TRIM_TRAILING:
082: return "TRAILING";
083: case TRIM_BOTH:
084: return "BOTH";
085: }
086: return "<? trimSpec " + trimSpec + "?>";
087: }
088:
089: public Object arrive(NodeVisitor v, Object msg) {
090: return v.arriveStringFunctionNode(this , msg);
091: }
092:
093: public String toStringImp() {
094: StringBuffer s = new StringBuffer();
095: s.append(getFunctionStr());
096: s.append('(');
097: if (function == TRIM) {
098: if (trimChar != null) {
099: s.append(getTrimSpecStr());
100: s.append(' ');
101: s.append(trimChar);
102: s.append(" FROM ");
103: }
104: }
105: if (argList != null) {
106: argList.appendList(s);
107: }
108: s.append(')');
109: return s.toString();
110: }
111:
112: public void resolve(ResolveContext rc) {
113: resolve(argList, rc);
114: }
115:
116: }
|