KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > FieldBinder


1 package jfun.yan;
2
3 import jfun.yan.util.ReflectionUtil;
4
5 /**
6  * For statically resolved field.
7  * <p>
8  * Zephyr Business Solution
9  *
10  * @author Ben Yu
11  *
12  */

13 final class FieldBinder implements ComponentBinder {
14   public Verifiable verify(Class JavaDoc type) {
15     final Class JavaDoc expecting = fld.getField().getDeclaringClass();
16     if(!ReflectionUtil.isAssignableFrom(
17         expecting, type)
18     ){
19       throw new TypeMismatchException(expecting, type,
20           "type mismatch for invocation target");
21     }
22     return Components.fun(Functions.field(null, fld.getField()));
23   }
24   public Creator bind(Object JavaDoc v){
25     return Components.fun(Functions.field(v, fld.getField()));
26   }
27   public Class JavaDoc bindType(Class JavaDoc t){
28     return fld.getField().getType();
29   }
30   private final jfun.util.SerializableField fld;
31   FieldBinder(final java.lang.reflect.Field JavaDoc fld) {
32     this.fld = new jfun.util.SerializableField(fld);
33   }
34   
35   public boolean equals(Object JavaDoc obj) {
36     if(obj instanceof FieldBinder){
37       final FieldBinder other = (FieldBinder)obj;
38       return fld.equals(other.fld);
39     }
40     else return false;
41   }
42   public int hashCode() {
43     return fld.hashCode();
44   }
45   public String JavaDoc toString() {
46     return fld.toString();
47   }
48 }
Popular Tags