KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > program > CompiledMethodRef_5


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.program;
31
32 import com.caucho.quercus.env.Env;
33 import com.caucho.quercus.env.NullValue;
34 import com.caucho.quercus.env.Value;
35 import com.caucho.quercus.expr.Expr;
36 import com.caucho.util.L10N;
37
38 import java.util.logging.Logger JavaDoc;
39
40 /**
41  * Represents a compiled method with 5 args
42  */

43 abstract public class CompiledMethodRef_5 extends CompiledMethodRef {
44   private static final Logger JavaDoc log
45     = Logger.getLogger(CompiledMethodRef_5.class.getName());
46   private static final L10N L = new L10N(CompiledMethodRef_5.class);
47
48   private String JavaDoc _name;
49   private Expr _default_0;
50   private Expr _default_1;
51   private Expr _default_2;
52   private Expr _default_3;
53   private Expr _default_4;
54
55   public CompiledMethodRef_5(String JavaDoc name,
56               Expr default_0,
57               Expr default_1,
58               Expr default_2,
59               Expr default_3,
60               Expr default_4)
61   {
62     _name = name;
63     _default_0 = default_0;
64     _default_1 = default_1;
65     _default_2 = default_2;
66     _default_3 = default_3;
67     _default_4 = default_4;
68   }
69   
70   /**
71    * Binds the user's arguments to the actual arguments.
72    *
73    * @param args the user's arguments
74    * @return the user arguments augmented by any defaults
75    */

76   public Expr []bindArguments(Env env, Expr fun, Expr []args)
77   {
78     if (args.length != 5)
79       env.warning(L.l("incorrect"));
80
81     return args;
82   }
83
84   /**
85    * Evaluates the method with the given variable arguments.
86    */

87   public Value callMethodRef(Env env, Value obj, Value []argValues)
88   {
89     switch (argValues.length) {
90     case 0:
91       return callMethodRef(env,
92             obj,
93             _default_0.eval(env),
94             _default_1.eval(env),
95             _default_2.eval(env),
96             _default_3.eval(env),
97             _default_4.eval(env));
98     case 1:
99       return callMethodRef(env,
100             obj,
101             argValues[0],
102             _default_1.eval(env),
103             _default_2.eval(env),
104             _default_3.eval(env),
105             _default_4.eval(env));
106     case 2:
107       return callMethodRef(env,
108             obj,
109             argValues[0],
110             argValues[1],
111             _default_2.eval(env),
112             _default_3.eval(env),
113             _default_4.eval(env));
114     case 3:
115       return callMethodRef(env,
116             obj,
117             argValues[0],
118             argValues[1],
119             argValues[2],
120             _default_3.eval(env),
121             _default_4.eval(env));
122     case 4:
123       return callMethodRef(env,
124             obj,
125             argValues[0],
126             argValues[1],
127             argValues[2],
128             argValues[3],
129             _default_4.eval(env));
130     case 5:
131     default:
132       return callMethodRef(env,
133             obj,
134             argValues[0],
135             argValues[1],
136             argValues[2],
137             argValues[3],
138             argValues[4]);
139     }
140   }
141
142   abstract public Value callMethodRef(Env env,
143                    Value obj,
144                    Value a1,
145                    Value a2,
146                    Value a3,
147                    Value a4,
148                                    Value a5);
149
150   /**
151    * Evaluates the method as a static function
152    */

153   public Value call(Env env, Value []argValues)
154   {
155     env.warning(L.l("can't call '{0}' as a static function", _name));
156
157     return NullValue.NULL;
158   }
159   
160   public String JavaDoc toString()
161   {
162     return "CompiledMethodRef_5[" + _name + "]";
163   }
164 }
165
166
Popular Tags