KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.quickserver.util.MyString;
23 import java.util.logging.*;
24
25 /**
26  * A Simple class that Stores PropertieSet
27  * @author Akshathkumar Shetty
28  */

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

64             //nested QSAdminServer tag
65
String JavaDoc mainTag = "propertie-set";
66             String JavaDoc 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 JavaDoc configFile =
81                 PropertieSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/PropertieSet.xml");
82             if(configFile==null)
83                 throw new RuntimeException JavaDoc("XML File not found : "+"PropertieSet.xml");
84
85             InputStream JavaDoc input = configFile.openStream();
86             logger.fine("Loading command config from xml file : " + input);
87             ps = (PropertieSet) digester.parse(input);
88         } catch(Exception JavaDoc 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