KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > kernel > digester > ComponentConfig


1 package com.jcorporate.expresso.kernel.digester;
2
3 /* ====================================================================
4  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
5  *
6  * Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by Jcorporate Ltd.
23  * (http://www.jcorporate.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. "Jcorporate" and product names such as "Expresso" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written permission,
30  * please contact info@jcorporate.com.
31  *
32  * 5. Products derived from this software may not be called "Expresso",
33  * or other Jcorporate product names; nor may "Expresso" or other
34  * Jcorporate product names appear in their name, without prior
35  * written permission of Jcorporate Ltd.
36  *
37  * 6. No product derived from this software may compete in the same
38  * market space, i.e. framework, without prior written permission
39  * of Jcorporate Ltd. For written permission, please contact
40  * partners@jcorporate.com.
41  *
42  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
46  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
48  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
52  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53  * SUCH DAMAGE.
54  * ====================================================================
55  *
56  * This software consists of voluntary contributions made by many
57  * individuals on behalf of the Jcorporate Ltd. Contributions back
58  * to the project(s) are encouraged when you make modifications.
59  * Please send them to support@jcorporate.com. For more information
60  * on Jcorporate Ltd. and its products, please see
61  * <http://www.jcorporate.com/>.
62  *
63  * Portions of this software are based upon other open source
64  * products and are subject to their respective licenses.
65  */

66
67 import java.util.ArrayList JavaDoc;
68 import java.util.Collections JavaDoc;
69 import java.util.HashMap JavaDoc;
70 import java.util.Iterator JavaDoc;
71 import java.util.Map JavaDoc;
72
73 /**
74  * This class represents the configuration of a component as parsed from the
75  * xxpresso-services.xml file. It is set by the Digester that fills it.
76  * <p>This is different from the ConfigurationBean used in the kernel package in
77  * that all data is string based. It is up to the system factory to convert the string
78  * data to the appropriate data type as specified by the component's metadata</p>
79  *
80  * @author Michael Rimov
81  */

82 public class ComponentConfig implements java.io.Serializable JavaDoc {
83
84     private String JavaDoc name;
85     private String JavaDoc className;
86     private Map JavaDoc properties;
87     private Map JavaDoc indexedProperties;
88     private Map JavaDoc mappedProperties;
89
90     private ArrayList JavaDoc childComponents;
91
92     /**
93      * Default initialization system.
94      */

95     public ComponentConfig() {
96         name = null;
97         className = null;
98         properties = new HashMap JavaDoc();
99         childComponents = new ArrayList JavaDoc();
100         indexedProperties = new HashMap JavaDoc();
101         mappedProperties = new HashMap JavaDoc();
102     }
103
104     /**
105      * Retrieve the name of the component
106      *
107      * @return java.lang.String
108      */

109     public String JavaDoc getName() {
110         return name;
111     }
112
113     /**
114      * Sets the name of the component
115      *
116      * @param name java.lang.String
117      */

118     public void setName(String JavaDoc name) {
119         this.name = name;
120     }
121
122     /**
123      * Sets the classname for this component
124      *
125      * @param className java.lang.String (Should be a valid class)
126      */

127     public void setClassName(String JavaDoc className) {
128         this.className = className;
129     }
130
131     /**
132      * Retrieve the classname for this component.
133      *
134      * @return java.lang.String
135      */

136     public String JavaDoc getClassName() {
137         return className;
138     }
139
140     /**
141      * Add a property for the component
142      *
143      * @param name the name of the property
144      * @param value the value of the named property.
145      */

146     public void addProperty(String JavaDoc name, String JavaDoc value) {
147         properties.put(name, value);
148     }
149
150     /**
151      * Add a mapped property.
152      *
153      * @param name the name of the mapped property
154      * @param key the property key
155      * @param value the value of the key
156      */

157     public void addMappedProperty(String JavaDoc name, String JavaDoc key, String JavaDoc value) {
158         if (mappedProperties == null) {
159             mappedProperties = new HashMap JavaDoc();
160         }
161
162         if (!mappedProperties.containsKey(name)) {
163             mappedProperties.put(name, new HashMap JavaDoc());
164         }
165
166         Map JavaDoc keyedProperties = (Map JavaDoc) mappedProperties.get(name);
167         keyedProperties.put(key, value);
168
169     }
170
171     /**
172      * Add an indexed property (often seen in the javabean world as arrays)
173      *
174      * @param name the name of the property
175      * @param index the index of the property
176      * @param value the value of the property at the given index.
177      */

178     public void addIndexedProperty(String JavaDoc name, int index, String JavaDoc value) {
179         if (indexedProperties == null) {
180             indexedProperties = new HashMap JavaDoc();
181         }
182
183         if (!indexedProperties.containsKey(name)) {
184             HashMap JavaDoc internalArray = new HashMap JavaDoc(index);
185             indexedProperties.put(name, internalArray);
186         }
187
188         Map JavaDoc indexKeyMap = (Map JavaDoc) indexedProperties.get(name);
189         indexKeyMap.put(new Integer JavaDoc(index), value);
190
191     }
192
193     /**
194      * Retrieve the value of a property
195      *
196      * @param name the name of the property
197      * @return java.lang.String
198      */

199     public String JavaDoc getProperty(String JavaDoc name) {
200         return (String JavaDoc) properties.get(name);
201     }
202
203     /**
204      * Sets the value of a particular property
205      *
206      * @param name the name of the property
207      * @param value the value of the property.
208      */

209     public void setProperty(String JavaDoc name, String JavaDoc value) {
210         if (properties == null) {
211             properties = new HashMap JavaDoc();
212         }
213         properties.put(name, value);
214     }
215
216     /**
217      * Retrieve the value of a mapped property
218      *
219      * @param name the property name
220      * @param key the key in the mapped property
221      * @return java.lang.String the actual property value
222      */

223     public String JavaDoc getMappedProperty(String JavaDoc name, String JavaDoc key) {
224         if (mappedProperties == null) {
225             return null;
226         }
227
228         Map JavaDoc oneMapped = (Map JavaDoc) mappedProperties.get(name);
229         if (oneMapped == null) {
230             return null;
231         } else {
232             return (String JavaDoc) oneMapped.get(key);
233         }
234     }
235
236     /**
237      * Sets an mapped property value.
238      *
239      * @param key The property name
240      * @param name the name of the property
241      * @param value the value for the property.
242      */

243     public void setMappedProperty(String JavaDoc key, String JavaDoc name, String JavaDoc value) {
244         if (mappedProperties == null) {
245             mappedProperties = new HashMap JavaDoc();
246         }
247
248         Map JavaDoc oneProperty = (Map JavaDoc) mappedProperties.get(key);
249         if (oneProperty == null) {
250             oneProperty = new HashMap JavaDoc();
251             mappedProperties.put(key, oneProperty);
252         }
253
254         oneProperty.put(name, value);
255     }
256
257
258     /**
259      * Retrieve all mapped property key/value pairs for a given property name
260      *
261      * @param name the name of the property
262      * @return String:String Map that corresponds to all mapped values for this
263      * given property
264      */

265     public Map JavaDoc getMappedProperties(String JavaDoc name) {
266         if (mappedProperties == null) {
267             return null;
268         }
269
270         return (Map JavaDoc) mappedProperties.get(name);
271     }
272
273     /**
274      * <p>Retrieve a map of all mapped properties. All objects in the map are Strings
275      * and are the format:</p>
276      * <p>Map keyed by property names</p>
277      * <p>&nbsp;&nbsp;Map for each property name keyed by 'key'</p>
278      * <p>&nbsp;&nbsp;&nbsp;&nbsp;The actual property values</p>
279      *
280      * @return java.util.Map
281      */

282     public Map JavaDoc getAllMappedProperties() {
283         return mappedProperties;
284     }
285
286     /**
287      * Retrieve a map of index properties. The keys in the map correspond to
288      * the indexes in a typical array as they are used in a javabean.
289      *
290      * @param name the name of the property to retrieve
291      * @return java.util.Map keyed by java.lang.Integer
292      */

293     public Map JavaDoc getIndexedProperties(String JavaDoc name) {
294         if (indexedProperties == null) {
295             return null;
296         } else {
297             return (Map JavaDoc) indexedProperties.get(name);
298         }
299     }
300
301     /**
302      * Retrieve a map of all indexed properties. The map is keyed by strings which in
303      * turn point to maps that are keyed by Integers representing the array
304      * indexes for each property name.
305      *
306      * @return java.util.Map
307      */

308     public Map JavaDoc getAllIndexedProperties() {
309         return indexedProperties;
310     }
311
312     /**
313      * Retrieve a particular indexed property.
314      *
315      * @param key the property name
316      * @param index the index of the property who's value we wish to retrieve
317      * @return java.lang.String
318      */

319     public String JavaDoc getIndexedProperty(String JavaDoc key, int index) {
320         Map