KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A parameter.
16  */

17 public class ParameterNode extends Node {
18
19     private String JavaDoc name;
20     private int position;
21     private ResolveContext.ParamUsage usage;
22
23     public ParameterNode(boolean positional, String JavaDoc name) {
24         this.name = name;
25         if (positional) {
26             position = Integer.parseInt(name);
27             if (position <= 0) {
28                 throw new IllegalArgumentException JavaDoc(
29                         "Invalid positional parameter: " + position);
30             }
31         } else {
32             position = -1;
33         }
34     }
35
36     public boolean isPositional() {
37         return position >= 1;
38     }
39
40     /**
41      * This returns the String form of the position for positional parameters
42      * and the name for named parameters.
43      */

44     public String JavaDoc getName() {
45         return name;
46     }
47
48     /**
49      * This returns -1 for named parameters.
50      */

51     public int getPosition() {
52         return position;
53     }
54
55     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
56         return v.arriveParameterNode(this, msg);
57     }
58
59     public String JavaDoc toStringImp() {
60         return (isPositional() ? "?" : ":") + name;
61     }
62
63     public void resolve(ResolveContext rc) {
64         usage = rc.addParameterNode(this);
65     }
66
67     /**
68      * Get our usage entry
69      */

70     public ResolveContext.ParamUsage getUsage() {
71         return usage;
72     }
73
74 }
75
76
Popular Tags