KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > IReportHashMapBean


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportHashMapBean.java
28  *
29  * Created on March 8, 2006, 2:23 PM
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import java.util.HashMap JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 /**
39  *
40  * @author gtoffoli
41  */

42 public class IReportHashMapBean implements Cloneable JavaDoc {
43     
44     private HashMap JavaDoc beanProperties = new HashMap JavaDoc();
45     
46     /** Creates a new instance of IReportDynamicBean */
47     public IReportHashMapBean() {
48     }
49
50     public HashMap JavaDoc getBeanProperties() {
51         return beanProperties;
52     }
53
54     public void setBeanProperties(HashMap JavaDoc beanProperties) {
55         this.beanProperties = beanProperties;
56     }
57     
58     /** Create a object copy */
59     public Object JavaDoc clone()
60     {
61             IReportHashMapBean newBean = new IReportHashMapBean();
62             return clone(newBean);
63     }
64     
65     /** this method copies all properties of this objects into newBean attibutes */
66     public Object JavaDoc clone(IReportHashMapBean newBean)
67     {
68             Iterator JavaDoc i_keys = getBeanProperties().keySet().iterator();
69
70             while (i_keys.hasNext())
71             {
72                 Object JavaDoc key = i_keys.next();
73                 newBean.getBeanProperties().put(key,getBeanProperties().get(key));
74             }
75
76             return newBean;
77     }
78         
79     /**
80      * Look for property in the map. The value must be true or false.
81      * If the property is not found, the defaultValue is returned.
82      */

83     public boolean getBooleanValue(String JavaDoc property, boolean defaultValue)
84     {
85         Object JavaDoc prop = getBeanProperties().get(property);
86         if (prop == null) return defaultValue;
87         return Boolean.valueOf( prop.toString() ).booleanValue();
88     }
89     
90     /**
91      * Look for property in the map.
92      * If the property is not found, the defaultValue is returned.
93      */

94     public String JavaDoc getStringValue(String JavaDoc property, String JavaDoc defaultValue)
95     {
96         Object JavaDoc prop = getBeanProperties().get(property);
97         if (prop == null) return defaultValue;
98         return prop.toString();
99     }
100     
101     /**
102      * Look for property in the map. The value must be a Color object.
103      * If the property is not found, the defaultValue is returned.
104      */

105     public java.awt.Color JavaDoc getColorValue(String JavaDoc property, java.awt.Color JavaDoc defaultValue)
106     {
107         Object JavaDoc prop = getBeanProperties().get(property);
108         if (prop == null || !(prop instanceof java.awt.Color JavaDoc)) return defaultValue;
109         return (java.awt.Color JavaDoc)prop;
110     }
111     
112     /**
113      * Look for property in the map. The value must rapresent a valid number.
114      * If the property is not found, the defaultValue is returned.
115      *
116      * If the number is not valid, a NumberFormatException is thrown
117      */

118     public int getIntValue(String JavaDoc property, int defaultValue)
119     {
120         Object JavaDoc prop = getBeanProperties().get(property);
121         if (prop == null) return defaultValue;
122         try {
123         return Integer.valueOf( prop.toString() ).intValue();
124         } catch (Exception JavaDoc ex)
125         {
126             getBeanProperties().remove(property);
127             return defaultValue;
128         }
129     }
130     
131     /**
132      * Shurtcut for getBeanProperties().put(property, value)
133      *
134      * If property is null, the method does nothing
135      */

136     public void setPropertyValue(String JavaDoc property, Object JavaDoc value)
137     {
138         if (property == null) return;
139         getBeanProperties().put(property,value);
140     }
141     
142     /**
143      * Shurtcut for getBeanProperties().get(property)
144      *
145      * If property is null, the method return null
146      */

147     public Object JavaDoc getPropertyValue(String JavaDoc property)
148     {
149         if (property == null) return null;
150         return getBeanProperties().get(property);
151     }
152     
153     /**
154      * Look for property in the map. The value must rapresent a valid number.
155      * If the property is not found, the defaultValue is returned.
156      *
157      * If the number is not valid, a NumberFormatException is thrown
158      */

159     public int getDoubleValue(String JavaDoc property, int defaultValue)
160     {
161         Object JavaDoc prop = getBeanProperties().get(property);
162         if (prop == null) return defaultValue;
163         return Integer.valueOf( prop.toString() ).intValue();
164     }
165     
166 }
167
Popular Tags