KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > alert > AlertSystemConfig


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.alert;
15
16 import org.jdom.input.SAXBuilder;
17 import org.jdom.Document;
18 import org.jdom.Element;
19 import org.jdom.JDOMException;
20 import org.jmanage.core.util.CoreUtils;
21
22 import java.util.List JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.io.File JavaDoc;
26
27 /**
28  * Contains the configuration for the Alerts sub-system. The Alerts sub-system
29  * can be configured using alert-config.xml file.
30  *
31  * Date: Aug 2, 2005
32  * @author Rakesh Kalra
33  */

34 public class AlertSystemConfig {
35
36     private static final String JavaDoc ALERT_CONFIG_FILE = CoreUtils.getConfigDir() +
37             File.separator +
38             "system" +
39             File.separator +
40             "alert-config.xml";
41
42     private static final AlertSystemConfig instance = new AlertSystemConfig();
43
44     public static AlertSystemConfig getInstance(){
45         return instance;
46     }
47
48     // list of DeliveryType objects
49
private List JavaDoc deliveryTypes = new LinkedList JavaDoc();
50
51
52     private AlertSystemConfig(){
53         init();
54     }
55
56     private void init(){
57         Document config = null;
58
59         try {
60             config = new SAXBuilder().build(ALERT_CONFIG_FILE);
61         } catch (JDOMException e) {
62             throw new RuntimeException JavaDoc();
63         }
64
65         Element deliveryTypesElement =
66                 config.getRootElement().getChild("deliveryTypes");
67         assert deliveryTypesElement != null;
68         for(Iterator JavaDoc it=deliveryTypesElement.getChildren("delivery").iterator();
69                 it.hasNext(); ){
70             Element deliveryType = (Element)it.next();
71             deliveryTypes.add(
72                     new DeliveryType(deliveryType.getAttributeValue("type"),
73                             deliveryType.getAttributeValue("className")));
74         }
75     }
76
77     public List JavaDoc getDeliveryTypes(){
78         return deliveryTypes;
79     }
80
81     public static class DeliveryType {
82         private final String JavaDoc type;
83         private final String JavaDoc className;
84         public DeliveryType(String JavaDoc type, String JavaDoc className){
85             this.type = type;
86             this.className = className;
87         }
88
89         public String JavaDoc getType(){
90             return type;
91         }
92
93         public String JavaDoc getClassName(){
94             return className;
95         }
96     }
97 }
98
Popular Tags