KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.versant.core.common.BindingSupportImpl;
15
16 /**
17  * A method call.
18  */

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