KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > ComponentInfo


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 Jun 27, 2005
11  *
12  * Author Michelle Lei
13  * ZBS
14  */

15 package jfun.yan;
16
17 import java.util.Map JavaDoc;
18
19 /**
20  * This class contains meta information about any component.
21  * <p>
22  * Zephyr Business Solution
23  *
24  * @author Michelle Lei
25  *
26  */

27 public class ComponentInfo {
28   private final int num_params;
29   private final Map props;
30   private final Map params;
31   private final Class JavaDoc rtype;
32   
33   /**
34    * Creates a ComponentInfo object.
35    * @param num_params the number of parameters.
36    * @param params the map of the parameters.
37    * @param props the map of the propertyes.
38    * @param rtype the component type.
39    */

40   public ComponentInfo(final int num_params, final Map params, final Map props,
41       final Class JavaDoc rtype) {
42     this.num_params = num_params;
43     this.props = props;
44     this.params = params;
45     this.rtype = rtype;
46   }
47   /**
48    * Get the total number of parameters.
49    * This number is determined by the maximal ordinal position of the expected
50    * parameters.
51    * It may be different than getParameters().size() because certain parameter
52    * may not be expected. For example, a component may only expect parameters
53    * of ordinal position (0, 2, 3) with parameter 1 ignored.
54    * @return the total number of parameters.
55    */

56   public int getParameterCount() {
57     return num_params;
58   }
59   /**
60    * Get the parameters.
61    * @return a Map with the ordinal position as key and the parameter type as
62    * value.
63    */

64   public Map getParameters() {
65     return params;
66   }
67   /**
68    * Get the properties.
69    * @return a Map with the property type as value.
70    */

71   public Map getProperties() {
72     return props;
73   }
74   /**
75    * Get the property type.
76    * @return the property type.
77    */

78   public Class JavaDoc getComponentType(){
79     return rtype;
80   }
81   
82   public boolean equals(Object JavaDoc obj) {
83     if(obj instanceof ComponentInfo){
84       final ComponentInfo other = (ComponentInfo)obj;
85       return num_params==other.num_params && rtype.equals(other.rtype)
86         && params.equals(other.params) && props.equals(other.props);
87     }
88     else return false;
89   }
90   public int hashCode() {
91     return hcode(rtype)+31*(hcode(params)+31*hcode(props));
92   }
93   public String JavaDoc toString() {
94     return "type = " + jfun.util.Misc.getTypeName(rtype) + "\n"
95       + "parameters = " + params + "\n"
96       + "properties = " + props;
97   }
98   private int hcode(Object JavaDoc obj){
99     return (obj==null)?0:obj.hashCode();
100   }
101 }
102
Popular Tags