KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.quickserver.util.MyString;
18
19 /**
20  * A Simple class that Stores information about QSAdmin Command
21  * that are common to any <code>target</code>
22  * @author Akshathkumar Shetty
23  */

24 public class SimpleCommand {
25     private String JavaDoc name;
26     private String JavaDoc target = "server";
27     private String JavaDoc command;
28     private String JavaDoc desc;
29     private String JavaDoc targetNeeded = "yes";
30     private String JavaDoc multiLineResponse = "no";
31     private String JavaDoc version = "1.3"; //when AdminUI was added
32

33     public String JavaDoc getSimpleCommand() {
34         if(targetNeeded.equals("yes"))
35             return command+" "+target;
36         else
37             return command;
38     }
39
40     public String JavaDoc getName(){
41         return name;
42     }
43     public void setName(String JavaDoc name) {
44         this.name = name;
45     }
46
47     public String JavaDoc getTarget() {
48         return target;
49     }
50     public void setTarget(String JavaDoc target) {
51         this.target = target;
52     }
53
54     public String JavaDoc getCommand() {
55         return command;
56     }
57     public void setCommand(String JavaDoc command) {
58         this.command = command;
59     }
60
61     public String JavaDoc getDesc() {
62         return desc;
63     }
64     public void setDesc(String JavaDoc desc) {
65         this.desc = desc;
66     }
67
68     public String JavaDoc getTargetNeeded() {
69         return targetNeeded;
70     }
71     public void setTargetNeeded(String JavaDoc targetNeeded) {
72         this.targetNeeded = targetNeeded.toLowerCase();
73     }
74
75     public String JavaDoc getMultiLineResponse() {
76         return multiLineResponse;
77     }
78     public void setMultiLineResponse(String JavaDoc multiLineResponse) {
79         this.multiLineResponse = multiLineResponse.toLowerCase();
80     }
81
82     public String JavaDoc getVersion() {
83         return version;
84     }
85     public float getVersionNo() {
86         return getVersionNo(version);
87     }
88     public void setVersion(String JavaDoc version) {
89         if(version!=null && version.equals("")==false)
90             this.version = version.toLowerCase();
91     }
92
93     public String JavaDoc toXML() {
94         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
95         sb.append("<simple-command>\n");
96         sb.append("\t<name>"+name+"</name>\n");
97         sb.append("\t<command>"+command+"</command>\n");
98         if(multiLineResponse!=null && multiLineResponse.equals("yes"))
99             sb.append("\t<multi-line-response>yes</multi-line-response>\n");
100         else
101             sb.append("\t<multi-line-response>no</multi-line-response>\n");
102         if(desc!=null)
103             sb.append("\t<desc>"+desc+"</desc>\n");
104         sb.append("\t<version>"+version+"</version>\n");
105         if(targetNeeded!=null && targetNeeded.equals("yes"))
106             sb.append("\t<target-needed>yes</target-needed>\n");
107         else
108             sb.append("\t<target-needed>no</target-needed>\n");
109         sb.append("</simple-command>\n");
110         return sb.toString();
111     }
112
113     private static final float getVersionNo(String JavaDoc ver) {
114         //String ver = getVersion();
115
float version = 0;
116         int i = ver.indexOf(" "); //check if beta
117
if(i == -1)
118             i = ver.length();
119         ver = ver.substring(0, i);
120         
121         i = ver.indexOf("."); //check for sub version
122
if(i!=-1) {
123             int j = ver.indexOf(".", i);
124             if(j!=-1) {
125                 ver = ver.substring(0, i)+"."+
126                     MyString.replaceAll(ver.substring(i+1), ".", "");
127             }
128         }
129
130         try {
131             version = Float.parseFloat(ver);
132         } catch(NumberFormatException JavaDoc e) {
133             throw new RuntimeException JavaDoc("Corrupt QuickServer");
134         }
135         return version;
136     }
137 }
138
Popular Tags