KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > PropertyWriter


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.function.Function;
18
19
20 /**
21  * Zephyr Business Solution
22  *
23  * @author Ben Yu
24  *
25  */

26 final class PropertyWriter implements Function {
27   private final jfun.util.beans.Bean bean;
28   private final String JavaDoc prop;
29   private final Class JavaDoc ptype;
30   PropertyWriter(final jfun.util.beans.Bean bean, final String JavaDoc prop) {
31     this.bean = bean;
32     this.prop = prop;
33     this.ptype = bean.getBeanType().getPropertySetterType(prop);
34   }
35   
36   public Object JavaDoc call(Object JavaDoc[] args) throws Throwable JavaDoc {
37     bean.setProperty(prop, args[0]);
38     return bean.getObject();
39   }
40   public Class JavaDoc[] getParameterTypes() {
41     return new Class JavaDoc[]{ptype};
42   }
43   public Class JavaDoc getReturnType() {
44     final Object JavaDoc obj = bean.getObject();
45     return obj==null?bean.getBeanType().getType():obj.getClass();
46   }
47   public boolean isConcrete(){
48     return bean.getObject()!=null;
49   }
50   public boolean equals(Object JavaDoc obj) {
51     if(obj instanceof PropertyWriter){
52       final PropertyWriter other = (PropertyWriter)obj;
53       return prop.equals(other.prop) && bean.equals(other.bean);
54     }
55     else return false;
56   }
57   public int hashCode() {
58     return bean.hashCode() * 31 + prop.hashCode();
59   }
60   public String JavaDoc toString() {
61     return bean.toString() + "." + prop +"";
62   }
63   public String JavaDoc getName(){
64     return prop;
65   }
66 }
67
Popular Tags