KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > function > Property2Signature


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 Aug 9, 2005
11  *
12  * Author Ben Yu
13  * ZBS
14  */

15 package jfun.yan.function;
16
17 /**
18  * To adapt a Java Bean property description to a Signature object.
19  * <p>
20  * Zephyr Business Solution
21  *
22  * @author Ben Yu
23  *
24  */

25 public class Property2Signature implements Signature {
26   private final Class JavaDoc component_type;
27   private final Object JavaDoc key;
28   private final Class JavaDoc prop_type;
29   public Class JavaDoc getReturnType() {
30     return component_type;
31   }
32
33   public Class JavaDoc[] getParameterTypes() {
34     return new Class JavaDoc[]{prop_type};
35   }
36
37   public String JavaDoc getName() {
38     return ""+key;
39   }
40
41   /**
42    * To create a Property2Signature object.
43    * @param component_type the type of the java bean.
44    * @param key the property key.
45    * @param prop_type the property type.
46    */

47   public Property2Signature(Class JavaDoc component_type, Object JavaDoc key, Class JavaDoc prop_type) {
48     this.component_type = component_type;
49     this.key = key;
50     this.prop_type = prop_type;
51   }
52
53   public boolean equals(Object JavaDoc obj) {
54     if(obj instanceof Property2Signature){
55       final Property2Signature other = (Property2Signature)obj;
56       return component_type.equals(other.component_type)
57         && equals(key, other.key);
58     }
59     else return false;
60   }
61
62   public int hashCode() {
63     return (component_type.hashCode()*31+key.hashCode())*31;
64   }
65
66   public String JavaDoc toString() {
67     return component_type.getName()+"."+key+"("+prop_type.getName()+")";
68   }
69   private static int hcode(Object JavaDoc obj){
70     return obj==null?0:obj.hashCode();
71   }
72   private static boolean equals(Object JavaDoc a, Object JavaDoc b){
73     return a==null?b==null:a.equals(b);
74   }
75 }
76
Popular Tags