Rev 1532 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1532 | Rev 1559 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package dongfang.mkt.configuration; |
1 | package dongfang.mkt.configuration; |
Line 2... | Line 2... | ||
2 | 2 | ||
3 | import java.io.File; |
3 | import java.io.File; |
4 | import java.io.IOException; |
4 | import java.io.IOException; |
5 | import java.util.ArrayList; |
- | |
6 | import java.util.HashMap; |
5 | import java.util.ArrayList; |
7 | import java.util.List; |
- | |
Line 8... | Line 6... | ||
8 | import java.util.Map; |
6 | import java.util.List; |
9 | 7 | ||
10 | import javax.xml.parsers.DocumentBuilder; |
8 | import javax.xml.parsers.DocumentBuilder; |
11 | import javax.xml.parsers.DocumentBuilderFactory; |
9 | import javax.xml.parsers.DocumentBuilderFactory; |
Line 259... | Line 257... | ||
259 | 257 | ||
260 | // This parses only for the purpose of naming and typing parameter sets! |
258 | // This parses only for the purpose of naming and typing parameter sets! |
261 | // It does not parse the section and default information, which could be |
259 | // It does not parse the section and default information, which could be |
262 | // useful for GUIs etc. |
260 | // useful for GUIs etc. |
263 | public static ConfigSet parseXMLConfigSet(int version) throws IOException { |
261 | public static ConfigSet parseXMLConfigSet(int version) throws IOException { |
264 | String fileName = "v" + version + ".xml"; |
262 | String fileName = "configsets/templates/v" + version + ".xml"; |
265 | File f = new File(fileName); |
263 | File f = new File(fileName); |
266 | DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
264 | DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance(); |
267 | saxfac.setValidating(false); |
265 | saxfac.setValidating(false); |
268 | try { |
266 | try { |
269 | DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
267 | DocumentBuilder bldr = saxfac.newDocumentBuilder(); |
270 | Document doc = bldr.parse(f); |
268 | Document doc = bldr.parse(f); |
Line 271... | Line 269... | ||
271 | XPath xpath = XPathFactory.newInstance().newXPath(); |
269 | XPath xpath = XPathFactory.newInstance().newXPath(); |
272 | 270 | ||
273 | String s_eepromVersion = xpath.evaluate( |
271 | String s_eepromVersion = xpath.evaluate( |
Line 274... | Line 272... | ||
274 | "/parameterconfig/@eepromVersion", doc); |
272 | "/parametertemplate/@eepromVersion", doc); |
275 | int eepromVersion = Integer.parseInt(s_eepromVersion); |
273 | int eepromVersion = Integer.parseInt(s_eepromVersion); |
276 | 274 | ||
277 | if (eepromVersion != version) { |
275 | if (eepromVersion != version) { |
278 | throw new IOException( |
276 | throw new IOException( |
279 | "Version mismatch between file name (" |
277 | "Version mismatch between file name (" |
280 | + fileName |
278 | + fileName |
Line 281... | Line 279... | ||
281 | + ") and the version in the parameterconfig/@eepromVersion attribute(" |
279 | + ") and the version in the parametertemplate/@eepromVersion attribute(" |
Line 282... | Line 280... | ||
282 | + s_eepromVersion + ")"); |
280 | + s_eepromVersion + ")"); |
283 | } |
281 | } |
Line 284... | Line 282... | ||
284 | 282 | ||
285 | ConfigSet result = new ConfigSet(eepromVersion); |
283 | ConfigSet result = new ConfigSet(eepromVersion); |
286 | 284 | ||
287 | NodeList sectionNodes = (NodeList) xpath.evaluate( |
285 | NodeList sectionNodes = (NodeList) xpath.evaluate( |
288 | "/section", doc, XPathConstants.NODESET); |
- | |
Line 289... | Line 286... | ||
289 | 286 | "/parametertemplate/section", doc, XPathConstants.NODESET); |
|
290 | for (int i = 0; i < sectionNodes.getLength(); i++) { |
287 | |
Line 291... | Line -... | ||
291 | Element e = (Element) sectionNodes.item(i); |
- | |
292 | Section section = new Section(e.getAttribute("name"), e.getAttribute("title")); |
288 | for (int i = 0; i < sectionNodes.getLength(); i++) { |
293 | result.declaredSections.add(section); |
289 | Element sectionNode = (Element) sectionNodes.item(i); |
Line 294... | Line -... | ||
294 | } |
- | |
295 | 290 | Section section = new Section(sectionNode.getAttribute("name"), sectionNode.getAttribute("title")); |
|
Line 296... | Line 291... | ||
296 | NodeList parameterNodes = (NodeList) xpath.evaluate( |
291 | result.declaredSections.add(section); |
297 | "/parameterconfig/parameter", doc, XPathConstants.NODESET); |
292 | |
298 | 293 | NodeList parameterNodes = (NodeList) xpath.evaluate( |
|
299 | Section rest = new Section("others", "Entries without a declared section"); |
294 | "parameter", sectionNode, XPathConstants.NODESET); |
300 | for (int i = 0; i < parameterNodes.getLength(); i++) { |
- | |
301 | Element e = (Element) parameterNodes.item(i); |
- | |
Line -... | Line 295... | ||
- | 295 | ||
302 | 296 | for (int j=0; j<parameterNodes.getLength(); j++) { |
|
Line 303... | Line 297... | ||
303 | Map<String, Section> sectionMap = new HashMap<String, Section>(); |
297 | Element parameterNode = (Element) parameterNodes.item(j); |
304 | ConfigEntry entry; |
298 | |
305 | 299 | ConfigEntry entry; |
|
306 | if (!e.hasAttribute("name")) { |
300 | |
307 | throw new IOException("A parameter element (the " + i |
301 | if (!sectionNode.hasAttribute("name")) { |
Line 308... | Line 302... | ||
308 | + "th) had no name attribute!"); |
302 | throw new IOException("A parameter element (the " + j |
309 | } |
303 | + "th in section "+sectionNode.getAttribute("name")+") had no name attribute!"); |
310 | String s_name = e.getAttribute("name"); |
304 | } |
311 | String s_section = e.getAttribute("section"); |
305 | |
312 | 306 | String s_name = parameterNode.getAttribute("name"); |
|
313 | String s_type; |
307 | String s_type; |
314 | - | ||
315 | if (e.hasAttribute("type")) { |
308 | |
316 | s_type = e.getAttribute("type"); |
309 | if (parameterNode.hasAttribute("type")) { |
317 | } else { |
310 | s_type = parameterNode.getAttribute("type"); |
318 | s_type = "static"; |
311 | } else { |
319 | } |
312 | s_type = "static"; |
320 | 313 | } |
|
321 | if ("static".equals(s_type)) { |
314 | |
322 | entry = new ConfigSet.ByteEntry(s_name, false); |
315 | if ("static".equals(s_type)) { |
323 | } else if ("dynamic".equals(s_type)) { |
316 | entry = new ConfigSet.ByteEntry(s_name, false); |
324 | entry = new ConfigSet.ByteEntry(s_name, true); |
317 | } else if ("dynamic".equals(s_type)) { |
325 | } else if ("bitset".equals(s_type)) { |
- | |
326 | NodeList bitNodes = (NodeList) xpath.evaluate("bit", e, |
318 | entry = new ConfigSet.ByteEntry(s_name, true); |
327 | XPathConstants.NODESET); |
319 | } else if ("bitset".equals(s_type)) { |
328 | String[] bitNames = new String[8]; |
320 | NodeList bitNodes = (NodeList) xpath.evaluate("bit", parameterNode, XPathConstants.NODESET); |
Line 329... | Line 321... | ||
329 | for (int j = 0; j < 8; j++) { |
321 | String[] bitNames = new String[8]; |
330 | Element bitNode = (Element) bitNodes.item(j); |
- | |
331 | if (bitNode != null) { |
- | |
332 | bitNames[j] = bitNode.getAttribute("name"); |
322 | for (int k=0; k<8; k++) { |
333 | } else { |
323 | Element bitNode = (Element) bitNodes.item(k); |
334 | bitNames[j] = "Unused"; |
- | |
335 | } |
- | |
336 | } |
324 | if (bitNode != null) { |
337 | entry = new ConfigSet.BitSetEntry(s_name, |
325 | bitNames[k] = bitNode.getAttribute("name"); |
338 | bitNames); |
326 | } else { |
339 | } else { |
327 | bitNames[k] = "Unused"; |
340 | throw new IOException("Unknown parameter type: " + s_type); |
328 | } |