001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.env;
031:
032: /**
033: * Represents a call to a function.
034: */
035: abstract public class Callback extends Value {
036:
037: /*
038: * Evaluates a callback where the first argument is from an array.
039: * For ArrayModule.
040: *
041: * @param env
042: * @param array from which a1 came from
043: * @param key index of a1 in the array
044: * @param a1 need to make a reference to this variable
045: */
046: final public Value call(Env env, ArrayValue array, Value key,
047: Value a1) {
048: Value result;
049:
050: if (a1 instanceof Var) {
051: a1 = new RefVar((Var) a1);
052:
053: result = call(env, a1);
054: } else {
055: a1 = new Var(a1);
056:
057: result = call(env, a1);
058:
059: array.put(key, a1.toValue());
060: }
061:
062: return result;
063: }
064:
065: /*
066: * Evaluates a callback where the first argument is from an array.
067: * For ArrayModule.
068: *
069: * @param env
070: * @param array from which a1 came from
071: * @param key index of a1 in the array
072: * @param a1 need to make a reference to this variable
073: * @param a2 additional argument to pass to the callback
074: */
075: final public Value call(Env env, ArrayValue array, Value key,
076: Value a1, Value a2) {
077: Value result;
078:
079: if (a1 instanceof Var) {
080: a1 = new RefVar((Var) a1);
081:
082: result = call(env, a1, a2);
083: } else {
084: a1 = new Var(a1);
085:
086: result = call(env, a1, a2);
087:
088: array.put(key, a1.toValue());
089: }
090:
091: return result;
092: }
093:
094: /*
095: * Evaluates a callback where the first argument is from an array.
096: * For ArrayModule.
097: *
098: * @param env
099: * @param array from which a1 came from
100: * @param key index of a1 in the array
101: * @param a1 need to make a reference to this variable
102: * @param a2 additional argument to pass to the callback
103: * @param a3 additional argument to pass to the callback
104: */
105: final public Value call(Env env, ArrayValue array, Value key,
106: Value a1, Value a2, Value a3) {
107: Value result;
108:
109: if (a1 instanceof Var) {
110: a1 = new RefVar((Var) a1);
111:
112: result = call(env, a1, a2, a3);
113: } else {
114: a1 = new Var(a1);
115:
116: result = call(env, a1, a2, a3);
117:
118: array.put(key, a1.toValue());
119: }
120:
121: return result;
122: }
123:
124: /**
125: * Evaluates the callback with no arguments.
126: *
127: * @param env the calling environment
128: */
129: abstract public Value call(Env env);
130:
131: /**
132: * Evaluates the callback with 1 arguments.
133: *
134: * @param env the calling environment
135: */
136: abstract public Value call(Env env, Value a1);
137:
138: /**
139: * Evaluates the callback with 2 arguments.
140: *
141: * @param env the calling environment
142: */
143: abstract public Value call(Env env, Value a1, Value a2);
144:
145: /**
146: * Evaluates the callback with 3 arguments.
147: *
148: * @param env the calling environment
149: */
150: abstract public Value call(Env env, Value a1, Value a2, Value a3);
151:
152: /**
153: * Evaluates the callback with 4 arguments.
154: *
155: * @param env the calling environment
156: */
157: abstract public Value call(Env env, Value a1, Value a2, Value a3,
158: Value a4);
159:
160: /**
161: * Evaluates the callback with 5 arguments.
162: *
163: * @param env the calling environment
164: */
165: abstract public Value call(Env env, Value a1, Value a2, Value a3,
166: Value a4, Value a5);
167:
168: /**
169: * Evaluates the callback with variable arguments.
170: *
171: * @param env the calling environment
172: */
173: abstract public Value call(Env env, Value[] args);
174:
175: /**
176: *
177: * @return true if this is an invalid callback reference
178: */
179: abstract public boolean isValid();
180:
181: /**
182: * Returns the name of the callback.
183: *
184: */
185: abstract public String getCallbackName();
186:
187: /**
188: * Returns true if this callback is implemented internally (i.e. in Java).
189: *
190: */
191: abstract public boolean isInternal();
192: }
|