1 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 ; 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.io.File ; 26 27 34 public class AlertSystemConfig { 35 36 private static final String 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 private List deliveryTypes = new LinkedList (); 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 (); 63 } 64 65 Element deliveryTypesElement = 66 config.getRootElement().getChild("deliveryTypes"); 67 assert deliveryTypesElement != null; 68 for(Iterator 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 getDeliveryTypes(){ 78 return deliveryTypes; 79 } 80 81 public static class DeliveryType { 82 private final String type; 83 private final String className; 84 public DeliveryType(String type, String className){ 85 this.type = type; 86 this.className = className; 87 } 88 89 public String getType(){ 90 return type; 91 } 92 93 public String getClassName(){ 94 return className; 95 } 96 } 97 } 98 | Popular Tags |