KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > DynamicMethodBinder


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solution. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8
9 /*
10  * Created on Apr 22, 2005
11  *
12  * Author Ben Yu
13  * ZBS
14  */

15 package jfun.yan;
16
17 import java.util.Arrays JavaDoc;
18
19 import jfun.util.Misc;
20
21 /**
22  * For specifying a method without knowing the actual type it is in.
23  * <p>
24  * Zephyr Business Solution
25  *
26  * @author Ben Yu
27  *
28  */

29 final class DynamicMethodBinder implements ComponentBinder {
30   /* method name */
31   private final String JavaDoc mname;
32   private final Class JavaDoc[] param_types;
33   private final boolean suppress_security;
34   private boolean isParameterless(){
35     return param_types==null || param_types.length==0;
36   }
37   DynamicMethodBinder(final String JavaDoc mname, final Class JavaDoc[] param_types,
38       boolean suppress_security) {
39     this.mname = mname;
40     this.param_types = param_types;
41     this.suppress_security = suppress_security;
42   }
43   
44   public Verifiable verify(Class JavaDoc type) {
45     return Components.fun(
46         Functions.method(type, null, mname, param_types, suppress_security)
47     );
48   }
49   public Creator bind(Object JavaDoc v){
50     return Components.fun(Functions.method(
51         v, mname, param_types, suppress_security
52       )
53     );
54   }
55   public Class JavaDoc bindType(Class JavaDoc t){
56     return null;
57   }
58   public boolean equals(Object JavaDoc obj) {
59     if(obj instanceof DynamicMethodBinder){
60       final DynamicMethodBinder other = (DynamicMethodBinder)obj;
61       if(!mname.equals(other.mname)) return false;
62       if(suppress_security!=other.suppress_security) return false;
63       if(isParameterless()) return other.isParameterless();
64       return Arrays.equals(param_types, other.param_types);
65     }
66     else return false;
67   }
68   public int hashCode() {
69     int hcode = mname.hashCode();
70     if(param_types==null) return hcode*31;
71     return 31*Misc.getArrayHashcode(param_types)+hcode;
72   }
73   public String JavaDoc toString() {
74     return mname+jfun.yan.util.Utils.toString(param_types);
75   }
76 }
77
Popular Tags