01: /*
02: * @(#)makeProxy.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import pnuts.lang.Context;
12: import pnuts.lang.PnutsFunction;
13: import pnuts.compiler.DynamicRuntime;
14: import java.lang.reflect.Method;
15: import java.lang.reflect.Constructor;
16:
17: public class makeProxy extends PnutsFunction {
18:
19: public makeProxy() {
20: super ("makeProxy");
21: }
22:
23: public boolean defined(int nargs) {
24: return nargs == 1;
25: }
26:
27: protected Object exec(Object[] args, Context context) {
28: if (args.length != 1) {
29: undefined(args, context);
30: return null;
31: }
32: Object target = args[0];
33: if (target instanceof Method) {
34: return DynamicRuntime.makeProxy((Method) target);
35: } else if (target instanceof Constructor) {
36: return DynamicRuntime.makeProxy((Constructor) target);
37: } else {
38: throw new IllegalArgumentException(String.valueOf(target));
39: }
40: }
41:
42: public String toString() {
43: return "function makeProxy(methodOrConstructor)";
44: }
45: }
|