KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > qsadmin > gui > SimpleCommandSet


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.qsadmin.gui;
16
17 import java.util.*;
18 import org.apache.commons.digester.*;
19 import java.net.URL JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.logging.*;
23 import org.quickserver.util.MyString;
24
25 /**
26  * A Simple class that Stores SimpleCommands for QSAdmin GUI
27  * @author Akshathkumar Shetty
28  */

29 public class SimpleCommandSet {
30     private static Logger logger = Logger.getLogger(SimpleCommandSet.class.getName());
31
32     //stores commands from xml file
33
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     /* Returns SimpleCommandSet containing simple commands */
54     public static SimpleCommandSet getSimpleCommands() {
55         SimpleCommandSet sms = null;
56         try {
57             Digester digester = new Digester();
58             digester.setValidating(false);
59             //digester.setNamespaceAware(true);
60
//String xsd = "" + new File("quickserver_config.xsd").toURI();
61
//digester.setSchema(xsd);
62

63             //nested QSAdminServer tag
64
String JavaDoc mainTag = "simple-command-set";
65             String JavaDoc 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 JavaDoc configFile =
76                 SimpleCommandSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/MainCommandPanel.xml");
77             if(configFile==null)
78                 throw new RuntimeException JavaDoc("XML File not found : "+"MainCommandPanel.xml");
79
80             InputStream JavaDoc input = configFile.openStream();
81             logger.fine("Loading command config from xml file : " + input);
82             sms = (SimpleCommandSet) digester.parse(input);
83         } catch(Exception JavaDoc 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