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.ejb.query;
12:
13: /**
14: * A parameter.
15: */
16: public class ParameterNode extends Node {
17:
18: private String name;
19: private int position;
20: private ResolveContext.ParamUsage usage;
21:
22: public ParameterNode(boolean positional, String name) {
23: this .name = name;
24: if (positional) {
25: position = Integer.parseInt(name);
26: if (position <= 0) {
27: throw new IllegalArgumentException(
28: "Invalid positional parameter: " + position);
29: }
30: } else {
31: position = -1;
32: }
33: }
34:
35: public boolean isPositional() {
36: return position >= 1;
37: }
38:
39: /**
40: * This returns the String form of the position for positional parameters
41: * and the name for named parameters.
42: */
43: public String getName() {
44: return name;
45: }
46:
47: /**
48: * This returns -1 for named parameters.
49: */
50: public int getPosition() {
51: return position;
52: }
53:
54: public Object arrive(NodeVisitor v, Object msg) {
55: return v.arriveParameterNode(this , msg);
56: }
57:
58: public String toStringImp() {
59: return (isPositional() ? "?" : ":") + name;
60: }
61:
62: public void resolve(ResolveContext rc) {
63: usage = rc.addParameterNode(this );
64: }
65:
66: /**
67: * Get our usage entry
68: */
69: public ResolveContext.ParamUsage getUsage() {
70: return usage;
71: }
72:
73: }
|