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 java.util.logging.*; 23 import org.quickserver.util.MyString; 24 25 29 public class SimpleCommandSet { 30 private static Logger logger = Logger.getLogger(SimpleCommandSet.class.getName()); 31 32 private List list; 34 private Map map; 35 36 public SimpleCommandSet() { 37 list = new ArrayList(); 38 map = new HashMap(); 39 } 40 41 public List getList() { 42 return list; 43 } 44 public Map getMap() { 45 return map; 46 } 47 48 public void addCommand(SimpleCommand sm) { 49 list.add(sm); 50 map.put(sm.getCommand(), sm); 51 } 52 53 54 public static SimpleCommandSet getSimpleCommands() { 55 SimpleCommandSet sms = null; 56 try { 57 Digester digester = new Digester(); 58 digester.setValidating(false); 59 63 String mainTag = "simple-command-set"; 65 String subTag = "simple-command"; 66 digester.addObjectCreate(mainTag, SimpleCommandSet.class); 67 digester.addObjectCreate(mainTag+"/"+subTag, SimpleCommand.class); 68 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/name"); 69 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/command"); 70 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/desc"); 71 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/target-needed", "targetNeeded"); 72 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/multi-line-response", "multiLineResponse"); 73 digester.addBeanPropertySetter(mainTag+"/"+subTag+"/version"); 74 digester.addSetNext(mainTag+"/"+subTag,"addCommand"); 75 URL configFile = 76 SimpleCommandSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/MainCommandPanel.xml"); 77 if(configFile==null) 78 throw new RuntimeException ("XML File not found : "+"MainCommandPanel.xml"); 79 80 InputStream input = configFile.openStream(); 81 logger.fine("Loading command config from xml file : " + input); 82 sms = (SimpleCommandSet) digester.parse(input); 83 } catch(Exception e) { 84 logger.severe("Could not init from xml file : " +e); 85 logger.fine("StackTrace:\n"+MyString.getStackTrace(e)); 86 } 87 return sms; 88 } 89 } 90 | Popular Tags |