01: package jsint;
02:
03: import java.lang.reflect.Constructor;
04:
05: /** Provides dynamic constructors.
06: * @author Peter Norvig, Copyright 1998, peter@norvig.com, <a href="license.txt">license</a>
07: * subsequently modified by Jscheme project members
08: * licensed under zlib licence (see license.txt)
09: **/
10:
11: public class JavaConstructor extends StaticReflector {
12:
13: private transient Object[] methods;
14:
15: /** Depricated! **/
16: public JavaConstructor(Class c) {
17: this (c.getName());
18: }
19:
20: public JavaConstructor(String c, boolean isPrivileged) {
21: this .name = c;
22: this .isPrivileged = isPrivileged;
23: this .reset();
24: }
25:
26: public JavaConstructor(String c) {
27: this (c, false);
28: }
29:
30: public Object apply(Object[] args) {
31: return Invoke.invokeRawConstructor(((Constructor) Invoke
32: .findMethod(methods, args)), args);
33: }
34:
35: protected synchronized void reset() {
36: methods = Invoke.constructorTable(name, isPrivileged);
37:
38: int min = Integer.MAX_VALUE;
39: int max = 0;
40:
41: for (int i = 0; i < methods.length; i = i + Invoke.BUCKET_SIZE) {
42: int n = ((Object[]) methods[i]).length;
43: if (n < min)
44: min = n;
45: if (n > max)
46: max = n;
47: }
48: minArgs = min;
49: maxArgs = max;
50: }
51:
52: /** Code is like (vector Hashtable. 10), ie the first element is the
53: Constructor. **/
54: }
|