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: import com.versant.core.common.BindingSupportImpl;
14:
15: /**
16: * A method call.
17: */
18: public class MethodNode extends Node {
19:
20: public Node args;
21: private int method;
22:
23: public static final int STARTS_WITH = 1;
24: public static final int ENDS_WITH = 2;
25: public static final int CONTAINS = 3;
26: public static final int IS_EMPTY = 4;
27: public static final int CONTAINS_KEY = 5;
28: public static final int TO_LOWER_CASE = 6;
29: public static final int SQL = 7;
30: public static final int CONTAINS_PARAM = 8;
31:
32: public MethodNode() {
33: }
34:
35: public MethodNode(int method) {
36: this .method = method;
37: }
38:
39: public Object accept(NodeVisitor visitor, Object[] results) {
40: return visitor.visitMethodNode(this , results);
41: }
42:
43: public String getName() {
44: switch (method) {
45: case STARTS_WITH:
46: return "startsWith";
47: case ENDS_WITH:
48: return "endsWith";
49: case CONTAINS:
50: return "contains";
51: case IS_EMPTY:
52: return "isEmpty";
53: case CONTAINS_KEY:
54: return "containsKey";
55: case TO_LOWER_CASE:
56: return "toLowerCase";
57: case SQL:
58: return "sql";
59: }
60: return "Unknown(" + method + ")";
61: }
62:
63: public int getMethod() {
64: return method;
65: }
66:
67: public void setName(String name) {
68: if (name.equals("startsWith"))
69: method = STARTS_WITH;
70: else if (name.equals("endsWith"))
71: method = ENDS_WITH;
72: else if (name.equals("contains"))
73: method = CONTAINS;
74: else if (name.equals("isEmpty"))
75: method = IS_EMPTY;
76: else if (name.equals("containsKey"))
77: method = CONTAINS_KEY;
78: else if (name.equals("toLowerCase"))
79: method = TO_LOWER_CASE;
80: else if (name.equals("sql"))
81: method = SQL;
82: else
83: throw BindingSupportImpl.getInstance().invalidOperation(
84: "Invalid method name: '" + name + "'");
85: }
86:
87: public String toString() {
88: return super .toString() + " : " + getName();
89: }
90:
91: public Field visit(MemVisitor visitor, Object obj) {
92: return visitor.visitMethodNode(this , obj);
93: }
94:
95: public Object arrive(NodeVisitor v, Object msg) {
96: return v.arriveMethodNode(this, msg);
97: }
98:
99: }
|