KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > MethodBinder


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 jfun.yan.util.ReflectionUtil;
18
19 /**
20  * For statically resolved method.
21  * <p>
22  * Zephyr Business Solution
23  *
24  * @author Ben Yu
25  *
26  */

27 final class MethodBinder implements ComponentBinder {
28   public Verifiable verify(Class JavaDoc type) {
29     final Class JavaDoc expecting = mtd.getMethod().getDeclaringClass();
30     if(!ReflectionUtil.isAssignableFrom(
31         expecting, type)
32     ){
33       throw new TypeMismatchException(expecting, type,
34           "type mismatch for invocation target");
35     }
36     return Components.fun(Functions.method(null, mtd.getMethod()));
37   }
38   public Creator bind(Object JavaDoc v){
39     return Components.fun(Functions.method(v, mtd.getMethod()));
40   }
41   public Class JavaDoc bindType(Class JavaDoc t){
42     return mtd.getMethod().getReturnType();
43   }
44   private final jfun.util.SerializableMethod mtd;
45   MethodBinder(final java.lang.reflect.Method JavaDoc mtd) {
46     this.mtd = new jfun.util.SerializableMethod(mtd);
47   }
48   
49   public boolean equals(Object JavaDoc obj) {
50     if(obj instanceof MethodBinder){
51       final MethodBinder other = (MethodBinder)obj;
52       return mtd.equals(other.mtd);
53     }
54     else return false;
55   }
56   public int hashCode() {
57     return mtd.hashCode();
58   }
59   public String JavaDoc toString() {
60     return mtd.toString();
61   }
62 }
63
Popular Tags