KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > configuration > PropertiesEl


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.configuration;
17
18 import scriptella.util.PropertiesMap;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Map JavaDoc;
24
25
26 /**
27  * TODO: Add documentation
28  *
29  * @author Fyodor Kupolov
30  * @version 1.0
31  */

32 public class PropertiesEl extends XmlConfigurableBase {
33     Map<String JavaDoc, ?> map = Collections.emptyMap();
34
35     public PropertiesEl() {
36     }
37
38     public PropertiesEl(XmlElement element) {
39         configure(element);
40     }
41
42     public void configure(final XmlElement element) {
43         if (element == null) {
44             return; //Properties is not a mandatory element
45
}
46         //optimization: if properties is empty - do not perform any additional steps
47
if (element.getElement().hasChildNodes()) {
48             PropertiesMap p = new PropertiesMap();
49             ContentEl content = new ContentEl(element);
50             InputStream JavaDoc is = null;
51
52             try {
53                 is = new ReaderInputStream(content.open());
54                 p.load(is);
55                 map = p;
56             } catch (Exception JavaDoc e) {
57                 throw new ConfigurationException("Unable to load properties", e,
58                         element);
59             } finally {
60                 if (is != null) {
61                     try {
62                         is.close();
63                     } catch (IOException JavaDoc e) {
64                     }
65                 }
66             }
67         }
68     }
69
70     public Map<String JavaDoc, ?> getMap() {
71         return map;
72     }
73
74     public void setMap(Map<String JavaDoc, ?> map) {
75         this.map = new PropertiesMap(map);
76     }
77 }
78
Popular Tags