source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ValidationParser.java@ 858

Last change on this file since 858 was 858, checked in by tobias, on Apr 9, 2010 at 10:56:07 AM

visual design slightly modified. tree functions extended

File size: 6.1 KB
Line 
1package de.dass_it.vanhelsing.gui;
2import java.io.*;
3/*
4 * Einlesen der Dateien dird_conf.c, filed_conf.c und stored_conf.c
5 */
6
7
8public class ValidationParser{
9
10 public static void main(String args[]) {
11 try {
12 FileInputStream fs = new FileInputStream(args[1]);
13 DataInputStream ds = new DataInputStream(fs);
14 BufferedReader br = new BufferedReader(new InputStreamReader(ds));
15 String line;
16 String[] lineParts;
17 String name ="FEHLER"; //Resourcename
18 String daemon = args[0];
19
20 String item; //Resourcenitem
21 String type; //Resourcentype
22 String ref; //Referenz auf andere Resourcen
23 String nec; //Kann oder Mussfeld
24 String def; //defaultwert
25
26 String state = "";
27 while ((line = br.readLine()) != null){
28 //Zeile enthält entweder Resourcenname oder Resourcenteildefinition
29 if (line.startsWith("static RES_ITEM")){
30 lineParts = line.split(" ");
31 name = lineParts[2].substring(0, (lineParts[2].length()-2));
32 state = "res";
33 continue;
34 }
35 if (line.startsWith("RES_ITEM")){
36 lineParts = line.split(" ");
37 name = lineParts[1].substring(0, (lineParts[1].length()-2));
38 state = "res";
39 continue;
40
41 }
42 if (line.startsWith("};")){
43 state = "";
44 continue;
45 }
46 if (line.contains("{NULL")){
47 continue;
48 }
49 if (line.split(",").length != 6){
50 continue;
51 }
52 if (state.equals("res")){
53 lineParts = line.split(",");
54 item = lineParts[0].replaceAll(" ", "");
55 item = item.replaceAll("\\{", "");
56 item = item.replaceAll("\"", "");
57 type = lineParts[1].replaceAll(" ", "");
58 type = type.replaceAll("\"", "");
59 ref = lineParts[3];
60 nec = lineParts[4];
61 def = lineParts[5].replaceAll("\\}", "");
62 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"ref" + " = " + getReferenz(ref));
63 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"type" + " = " +getJavaType(type));
64 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"required" + " = " +getJavaReq(nec));
65 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"def" + " = " +def);
66 continue;
67 }
68 }
69 ds.close();
70 } catch (Exception e){
71 e.printStackTrace();
72 }
73 }
74
75 private static String getReferenz(String s){
76 return s;
77 }
78
79 private static String getJavaType(String s){
80 for (conf2type c2t : conf2type.values()){
81 if (c2t.conf.equals(s)){
82 return c2t.type;
83 }
84 }
85 /*if (s.equals("store_bool") || s.equals("store_bit") ){
86 return "boolean";
87 }
88 if (s.equals("store_str") || s.equals("store_name") || s.equals("store_strname")){
89 return "String";
90 }
91 if (s.equals("store_pint32")||s.equals("store_size")){
92 return "int";
93 }
94 if (s.equals("store_dir")){
95 return "Path";
96 }
97 if (s.equals("store_password")){
98 return "Password";
99 }
100 if (s.equals("store_time")){
101 return "Date";
102 }
103 if (s.equals("store_acl")){
104 return "Acl";
105 }
106 if (s.equals("store_res")){
107 return "Resource";
108 }*/
109 //switch(s){
110 //case "store_bool" : s = "boolean"; break;
111 //case "store_pint32" : s = "int"; break;
112 //case "store_str" : s = "String";
113 //case "store_name" : s = "String"; break;
114 //case "store_dir" : s = "Path"; break;
115 //case "store_password" : s = "Password"; break;
116 //case "store_time" : s = "Date"; break;
117 //case "store_bit" : s = "boolean"; break;
118 //case "store_size" : s = "int"; break;
119 //case "store_acl" : s = "Acl"; break;
120 //case "store_strname" : s = "String"; break;
121 //case "store_res" : s = "Resource"; break;
122 //}
123 return s;
124 }
125 private static String getJavaReq(String s){
126 if ( s.contains("ITEM_REQUIRED") ){
127 s = "true";
128 } else {
129 s = "false";
130 }
131 return s;
132 }
133 private static String getPrettyName(String s){
134 for (prettyNames name : prettyNames.values()){
135 if (name.ugly.equals(s)){
136 return name.pretty;
137 }
138 }
139
140 return s;
141 }
142 /**
143 * @author tgoecke
144 */
145 private enum prettyNames{
146 CATALOG ("cat_items", "catalog"),
147 CLIENT ("cli_items", "client"),
148 CONSOLE ("con_items", "console"),
149 COUNTER ("counter_items", "counter"),
150 DIRECTOR ("dir_items", "director"),
151 FILESET ("fs_items", "fileset"),
152 POOL ("pool_items", "pool"),
153 RUNSCRIPT ("runscript_items", "runscript"),
154 SCHEDULE ("sch_items", "schedule"),
155 STORAGE ("store_items", "storage"),
156 AUTOCHANGER ("changer_items", "autochanger"),
157 DEVICE ("dev_items", "device"),
158 JOB("job_items", "job"),
159 MESSAGE("msgs_item","message");
160
161 private String ugly;
162 private String pretty;
163
164 prettyNames(String ugly, String pretty){
165 this.ugly = ugly;
166 this.pretty = pretty;
167 }
168 }
169 /**
170 * @author tgoecke
171 */
172 private enum conf2type{
173 /**
174 * @uml.property name="sTOREPOOL"
175 * @uml.associationEnd
176 */
177 STOREPOOL ("store_pool", "boolean"),
178 /**
179 * @uml.property name="sTOREBIT"
180 * @uml.associationEnd
181 */
182 STOREBIT ("store_bit","boolean"),
183 /**
184 * @uml.property name="sTORE_STR"
185 * @uml.associationEnd
186 */
187 STORE_STR ("store_str","String"),
188 /**
189 * @uml.property name="sTORE_NAME"
190 * @uml.associationEnd
191 */
192 STORE_NAME ("store_name", "String"),
193 /**
194 * @uml.property name="sTORE_STRNAME"
195 * @uml.associationEnd
196 */
197 STORE_STRNAME ("store_strname", "String"),
198 /**
199 * @uml.property name="sTORE_PINT32"
200 * @uml.associationEnd
201 */
202 STORE_PINT32 ("store_pint32", "int"),
203 /**
204 * @uml.property name="sTORE_SIZE"
205 * @uml.associationEnd
206 */
207 STORE_SIZE ("store_size", "int"),
208 /**
209 * @uml.property name="sTORE_DIR"
210 * @uml.associationEnd
211 */
212 STORE_DIR ("store_dir", "path"),
213 /**
214 * @uml.property name="sTORE_PASSWORD"
215 * @uml.associationEnd
216 */
217 STORE_PASSWORD ("store_password", "Password"),
218 /**
219 * @uml.property name="sTORE_TIME"
220 * @uml.associationEnd
221 */
222 STORE_TIME ("store_time", "Date"),
223 /**
224 * @uml.property name="sTORE_ACL"
225 * @uml.associationEnd
226 */
227 STORE_ACL ("store_acl", "Acl"),
228 /**
229 * @uml.property name="sTORE_RES"
230 * @uml.associationEnd
231 */
232 STORE_RES ("store_res", "Resource");
233
234 private String conf;
235 private String type;
236
237 conf2type(String conf, String type){
238 this.conf = conf;
239 this.type = type;
240 }
241 }
242}
Note: See TracBrowser for help on using the repository browser.