001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine;
029:
030: import java.io.Serializable;
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.List;
034: import java.util.Map;
035:
036: /**
037: * Properties map of an JR element.
038: * <p/>
039: * The order of the properties (obtained by {@link #getPropertyNames() getPropertyNames()}
040: * is the same as the order in which the properties were added.
041: *
042: * @author Lucian Chirita (lucianc@users.sourceforge.net)
043: * @version $Id: JRPropertiesMap.java 1832 2007-08-24 15:41:50Z teodord $
044: */
045: public class JRPropertiesMap implements Serializable {
046: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
047:
048: private final Map propertiesMap;
049: private final List propertiesList;
050:
051: /**
052: * Creates a properties map.
053: */
054: public JRPropertiesMap() {
055: propertiesMap = new HashMap();
056: propertiesList = new ArrayList();
057: }
058:
059: /**
060: * Clones a properties map.
061: *
062: * @param propertiesMap the original properties map
063: */
064: public JRPropertiesMap(JRPropertiesMap propertiesMap) {
065: this ();
066:
067: String[] propertyNames = propertiesMap.getPropertyNames();
068: if (propertyNames != null && propertyNames.length > 0) {
069: for (int i = 0; i < propertyNames.length; i++) {
070: setProperty(propertyNames[i], propertiesMap
071: .getProperty(propertyNames[i]));
072: }
073: }
074: }
075:
076: /**
077: * Returns the names of the properties.
078: *
079: * @return the names of the properties
080: */
081: public String[] getPropertyNames() {
082: return (String[]) propertiesList
083: .toArray(new String[propertiesList.size()]);
084: }
085:
086: /**
087: * Returns the value of a property.
088: *
089: * @param propName the name of the property
090: * @return the value
091: */
092: public String getProperty(String propName) {
093: return (String) propertiesMap.get(propName);
094: }
095:
096: /**
097: * Adds/sets a property value.
098: *
099: * @param propName the name of the property
100: * @param value the value of the property
101: */
102: public void setProperty(String propName, String value) {
103: if (!propertiesMap.containsKey(propName)) {
104: propertiesList.add(propName);
105: }
106: propertiesMap.put(propName, value);
107: }
108:
109: /**
110: * Removes a property.
111: *
112: * @param propName the property name
113: */
114: public void removeProperty(String propName) {
115: if (propertiesMap.containsKey(propName)) {
116: propertiesList.remove(propName);
117: propertiesMap.remove(propName);
118: }
119: }
120:
121: /**
122: * Clones this property map.
123: *
124: * @return a clone of this property map
125: */
126: public JRPropertiesMap cloneProperties() {
127: return new JRPropertiesMap(this );
128: }
129:
130: public String toString() {
131: return propertiesMap.toString();
132: }
133: }
|