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 org.quickserver.util.MyString;
023: import java.util.logging.*;
024:
025: /**
026: * A Simple class that Stores PropertieSet
027: * @author Akshathkumar Shetty
028: */
029: public class PropertieSet {
030: private static Logger logger = Logger.getLogger(PropertieSet.class
031: .getName());
032:
033: //stores commands from xml file
034: private List list;
035: private Map map;
036:
037: public PropertieSet() {
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(Propertie p) {
051: list.add(p);
052: map.put(p.getCommand(), p);
053: }
054:
055: /* Returns SimpleCommandSet containing simple commands */
056: public static PropertieSet getPropertieSet() {
057: PropertieSet ps = 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 = "propertie-set";
067: String subTag = "propertie";
068: digester.addObjectCreate(mainTag, PropertieSet.class);
069: digester.addObjectCreate(mainTag + "/" + subTag,
070: Propertie.class);
071: digester.addBeanPropertySetter(mainTag + "/" + subTag
072: + "/name");
073: digester.addBeanPropertySetter(mainTag + "/" + subTag
074: + "/command");
075: digester.addCallMethod(mainTag + "/" + subTag + "/get",
076: "setGet", 0);
077: digester.addCallMethod(mainTag + "/" + subTag + "/set",
078: "setSet", 0);
079: digester.addBeanPropertySetter(mainTag + "/" + subTag
080: + "/type");
081: digester.addBeanPropertySetter(mainTag + "/" + subTag
082: + "/desc");
083: digester.addBeanPropertySetter(mainTag + "/" + subTag
084: + "/select");
085: digester.addBeanPropertySetter(mainTag + "/" + subTag
086: + "/target-needed", "targetNeeded");
087: digester.addBeanPropertySetter(mainTag + "/" + subTag
088: + "/version");
089: digester.addSetNext(mainTag + "/" + subTag, "addCommand");
090:
091: URL configFile = PropertieSet.class
092: .getResource("/org/quickserver/net/qsadmin/gui/conf/PropertieSet.xml");
093: if (configFile == null)
094: throw new RuntimeException("XML File not found : "
095: + "PropertieSet.xml");
096:
097: InputStream input = configFile.openStream();
098: logger.fine("Loading command config from xml file : "
099: + input);
100: ps = (PropertieSet) digester.parse(input);
101: } catch (Exception e) {
102: logger.severe("Could not init from xml file : " + e);
103: logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
104: }
105: return ps;
106: }
107: }
|