KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > IndexedPropertyWriter


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  * Zephyr Business Solution
21  *
22  * @author Ben Yu
23  *
24  */

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