001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.net.qsadmin.gui;
016:
017: import java.util.*;
018: import org.apache.commons.digester.*;
019: import java.net.URL;
020: import java.io.IOException;
021: import java.io.InputStream;
022: import java.util.logging.*;
023: import org.quickserver.util.MyString;
024:
025: /**
026: * A Simple class that Stores SimpleCommands for QSAdmin GUI
027: * @author Akshathkumar Shetty
028: */
029: public class SimpleCommandSet {
030: private static Logger logger = Logger
031: .getLogger(SimpleCommandSet.class.getName());
032:
033: //stores commands from xml file
034: private List list;
035: private Map map;
036:
037: public SimpleCommandSet() {
038: list = new ArrayList();
039: map = new HashMap();
040: }
041:
042: public List getList() {
043: return list;
044: }
045:
046: public Map getMap() {
047: return map;
048: }
049:
050: public void addCommand(SimpleCommand sm) {
051: list.add(sm);
052: map.put(sm.getCommand(), sm);
053: }
054:
055: /* Returns SimpleCommandSet containing simple commands */
056: public static SimpleCommandSet getSimpleCommands() {
057: SimpleCommandSet sms = null;
058: try {
059: Digester digester = new Digester();
060: digester.setValidating(false);
061: //digester.setNamespaceAware(true);
062: //String xsd = "" + new File("quickserver_config.xsd").toURI();
063: //digester.setSchema(xsd);
064:
065: //nested QSAdminServer tag
066: String mainTag = "simple-command-set";
067: String subTag = "simple-command";
068: digester.addObjectCreate(mainTag, SimpleCommandSet.class);
069: digester.addObjectCreate(mainTag + "/" + subTag,
070: SimpleCommand.class);
071: digester.addBeanPropertySetter(mainTag + "/" + subTag
072: + "/name");
073: digester.addBeanPropertySetter(mainTag + "/" + subTag
074: + "/command");
075: digester.addBeanPropertySetter(mainTag + "/" + subTag
076: + "/desc");
077: digester.addBeanPropertySetter(mainTag + "/" + subTag
078: + "/target-needed", "targetNeeded");
079: digester.addBeanPropertySetter(mainTag + "/" + subTag
080: + "/multi-line-response", "multiLineResponse");
081: digester.addBeanPropertySetter(mainTag + "/" + subTag
082: + "/version");
083: digester.addSetNext(mainTag + "/" + subTag, "addCommand");
084: URL configFile = SimpleCommandSet.class
085: .getResource("/org/quickserver/net/qsadmin/gui/conf/MainCommandPanel.xml");
086: if (configFile == null)
087: throw new RuntimeException("XML File not found : "
088: + "MainCommandPanel.xml");
089:
090: InputStream input = configFile.openStream();
091: logger.fine("Loading command config from xml file : "
092: + input);
093: sms = (SimpleCommandSet) digester.parse(input);
094: } catch (Exception e) {
095: logger.severe("Could not init from xml file : " + e);
096: logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
097: }
098: return sms;
099: }
100: }
|