KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > xmlreader > ApplicationConfiguration


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.util.xmlreader;
16
17 import java.util.*;
18
19 /**
20  * This class encapsulate the Application Configuration.
21  * The example xml is <pre>
22  &lt;quickserver&gt;
23     ....
24     &lt;application-configuration&gt;
25         &lt;property&gt;
26             &lt;property-name&gt;FTP_ROOT&lt;/property-name&gt;
27             &lt;property-value&gt;c:\&lt;/property-value&gt;
28         &lt;/property&gt;
29         &lt;property&gt;
30             &lt;property-name&gt;Server Name&lt;/property-name&gt;
31             &lt;property-value&gt;My Server&lt;/property-value&gt;
32         &lt;/property&gt;
33     &lt;/application-configuration&gt;
34     ....
35 &lt;/quickserver&gt;
36 </pre>
37  * @author Akshathkumar Shetty
38  * @since 1.3.2
39  */

40 public class ApplicationConfiguration extends HashMap {
41     private String JavaDoc promptType = "gui";//OR console
42

43     /**
44      * Sets the PromptType.
45      * XML Tag: &lt;prompt-type&gt;true&lt;/prompt-typ&gt;
46      * Allowed values = <code>gui</code> | <code>console</code>
47      * @see #getPromptType
48      * @since 1.4.5
49      */

50     public void setPromptType(String JavaDoc promptType) {
51         if(promptType!=null && promptType.equals("")==false)
52             if(promptType.equals("gui") || promptType.equals("console"))
53                 this.promptType = promptType;
54     }
55     /**
56      * Returns the PromptType
57      * @see #setPromptType
58      * @since 1.4.5
59      */

60     public String JavaDoc getPromptType() {
61         return promptType;
62     }
63
64     /**
65      * Addes the {@link Property} passed to the HashMap
66      */

67     public void addProperty(Property property) {
68         put(property.getName(), property.getValue());
69     }
70
71     /**
72      * Finds if any {@link Property} is present.
73      * @return <code>null</code> if no Property was found.
74      */

75     public Property findProperty(String JavaDoc name) {
76         String JavaDoc temp = (String JavaDoc) get(name);
77         if(temp!=null) {
78             return new Property(name, temp);
79         } else {
80             return null;
81         }
82     }
83
84     /**
85      * Returns XML config of this class.
86      */

87     public String JavaDoc toXML(String JavaDoc pad) {
88         if(pad==null) pad="";
89         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
90         sb.append(pad+"<application-configuration>\n");
91         
92         sb.append(pad+"\t<prompt-type>"+getPromptType()+"</prompt-type>");
93
94         Iterator iterator = keySet().iterator();
95         while(iterator.hasNext()) {
96             String JavaDoc key = (String JavaDoc) iterator.next();
97             String JavaDoc value = (String JavaDoc) get(key);
98             sb.append(pad+"\t<property>");
99             sb.append(pad+"\t\t<property-name>"+key+"</property-name>\n");
100             sb.append(pad+"\t\t<property-value>"+value+"</property-value>\n");
101             sb.append(pad+"\t</property>\n");
102         }
103         sb.append(pad+"</application-configuration>\n");
104         return sb.toString();
105     }
106 }
107
Popular Tags