KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > env > CallbackObjectMethod


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.env;
31
32 import com.caucho.quercus.program.AbstractFunction;
33 import com.caucho.vfs.WriteStream;
34
35 import java.io.IOException JavaDoc;
36 import java.util.IdentityHashMap JavaDoc;
37
38 /**
39  * Represents a call to an object's method
40  */

41 public class CallbackObjectMethod extends Callback {
42   private final Value _obj;
43   private final String JavaDoc _methodName;
44   private final AbstractFunction _fun;
45
46   public CallbackObjectMethod(Env env, Value obj, String JavaDoc methodName)
47   {
48     _obj = obj;
49     _methodName = methodName.intern();
50     // _fun = env.findMethod(_obj.getType(), _methodName);
51
_fun = env.findMethod(_obj.getClassName(), _methodName);
52   }
53
54   /**
55    * Evaluates the callback with no arguments.
56    *
57    * @param env the calling environment
58    */

59   public Value call(Env env)
60   {
61     return _obj.callMethod(env, _methodName);
62   }
63
64   /**
65    * Evaluates the callback with 1 argument.
66    *
67    * @param env the calling environment
68    */

69   public Value call(Env env, Value a1)
70   {
71     return _obj.callMethod(env, _methodName, a1);
72   }
73
74   /**
75    * Evaluates the callback with 2 arguments.
76    *
77    * @param env the calling environment
78    */

79   public Value call(Env env, Value a1, Value a2)
80   {
81     return _obj.callMethod(env, _methodName, a1, a2);
82   }
83
84   /**
85    * Evaluates the callback with 3 arguments.
86    *
87    * @param env the calling environment
88    */

89   public Value call(Env env, Value a1, Value a2, Value a3)
90   {
91     return _obj.callMethod(env, _methodName, a1, a2, a3);
92   }
93
94   /**
95    * Evaluates the callback with 3 arguments.
96    *
97    * @param env the calling environment
98    */

99   public Value call(Env env, Value a1, Value a2, Value a3,
100                  Value a4)
101   {
102     return _obj.callMethod(env, _methodName, a1, a2, a3, a4);
103   }
104
105   /**
106    * Evaluates the callback with 3 arguments.
107    *
108    * @param env the calling environment
109    */

110   public Value call(Env env, Value a1, Value a2, Value a3,
111             Value a4, Value a5)
112   {
113     return _obj.callMethod(env, _methodName, a1, a2, a3, a4, a5);
114   }
115
116   public Value call(Env env, Value []args)
117   {
118     return _obj.callMethod(env, _methodName, args);
119   }
120
121   public void varDumpImpl(Env env,
122                           WriteStream out,
123                           int depth,
124                           IdentityHashMap JavaDoc<Value, String JavaDoc> valueSet)
125     throws IOException JavaDoc
126   {
127     out.print(getClass().getName());
128     out.print('[');
129     out.print(_methodName);
130     out.print(']');
131   }
132   
133   // XXX: just a placeholder, need real implementation here
134
public boolean isValid()
135   {
136     return true;
137   }
138
139   public String JavaDoc getCallbackName()
140   {
141     return _methodName;
142   }
143
144   public boolean isInternal()
145   {
146     return _fun instanceof JavaInvoker;
147   }
148 }
149
Popular Tags