1 14 15 package org.quickserver.net.qsadmin.gui; 16 17 import java.util.*; 18 import org.apache.commons.digester.*; 19 import java.net.URL ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import org.quickserver.util.MyString; 23 import java.util.logging.*; 24 25 29 public class PropertieSet { 30 private static Logger logger = Logger.getLogger( 31 PropertieSet.class.getName()); 32 33 private List list; 35 private Map map; 36 37 public PropertieSet() { 38 list = new ArrayList(); 39 map = new HashMap(); 40 } 41 42 public List getList() { 43 return list; 44 } 45 public Map getMap() { 46 return map; 47 } 48 49 public void addCommand(Propertie p) { 50 list.add(p); 51 map.put(p.getCommand(), p); 52 } 53 54 55 public static PropertieSet getPropertieSet() { 56 PropertieSet ps = null; 57 try { 58 Digester digester = new Digester(); 59 digester.setValidating(false); 60 64 String mainTag = "propertie-set"; 66 String subTag = "propertie"; 67 digester.addObjectCreate(mainTag, PropertieSet.class); 68 digester.addObjectCreate(mainTag+"/"+subTag, Propertie.class); 69 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/name"); 70 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/command"); 71 digester.addCallMethod(mainTag+"/"+subTag+"/get", "setGet",0); 72 digester.addCallMethod(mainTag+"/"+subTag+"/set", "setSet",0); 73 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/type"); 74 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/desc"); 75 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/select"); 76 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/target-needed", "targetNeeded"); 77 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/version"); 78 digester.addSetNext(mainTag+"/"+subTag,"addCommand"); 79 80 URL configFile = 81 PropertieSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/PropertieSet.xml"); 82 if(configFile==null) 83 throw new RuntimeException ("XML File not found : "+"PropertieSet.xml"); 84 85 InputStream input = configFile.openStream(); 86 logger.fine("Loading command config from xml file : " + input); 87 ps = (PropertieSet) digester.parse(input); 88 } catch(Exception e) { 89 logger.severe("Could not init from xml file : " +e); 90 logger.fine("StackTrace:\n"+MyString.getStackTrace(e)); 91 } 92 return ps; 93 } 94 } 95 | Popular Tags |