| 175 | } |
| 176 | |
| 177 | public Object invokeImpl( Object proxy, Method method, Object[] args ) |
| 178 | throws EvalError |
| 179 | { |
| 180 | String methodName = method.getName(); |
| 181 | CallStack callstack = new CallStack( namespace ); |
| 182 | |
| 183 | /* |
| 184 | If equals() is not explicitly defined we must override the |
| 185 | default implemented by the This object protocol for scripted |
| 186 | object. To support XThis equals() must test for equality with |
| 187 | the generated proxy object, not the scripted bsh This object; |
| 188 | otherwise callers from outside in Java will not see a the |
| 189 | proxy object as equal to itself. |
| 190 | */ |
| 191 | BshMethod equalsMethod = null; |
| 192 | try { |
| 193 | equalsMethod = namespace.getMethod( |
| 194 | "equals", new Class [] { Object.class } ); |
| 195 | } catch ( UtilEvalError e ) {/*leave null*/ } |
| 196 | if ( methodName.equals("equals" ) && equalsMethod == null ) { |
| 197 | Object obj = args[0]; |
| 198 | return proxy == obj; |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | If toString() is not explicitly defined override the default |
| 203 | to show the proxy interfaces. |
| 204 | */ |
| 205 | BshMethod toStringMethod = null; |
| 206 | try { |
| 207 | toStringMethod = |
| 208 | namespace.getMethod( "toString", new Class [] { } ); |
| 209 | } catch ( UtilEvalError e ) {/*leave null*/ } |
| 210 | |
| 211 | if ( methodName.equals("toString" ) && toStringMethod == null) |
| 212 | { |
| 213 | Class [] ints = proxy.getClass().getInterfaces(); |
| 214 | // XThis.this refers to the enclosing class instance |
| 215 | StringBuilder sb = new StringBuilder( |
| 216 | This.this.toString() + "\nimplements:" ); |
| 217 | for(int i=0; i<ints.length; i++) |
| 218 | sb.append( " "+ ints[i].getName() |
| 219 | + ((ints.length > 1)?",":"") ); |
| 220 | return sb.toString(); |
| 221 | } |
| 222 | |
| 223 | Class [] paramTypes = method.getParameterTypes(); |
| 224 | return Primitive.unwrap( |
| 225 | invokeMethod( methodName, Primitive.wrap(args, paramTypes) ) ); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | This( NameSpace namespace, Interpreter declaringInterpreter ) { |