Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1558 → Rev 1559

/dongfang_FC_rewrite_tool/src/dongfang/mkt/configuration/ConfigSet.java
3,9 → 3,7
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
261,7 → 259,7
// It does not parse the section and default information, which could be
// useful for GUIs etc.
public static ConfigSet parseXMLConfigSet(int version) throws IOException {
String fileName = "v" + version + ".xml";
String fileName = "configsets/templates/v" + version + ".xml";
File f = new File(fileName);
DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance();
saxfac.setValidating(false);
271,7 → 269,7
XPath xpath = XPathFactory.newInstance().newXPath();
 
String s_eepromVersion = xpath.evaluate(
"/parameterconfig/@eepromVersion", doc);
"/parametertemplate/@eepromVersion", doc);
int eepromVersion = Integer.parseInt(s_eepromVersion);
 
if (eepromVersion != version) {
278,7 → 276,7
throw new IOException(
"Version mismatch between file name ("
+ fileName
+ ") and the version in the parameterconfig/@eepromVersion attribute("
+ ") and the version in the parametertemplate/@eepromVersion attribute("
+ s_eepromVersion + ")");
}
 
285,35 → 283,31
ConfigSet result = new ConfigSet(eepromVersion);
 
NodeList sectionNodes = (NodeList) xpath.evaluate(
"/section", doc, XPathConstants.NODESET);
"/parametertemplate/section", doc, XPathConstants.NODESET);
 
for (int i = 0; i < sectionNodes.getLength(); i++) {
Element e = (Element) sectionNodes.item(i);
Section section = new Section(e.getAttribute("name"), e.getAttribute("title"));
Element sectionNode = (Element) sectionNodes.item(i);
Section section = new Section(sectionNode.getAttribute("name"), sectionNode.getAttribute("title"));
result.declaredSections.add(section);
}
NodeList parameterNodes = (NodeList) xpath.evaluate(
"/parameterconfig/parameter", doc, XPathConstants.NODESET);
"parameter", sectionNode, XPathConstants.NODESET);
 
Section rest = new Section("others", "Entries without a declared section");
for (int i = 0; i < parameterNodes.getLength(); i++) {
Element e = (Element) parameterNodes.item(i);
for (int j=0; j<parameterNodes.getLength(); j++) {
Element parameterNode = (Element) parameterNodes.item(j);
 
Map<String, Section> sectionMap = new HashMap<String, Section>();
ConfigEntry entry;
if (!e.hasAttribute("name")) {
throw new IOException("A parameter element (the " + i
+ "th) had no name attribute!");
if (!sectionNode.hasAttribute("name")) {
throw new IOException("A parameter element (the " + j
+ "th in section "+sectionNode.getAttribute("name")+") had no name attribute!");
}
String s_name = e.getAttribute("name");
String s_section = e.getAttribute("section");
 
String s_name = parameterNode.getAttribute("name");
String s_type;
 
if (e.hasAttribute("type")) {
s_type = e.getAttribute("type");
if (parameterNode.hasAttribute("type")) {
s_type = parameterNode.getAttribute("type");
} else {
s_type = "static";
}
323,30 → 317,24
} else if ("dynamic".equals(s_type)) {
entry = new ConfigSet.ByteEntry(s_name, true);
} else if ("bitset".equals(s_type)) {
NodeList bitNodes = (NodeList) xpath.evaluate("bit", e,
XPathConstants.NODESET);
NodeList bitNodes = (NodeList) xpath.evaluate("bit", parameterNode, XPathConstants.NODESET);
String[] bitNames = new String[8];
for (int j = 0; j < 8; j++) {
Element bitNode = (Element) bitNodes.item(j);
for (int k=0; k<8; k++) {
Element bitNode = (Element) bitNodes.item(k);
if (bitNode != null) {
bitNames[j] = bitNode.getAttribute("name");
bitNames[k] = bitNode.getAttribute("name");
} else {
bitNames[j] = "Unused";
bitNames[k] = "Unused";
}
}
entry = new ConfigSet.BitSetEntry(s_name,
bitNames);
entry = new ConfigSet.BitSetEntry(s_name, bitNames);
} else {
throw new IOException("Unknown parameter type: " + s_type);
}
result.entries.add(entry);
Section section = sectionMap.get(s_section);
if (section==null) section = rest;
section.addConfigEntry(entry);
}
if (!rest.getEntries().isEmpty()) {
result.declaredSections.add(rest);
}
result.name = "" + version;
return result;