KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JRPropertiesMap


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine;
29
30 import java.io.Serializable JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import org.apache.commons.collections.SequencedHashMap;
35
36 /**
37  * Properties map of an JR element.
38  * <p/>
39  * The order of the properties (obtained by {@link #getPropertyNames() getPropertyNames()}
40  * is the same as the order in which the properties were added.
41  *
42  * @author Lucian Chirita (lucianc@users.sourceforge.net)
43  * @version $Id: JRPropertiesMap.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
44  */

45 public class JRPropertiesMap implements Serializable JavaDoc
46 {
47     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
48     
49     private final Map JavaDoc propertiesMap;
50     
51     
52     /**
53      * Creates a properties map.
54      */

55     public JRPropertiesMap()
56     {
57         propertiesMap = new SequencedHashMap();
58     }
59
60     
61     /**
62      * Clones a properties map.
63      *
64      * @param propertiesMap the original properties map
65      */

66     public JRPropertiesMap(JRPropertiesMap propertiesMap)
67     {
68         this.propertiesMap = new SequencedHashMap();
69         
70         String JavaDoc[] propertyNames = propertiesMap.getPropertyNames();
71         if (propertyNames != null && propertyNames.length > 0)
72         {
73             for(int i = 0; i < propertyNames.length; i++)
74             {
75                 setProperty(propertyNames[i], propertiesMap.getProperty(propertyNames[i]));
76             }
77         }
78     }
79
80     
81     /**
82      * Returns the names of the properties.
83      *
84      * @return the names of the properties
85      */

86     public String JavaDoc[] getPropertyNames()
87     {
88         Set JavaDoc names = propertiesMap.keySet();
89         String JavaDoc[] namesArray = new String JavaDoc[names.size()];
90         return (String JavaDoc[]) names.toArray(namesArray);
91     }
92
93     
94     /**
95      * Returns the value of a property.
96      *
97      * @param propName the name of the property
98      * @return the value
99      */

100     public String JavaDoc getProperty(String JavaDoc propName)
101     {
102         return (String JavaDoc)propertiesMap.get(propName);
103     }
104
105     
106     /**
107      * Adds/sets a property value.
108      *
109      * @param propName the name of the property
110      * @param value the value of the property
111      */

112     public void setProperty(String JavaDoc propName, String JavaDoc value)
113     {
114         propertiesMap.put(propName, value);
115     }
116     
117     
118     /**
119      * Removes a property.
120      *
121      * @param propName the property name
122      */

123     public void removeProperty(String JavaDoc propName)
124     {
125         propertiesMap.remove(propName);
126     }
127 }
128
Popular Tags