KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > functions > ConstantFunction0


1 // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.functions;
5 import gnu.mapping.*;
6 import gnu.expr.*;
7
8 /** A 0-argument function that returns a constant value.
9  * Used for false() and true() in XQuery. */

10
11 public class ConstantFunction0 extends Procedure0 implements CanInline
12 {
13   final Object JavaDoc value;
14   final QuoteExp constant;
15
16   public ConstantFunction0(String JavaDoc name, Object JavaDoc value)
17   {
18     super(name);
19     this.value = value;
20     this.constant = QuoteExp.getInstance(value);
21   }
22
23   public ConstantFunction0(String JavaDoc name, QuoteExp constant)
24   {
25     super(name);
26     this.value = constant.getValue();
27     this.constant = constant;
28   }
29
30   public Object JavaDoc apply0() { return value; }
31
32   public Expression inline (ApplyExp exp, ExpWalker walker)
33   {
34     int nargs = exp.getArgCount();
35     if (nargs != 0 && walker != null)
36       {
37     String JavaDoc message = WrongArguments.checkArgCount(this, nargs);
38     return walker.noteError(message);
39       }
40     return constant;
41   }
42 }
43
Popular Tags