KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > kernel > internal > DefaultConfigBean


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

64 package com.jcorporate.expresso.kernel.internal;
65
66 import com.jcorporate.expresso.kernel.Configuration;
67
68 import java.util.ArrayList JavaDoc;
69 import java.util.HashMap JavaDoc;
70 import java.util.Iterator JavaDoc;
71 import java.util.Map JavaDoc;
72 import java.util.TreeMap JavaDoc;
73
74
75 /**
76  * This class represents a default implementation of the Configuration interface.
77  * Is is used internally by the SystemFactory to load all the configuration values
78  * to be distributed to the Components for configuration. Those wishing to change the
79  * underlying class should create their own System factory
80  *
81  * @author Michael Rimov
82  * @version $Revision: 1.4 $ on $Date: 2004/11/17 20:48:17 $
83  * @since Expresso 5.1
84  */

85
86 public class DefaultConfigBean implements Configuration {
87     Map JavaDoc properties = null;
88
89     Map JavaDoc namedProperties = null;
90
91     Map JavaDoc indexedProperties = null;
92
93
94     public DefaultConfigBean() {
95     }
96
97     public Object JavaDoc get(String JavaDoc name) {
98         if (properties == null) {
99             return null;
100         } else {
101             return properties.get(name);
102         }
103     }
104
105     public Object JavaDoc get(String JavaDoc name, int index) {
106         if (indexedProperties == null) {
107             return null;
108         }
109
110         if (!indexedProperties.containsKey(name)) {
111             return null;
112         }
113
114         Map JavaDoc indexKeyMap = (Map JavaDoc) indexedProperties.get(name);
115         return indexKeyMap.get(new Integer JavaDoc(index));
116     }
117
118     /**
119      * Retrieve ALL the indexed properties defined by parameter name.
120      *
121      * @param name the name of the property
122      * @return java.util.List
123      */

124     public java.util.List JavaDoc getIndexedProperties(String JavaDoc name) {
125         if (indexedProperties == null) {
126             return null;
127         }
128
129         if (!indexedProperties.containsKey(name)) {
130             return null;
131         }
132
133         Map JavaDoc indexKeyMap = (Map JavaDoc) indexedProperties.get(name);
134         ArrayList JavaDoc returnValue = new ArrayList JavaDoc(indexKeyMap.size());
135
136         //
137
//The return value is sorted by index because it is actually stored
138
//in a sorted TreeMap.
139
//
140
/**
141          * @todo What do we do about skipped index numbers in the array??
142          * Right now we're just compacting it to the smallest representation,
143          * but other than that....
144          */

145         for (Iterator JavaDoc i = indexKeyMap.keySet().iterator(); i.hasNext();) {
146             Integer JavaDoc key = (Integer JavaDoc) i.next();
147             returnValue.add(indexKeyMap.get(key));
148         }
149
150         return null;
151     }
152
153
154     public Object JavaDoc get(String JavaDoc name, String JavaDoc key) {
155         if (namedProperties == null) {
156             return null;
157         } else {
158             Map JavaDoc keyedProperties = (Map JavaDoc) namedProperties.get(name);
159             if (keyedProperties == null) {
160                 return null;
161             } else {
162                 return keyedProperties.get(key);
163             }
164         }
165     }
166
167     /**
168      * Retrieved all the mapped properties defined by name
169      *
170      * @param name the name of the mapped properties to retrieve
171      * @return java.util.Map of all properties keyed by the property key.
172      */

173     public java.util.Map JavaDoc getMappedProperties(String JavaDoc name) {
174         if (namedProperties == null) {
175             return null;
176         }
177
178         return (Map JavaDoc) namedProperties.get(name);
179     }
180
181
182     public boolean contains(String JavaDoc name, String JavaDoc key) {
183         if (namedProperties == null) {
184             return false;
185         } else {
186             Map JavaDoc keyedProperties = (Map JavaDoc) namedProperties.get(name);
187             if (keyedProperties == null) {
188                 return false;
189             } else {
190                 return keyedProperties.containsKey(key);
191             }
192         }
193     }
194
195     public void set(String JavaDoc name, Object JavaDoc o) {
196         if (properties == null) {
197             properties = new HashMap JavaDoc();
198         }
199         properties.put(name, o);
200
201     }
202
203     public void set(String JavaDoc name, int index, Object JavaDoc o) {
204         if (indexedProperties == null) {
205             indexedProperties = new HashMap JavaDoc();
206         }
207
208         if (!indexedProperties.containsKey(name)) {
209             Map JavaDoc internalArray = new TreeMap JavaDoc();
210             indexedProperties.put(name, internalArray);
211         }
212
213         Map JavaDoc indexKeyMap = (Map JavaDoc) indexedProperties.get(name);
214         indexKeyMap.put(new Integer JavaDoc(index), o);
215     }
216
217     public void set(String JavaDoc name, String JavaDoc key, Object JavaDoc o) {
218         if (namedProperties == null) {
219             namedProperties = new HashMap JavaDoc();
220         }
221
222         if (!namedProperties.containsKey(name)) {
223             namedProperties.put(name, new HashMap JavaDoc());
224         }
225
226         Map JavaDoc keyedProperties = (Map JavaDoc) namedProperties.get(name);
227         keyedProperties.put(key, o);
228     }
229
230 }
Popular Tags