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: import com.caucho.quercus.program.AbstractFunction;
033: import com.caucho.vfs.WriteStream;
034:
035: import java.io.IOException;
036: import java.util.IdentityHashMap;
037:
038: /**
039: * Represents a call to an object's method
040: */
041: public class CallbackObjectMethod extends Callback {
042: private final Value _obj;
043:
044: private final String _methodName;
045: private final int _hash;
046: private final char[] _name;
047:
048: private final AbstractFunction _fun;
049:
050: public CallbackObjectMethod(Env env, Value obj, String methodName) {
051: _obj = obj;
052: _methodName = methodName;
053: _hash = MethodMap.hash(methodName);
054: _name = _methodName.toCharArray();
055:
056: // _fun = env.findMethod(_obj.getType(), _methodName);
057: _fun = env.findMethod(_obj.getClassName(), _methodName);
058: }
059:
060: /**
061: * Evaluates the callback with no arguments.
062: *
063: * @param env the calling environment
064: */
065: @Override
066: public Value call(Env env) {
067: return _obj.callMethod(env, _hash, _name, _name.length);
068: }
069:
070: /**
071: * Evaluates the callback with 1 argument.
072: *
073: * @param env the calling environment
074: */
075: @Override
076: public Value call(Env env, Value a1) {
077: return _obj.callMethod(env, _hash, _name, _name.length, a1);
078: }
079:
080: /**
081: * Evaluates the callback with 2 arguments.
082: *
083: * @param env the calling environment
084: */
085: @Override
086: public Value call(Env env, Value a1, Value a2) {
087: return _obj.callMethod(env, _hash, _name, _name.length, a1, a2);
088: }
089:
090: /**
091: * Evaluates the callback with 3 arguments.
092: *
093: * @param env the calling environment
094: */
095: @Override
096: public Value call(Env env, Value a1, Value a2, Value a3) {
097: return _obj.callMethod(env, _hash, _name, _name.length, a1, a2,
098: a3);
099: }
100:
101: /**
102: * Evaluates the callback with 3 arguments.
103: *
104: * @param env the calling environment
105: */
106: @Override
107: public Value call(Env env, Value a1, Value a2, Value a3, Value a4) {
108: return _obj.callMethod(env, _hash, _name, _name.length, a1, a2,
109: a3, a4);
110: }
111:
112: /**
113: * Evaluates the callback with 3 arguments.
114: *
115: * @param env the calling environment
116: */
117: @Override
118: public Value call(Env env, Value a1, Value a2, Value a3, Value a4,
119: Value a5) {
120: return _obj.callMethod(env, _hash, _name, _name.length, a1, a2,
121: a3, a4, a5);
122: }
123:
124: @Override
125: public Value call(Env env, Value[] args) {
126: return _obj.callMethod(env, _hash, _name, _name.length, args);
127: }
128:
129: @Override
130: public void varDumpImpl(Env env, WriteStream out, int depth,
131: IdentityHashMap<Value, String> valueSet) throws IOException {
132: out.print(getClass().getName());
133: out.print('[');
134: out.print(_methodName);
135: out.print(']');
136: }
137:
138: // XXX: just a placeholder, need real implementation here
139: @Override
140: public boolean isValid() {
141: return true;
142: }
143:
144: @Override
145: public String getCallbackName() {
146: return _methodName;
147: }
148:
149: @Override
150: public boolean isInternal() {
151: return _fun instanceof JavaInvoker;
152: }
153: }
|