001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * IReportHashMapBean.java
028: *
029: * Created on March 8, 2006, 2:23 PM
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import java.util.HashMap;
036: import java.util.Iterator;
037:
038: /**
039: *
040: * @author gtoffoli
041: */
042: public class IReportHashMapBean implements Cloneable {
043:
044: private HashMap beanProperties = new HashMap();
045:
046: /** Creates a new instance of IReportDynamicBean */
047: public IReportHashMapBean() {
048: }
049:
050: public HashMap getBeanProperties() {
051: return beanProperties;
052: }
053:
054: public void setBeanProperties(HashMap beanProperties) {
055: this .beanProperties = beanProperties;
056: }
057:
058: /** Create a object copy */
059: public Object clone() {
060: IReportHashMapBean newBean = new IReportHashMapBean();
061: return clone(newBean);
062: }
063:
064: /** this method copies all properties of this objects into newBean attibutes */
065: public Object clone(IReportHashMapBean newBean) {
066: Iterator i_keys = getBeanProperties().keySet().iterator();
067:
068: while (i_keys.hasNext()) {
069: Object key = i_keys.next();
070: newBean.getBeanProperties().put(key,
071: getBeanProperties().get(key));
072: }
073:
074: return newBean;
075: }
076:
077: /**
078: * Look for property in the map. The value must be true or false.
079: * If the property is not found, the defaultValue is returned.
080: */
081: public boolean getBooleanValue(String property, boolean defaultValue) {
082: Object prop = getBeanProperties().get(property);
083: if (prop == null)
084: return defaultValue;
085: return Boolean.valueOf(prop.toString()).booleanValue();
086: }
087:
088: /**
089: * Look for property in the map.
090: * If the property is not found, the defaultValue is returned.
091: */
092: public String getStringValue(String property, String defaultValue) {
093: Object prop = getBeanProperties().get(property);
094: if (prop == null)
095: return defaultValue;
096: return prop.toString();
097: }
098:
099: /**
100: * Look for property in the map. The value must be a Color object.
101: * If the property is not found, the defaultValue is returned.
102: */
103: public java.awt.Color getColorValue(String property,
104: java.awt.Color defaultValue) {
105: Object prop = getBeanProperties().get(property);
106: if (prop == null || !(prop instanceof java.awt.Color))
107: return defaultValue;
108: return (java.awt.Color) prop;
109: }
110:
111: /**
112: * Look for property in the map. The value must rapresent a valid number.
113: * If the property is not found, the defaultValue is returned.
114: *
115: * If the number is not valid, a NumberFormatException is thrown
116: */
117: public int getIntValue(String property, int defaultValue) {
118: Object prop = getBeanProperties().get(property);
119: if (prop == null)
120: return defaultValue;
121: try {
122: return Integer.valueOf(prop.toString()).intValue();
123: } catch (Exception ex) {
124: getBeanProperties().remove(property);
125: return defaultValue;
126: }
127: }
128:
129: /**
130: * Shurtcut for getBeanProperties().put(property, value)
131: *
132: * If property is null, the method does nothing
133: */
134: public void setPropertyValue(String property, Object value) {
135: if (property == null)
136: return;
137: getBeanProperties().put(property, value);
138: }
139:
140: /**
141: * Shurtcut for getBeanProperties().get(property)
142: *
143: * If property is null, the method return null
144: */
145: public Object getPropertyValue(String property) {
146: if (property == null)
147: return null;
148: return getBeanProperties().get(property);
149: }
150:
151: /**
152: * Look for property in the map. The value must rapresent a valid number.
153: * If the property is not found, the defaultValue is returned.
154: *
155: * If the number is not valid, a NumberFormatException is thrown
156: */
157: public int getDoubleValue(String property, int defaultValue) {
158: Object prop = getBeanProperties().get(property);
159: if (prop == null)
160: return defaultValue;
161: return Integer.valueOf(prop.toString()).intValue();
162: }
163:
164: }
|