Subversion Repositories Projects

Rev

Rev 1578 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1578 Rev 1601
1
package dongfang.mkt.configuration;
1
package dongfang.mkt.configuration;
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;
5
import java.util.ArrayList;
6
import java.util.List;
6
import java.util.List;
7
 
7
 
8
import javax.xml.parsers.DocumentBuilder;
8
import javax.xml.parsers.DocumentBuilder;
9
import javax.xml.parsers.DocumentBuilderFactory;
9
import javax.xml.parsers.DocumentBuilderFactory;
10
import javax.xml.parsers.ParserConfigurationException;
10
import javax.xml.parsers.ParserConfigurationException;
11
import javax.xml.xpath.XPath;
11
import javax.xml.xpath.XPath;
12
import javax.xml.xpath.XPathConstants;
12
import javax.xml.xpath.XPathConstants;
13
import javax.xml.xpath.XPathExpressionException;
13
import javax.xml.xpath.XPathExpressionException;
14
import javax.xml.xpath.XPathFactory;
14
import javax.xml.xpath.XPathFactory;
15
 
15
 
16
import org.w3c.dom.Document;
16
import org.w3c.dom.Document;
17
import org.w3c.dom.Element;
17
import org.w3c.dom.Element;
18
import org.w3c.dom.NodeList;
18
import org.w3c.dom.NodeList;
19
import org.xml.sax.SAXException;
19
import org.xml.sax.SAXException;
20
 
20
 
21
public class ConfigSet {
21
public class ConfigSet {
22
        public static final int NUMBER_OF_VARIABLES = 8;
22
        public static final int NUMBER_OF_VARIABLES = 8;
23
        String name;
23
        String name;
24
        int eepromVersion;
24
        int eepromVersion;
25
 
25
 
26
        List<Section> declaredSections = new ArrayList<Section>();
26
        List<Section> declaredSections = new ArrayList<Section>();
27
        List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
27
        List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
28
 
28
 
29
        public static class Section {
29
        public static class Section {
30
                String name, title;
30
                String name, title;
31
                List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
31
                List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
32
 
32
 
33
                public Section(String name, String title) {
33
                public Section(String name, String title) {
34
                        this.name = name;
34
                        this.name = name;
35
                        this.title = title;
35
                        this.title = title;
36
                }
36
                }
37
 
37
 
38
                public void addConfigEntry(ConfigEntry e) {
38
                public void addConfigEntry(ConfigEntry e) {
39
                        this.entries.add(e);
39
                        this.entries.add(e);
40
                }
40
                }
41
 
41
 
42
                public List<ConfigEntry> getEntries() {
42
                public List<ConfigEntry> getEntries() {
43
                        return entries;
43
                        return entries;
44
                }
44
                }
45
 
45
 
46
                public String getName() {
46
                public String getName() {
47
                        return name;
47
                        return name;
48
                }
48
                }
49
 
49
 
50
                public String getTitle() {
50
                public String getTitle() {
51
                        return title;
51
                        return title;
52
                }
52
                }
53
        }
53
        }
54
 
54
 
55
        public static abstract class ConfigEntry {
55
        public static abstract class ConfigEntry {
56
                String name;
56
                String name;
57
 
57
 
58
                ConfigEntry(String name) {
58
                ConfigEntry(String name) {
59
                        this.name = name;
59
                        this.name = name;
60
                }
60
                }
61
 
61
 
62
                abstract int getByteCount();
62
                abstract int getByteCount();
63
 
63
 
64
                abstract String toStringWithValues();
64
                abstract String toStringWithValues();
65
 
65
 
66
                abstract void toXML(StringBuilder result);
66
                abstract void toXML(StringBuilder result);
67
 
67
 
68
                abstract int setValue(int[] data, int offset);
68
                abstract int setValue(int[] data, int offset);
69
 
69
 
70
                public String getName() {
70
                public String getName() {
71
                        return name;
71
                        return name;
72
                }
72
                }
73
 
73
 
74
                public String getSection() {
74
                public String getSection() {
75
                        return name;
75
                        return name;
76
                }
76
                }
77
        }
77
        }
78
 
78
 
79
        public static class StaticByteEntry extends ConfigEntry {
79
        public static class StaticByteEntry extends ConfigEntry {
80
                StaticByteEntry(String name) {
80
                StaticByteEntry(String name) {
81
                        super(name);
81
                        super(name);
82
                }
82
                }
83
 
83
 
84
                int value;
84
                int value;
85
 
85
 
86
                int getByteCount() {
86
                int getByteCount() {
87
                        return 1;
87
                        return 1;
88
                }
88
                }
89
 
89
 
90
                int getValue() {
90
                int getValue() {
91
                        return value;
91
                        return value;
92
                }
92
                }
93
 
93
 
94
                int setValue(int[] data, int offset) {
94
                int setValue(int[] data, int offset) {
95
                        this.value = data[offset];
95
                        this.value = data[offset];
96
                        return getByteCount();
96
                        return getByteCount();
97
                }
97
                }
98
 
98
 
99
                String toStringWithValues() {
99
                String toStringWithValues() {
100
                        return name + ":\t" + value;
100
                        return name + ":\t" + value;
101
                }
101
                }
102
 
102
 
103
                void toXML(StringBuilder result) {
103
                void toXML(StringBuilder result) {
104
                        String s_value;
104
                        String s_value;
105
                        s_value = Integer.toString(value);
105
                        s_value = Integer.toString(value);
106
                        result.append("  <parameter name=\"" + name + "\" value=\""
106
                        result.append("  <parameter name=\"" + name + "\" value=\""
107
                                        + s_value + "\"/>\n");
107
                                        + s_value + "\"/>\n");
108
                }
108
                }
109
        }
109
        }
110
 
110
 
111
        public static class DynamicByteEntry extends StaticByteEntry {
111
        public static class DynamicByteEntry extends StaticByteEntry {
112
                int minValue = 0;
112
                int minValue = 0;
113
                int maxValue = 255;
113
                int maxValue = 255;
114
                String staticCodeName;
114
                String staticCodeName;
115
                String dynamicCodeName;
115
                String dynamicCodeName;
116
               
116
               
117
                DynamicByteEntry(String name) {
117
                DynamicByteEntry(String name) {
118
                        super(name);
118
                        super(name);
119
                }
119
                }
120
 
120
 
121
                int getMinValue() {
121
                int getMinValue() {
122
                        return minValue;
122
                        return minValue;
123
                }
123
                }
124
 
124
 
125
                int getMaxValue() {
125
                int getMaxValue() {
126
                        return maxValue;
126
                        return maxValue;
127
                }
127
                }
128
 
128
 
129
                void setMinValue(int minValue) {
129
                void setMinValue(int minValue) {
130
                        this.minValue = minValue;
130
                        this.minValue = minValue;
131
                }
131
                }
132
 
132
 
133
                void setMaxValue(int maxValue) {
133
                void setMaxValue(int maxValue) {
134
                        this.maxValue = maxValue;
134
                        this.maxValue = maxValue;
135
                }
135
                }
136
 
136
 
137
                String getStaticCodeName() {
137
                String getStaticCodeName() {
138
                        return staticCodeName;
138
                        return staticCodeName;
139
                }
139
                }
140
 
140
 
141
                String getDynamicCodeName() {
141
                String getDynamicCodeName() {
142
                        return dynamicCodeName;
142
                        return dynamicCodeName;
143
                }
143
                }
144
 
144
 
145
                void setStaticCodeName(String staticCodeName) {
145
                void setStaticCodeName(String staticCodeName) {
146
                        this.staticCodeName = staticCodeName;
146
                        this.staticCodeName = staticCodeName;
147
                }
147
                }
148
 
148
 
149
                void setDynamicCodeName(String dynamicCodeName) {
149
                void setDynamicCodeName(String dynamicCodeName) {
150
                        this.dynamicCodeName = dynamicCodeName;
150
                        this.dynamicCodeName = dynamicCodeName;
151
                }
151
                }
152
 
152
 
153
                void toXML(StringBuilder result) {
153
                void toXML(StringBuilder result) {
154
                        String s_value;
154
                        String s_value;
155
                        int numberOfLowestVariable = 256 - NUMBER_OF_VARIABLES;
155
                        int numberOfLowestVariable = 256 - NUMBER_OF_VARIABLES;
156
                        if (value >= numberOfLowestVariable) {
156
                        if (value >= numberOfLowestVariable) {
157
                                s_value = "var" + (value - numberOfLowestVariable);
157
                                s_value = "var" + (value - numberOfLowestVariable);
158
                        } else
158
                        } else
159
                                s_value = Integer.toString(value);
159
                                s_value = Integer.toString(value);
160
                        result.append("  <parameter name=\"" + name + "\" value=\""
160
                        result.append("  <parameter name=\"" + name + "\" value=\""
161
                                        + s_value + "\"/>\n");
161
                                        + s_value + "\"/>\n");
162
                }
162
                }
163
        }
163
        }
164
 
164
 
165
        public static class BitSetEntry extends ConfigEntry {
165
        public static class BitSetEntry extends ConfigEntry {
166
                BitSetEntry(String name, String[] bitNames) {
166
                BitSetEntry(String name, String[] bitNames) {
167
                        super(name);
167
                        super(name);
168
                        this.bitNames = bitNames;
168
                        this.bitNames = bitNames;
169
                }
169
                }
170
 
170
 
171
                int value;
171
                int value;
172
                String[] bitNames;
172
                String[] bitNames;
173
 
173
 
174
                int getByteCount() {
174
                int getByteCount() {
175
                        return 1;
175
                        return 1;
176
                }
176
                }
177
 
177
 
178
                int getValue() {
178
                int getValue() {
179
                        return value;
179
                        return value;
180
                }
180
                }
181
 
181
 
182
                int setValue(int[] data, int offset) {
182
                int setValue(int[] data, int offset) {
183
                        value = data[offset];
183
                        value = data[offset];
184
                        return getByteCount();
184
                        return getByteCount();
185
                }
185
                }
186
 
186
 
187
                String toStringWithValues() {
187
                String toStringWithValues() {
188
                        StringBuilder result = new StringBuilder(name + "\t[");
188
                        StringBuilder result = new StringBuilder(name + "\t[");
189
                        for (int i = 0; i < Math.min(bitNames.length, 8); i++) {
189
                        for (int i = 0; i < Math.min(bitNames.length, 8); i++) {
190
                                if (i != 0)
190
                                if (i != 0)
191
                                        result.append(", ");
191
                                        result.append(", ");
192
                                result.append(bitNames[i] + ":"
192
                                result.append(bitNames[i] + ":"
193
                                                + ((value & (1 << i)) != 0 ? "1" : "0"));
193
                                                + ((value & (1 << i)) != 0 ? "1" : "0"));
194
                        }
194
                        }
195
                        return result.toString();
195
                        return result.toString();
196
                }
196
                }
197
 
197
 
198
                void toXML(StringBuilder result) {
198
                void toXML(StringBuilder result) {
199
                        result.append("  <parameter name=\"" + name + "\">\n");
199
                        result.append("  <parameter name=\"" + name + "\">\n");
200
                        for (int i = 0; i < Math.min(bitNames.length, 8); i++) {
200
                        for (int i = 0; i < Math.min(bitNames.length, 8); i++) {
201
                                result.append("    <bit name=\"" + bitNames[i] + "\" value=\""
201
                                result.append("    <bit name=\"" + bitNames[i] + "\" value=\""
202
                                                + ((value & (1 << i)) != 0 ? "1" : "0") + "\"/>\n");
202
                                                + ((value & (1 << i)) != 0 ? "1" : "0") + "\"/>\n");
203
                        }
203
                        }
204
                        result.append("  </parameter>\n");
204
                        result.append("  </parameter>\n");
205
                }
205
                }
206
        }
206
        }
207
 
207
 
208
        public static class ArrayEntry extends ConfigEntry {
208
        public static class ArrayEntry extends ConfigEntry {
209
                int length;
209
                int length;
210
                boolean isDynamic;
210
                boolean isDynamic;
211
                int[] values;
211
                int[] values;
212
 
212
 
213
                ArrayEntry(String name, boolean isDynamic, int length) {
213
                ArrayEntry(String name, boolean isDynamic, int length) {
214
                        super(name);
214
                        super(name);
215
                        this.isDynamic = isDynamic;
215
                        this.isDynamic = isDynamic;
216
                        this.length = length;
216
                        this.length = length;
217
                }
217
                }
218
 
218
 
219
                int[] getValue() {
219
                int[] getValue() {
220
                        return values;
220
                        return values;
221
                }
221
                }
222
 
222
 
223
                int setValue(int[] data, int offset) {
223
                int setValue(int[] data, int offset) {
224
                        values = new int[length];
224
                        values = new int[length];
225
                        System.arraycopy(data, offset, values, 0, length);
225
                        System.arraycopy(data, offset, values, 0, length);
226
                        return length;
226
                        return length;
227
                }
227
                }
228
 
228
 
229
                int getByteCount() {
229
                int getByteCount() {
230
                        return length;
230
                        return length;
231
                }
231
                }
232
 
232
 
233
                String toStringWithValues() {
233
                String toStringWithValues() {
234
                        StringBuilder result = new StringBuilder(name + ":\t{");
234
                        StringBuilder result = new StringBuilder(name + ":\t{");
235
                        for (int i = 0; i < length; i++) {
235
                        for (int i = 0; i < length; i++) {
236
                                if (i != 0)
236
                                if (i != 0)
237
                                        result.append(",");
237
                                        result.append(",");
238
                                result.append(values[i]);
238
                                result.append(values[i]);
239
                        }
239
                        }
240
                        result.append("}");
240
                        result.append("}");
241
                        return result.toString();
241
                        return result.toString();
242
                }
242
                }
243
 
243
 
244
                void toXML(StringBuilder result) {
244
                void toXML(StringBuilder result) {
245
                        result.append("  <list name=\"" + name + "\">\n");
245
                        result.append("  <list name=\"" + name + "\">\n");
246
                        for (int i = 0; i < length; i++) {
246
                        for (int i = 0; i < length; i++) {
247
                                result.append("    <entry value=\"" + values[i] + "\"/>\n");
247
                                result.append("    <entry value=\"" + values[i] + "\"/>\n");
248
                        }
248
                        }
249
                        result.append("  </list>\n");
249
                        result.append("  </list>\n");
250
                }
250
                }
251
        }
251
        }
252
 
252
 
253
        public List<ConfigEntry> getEntries() {
253
        public List<ConfigEntry> getEntries() {
254
                return entries;
254
                return entries;
255
        }
255
        }
256
 
256
 
257
        public List<Section> getDeclaredSections() {
257
        public List<Section> getDeclaredSections() {
258
                return declaredSections;
258
                return declaredSections;
259
        }
259
        }
260
 
260
 
261
        public void setData(int[] data) {
261
        public void setData(int[] data) throws IOException {
-
 
262
                int offset = 0;
-
 
263
                int dataLength = data.length - 12;
-
 
264
                if (dataLength != getByteCount()) {
-
 
265
                        throw new IOException("The received number of databytes (" + dataLength + ") was not equal to the length of the declared parameter set(" + getByteCount()+").");
-
 
266
                }
262
                int offset = 0;
267
               
263
                for (ConfigEntry entry : entries) {
268
                for (ConfigEntry entry : entries) {
264
                        offset += entry.setValue(data, offset);
269
                        offset += entry.setValue(data, offset);
265
                }
270
                }
266
                StringBuilder sbname = new StringBuilder();
271
                StringBuilder sbname = new StringBuilder();
267
                for (int i = 0; i < 12; i++) {
272
                for (int i = 0; i < 12; i++) {
268
                        if (data[offset] == 0)
273
                        if (data[offset] == 0)
269
                                break;
274
                                break;
270
                        sbname.append((char) data[offset++]);
275
                        sbname.append((char) data[offset++]);
271
                }
276
                }
272
                name = sbname.toString();
277
                name = sbname.toString();
273
        }
278
        }
274
 
279
 
275
        public int getByteCount() {
280
        public int getByteCount() {
276
                int result = 0;
281
                int result = 0;
277
                for (ConfigEntry e : entries) {
282
                for (ConfigEntry e : entries) {
278
                        result += e.getByteCount();
283
                        result += e.getByteCount();
279
                }
284
                }
280
                return result;
285
                return result;
281
        }
286
        }
282
 
287
 
283
        public String toStringWithValues() {
288
        public String toStringWithValues() {
284
                StringBuilder result = new StringBuilder();
289
                StringBuilder result = new StringBuilder();
285
                result.append(name + "\n");
290
                result.append(name + "\n");
286
                for (ConfigEntry entry : entries) {
291
                for (ConfigEntry entry : entries) {
287
                        result.append(entry.toStringWithValues() + "\n");
292
                        result.append(entry.toStringWithValues() + "\n");
288
                }
293
                }
289
                return result.toString();
294
                return result.toString();
290
        }
295
        }
291
 
296
 
292
        public String toXML() {
297
        public String toXML() {
293
                StringBuilder result = new StringBuilder();
298
                StringBuilder result = new StringBuilder();
294
                result.append("<parameterset eepromVersion=\"" + eepromVersion
299
                result.append("<parameterset eepromVersion=\"" + eepromVersion
295
                                + "\" length=\"" + getByteCount() + "\">\n");
300
                                + "\" length=\"" + getByteCount() + "\">\n");
296
                for (int i = 0; i < entries.size(); i++) {
301
                for (int i = 0; i < entries.size(); i++) {
297
                        ConfigEntry entry = entries.get(i);
302
                        ConfigEntry entry = entries.get(i);
298
                        entry.toXML(result);
303
                        entry.toXML(result);
299
                }
304
                }
300
                result.append("</parameterset>\n");
305
                result.append("</parameterset>\n");
301
                return result.toString();
306
                return result.toString();
302
        }
307
        }
303
 
308
 
304
        public ConfigSet(int eepromVersion) {
309
        public ConfigSet(int eepromVersion) {
305
                super();
310
                super();
306
                this.eepromVersion = eepromVersion;
311
                this.eepromVersion = eepromVersion;
307
        }
312
        }
308
 
313
 
309
        // This parses only for the purpose of naming and typing parameter sets!
314
        // This parses only for the purpose of naming and typing parameter sets!
310
        // It does not parse the section and default information, which could be
315
        // It does not parse the section and default information, which could be
311
        // useful for GUIs etc.
316
        // useful for GUIs etc.
312
        public static ConfigSet parseXMLConfigSet(int version) throws IOException {
317
        public static ConfigSet parseXMLConfigSet(int version) throws IOException {
313
                String fileName = "configsets/templates/v" + version + ".xml";
318
                String fileName = "configsets/templates/v" + version + ".xml";
314
                File f = new File(fileName);
319
                File f = new File(fileName);
315
                DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance();
320
                DocumentBuilderFactory saxfac = DocumentBuilderFactory.newInstance();
316
                saxfac.setValidating(false);
321
                saxfac.setValidating(false);
317
                try {
322
                try {
318
                        DocumentBuilder bldr = saxfac.newDocumentBuilder();
323
                        DocumentBuilder bldr = saxfac.newDocumentBuilder();
319
                        Document doc = bldr.parse(f);
324
                        Document doc = bldr.parse(f);
320
                        XPath xpath = XPathFactory.newInstance().newXPath();
325
                        XPath xpath = XPathFactory.newInstance().newXPath();
321
 
326
 
322
                        String s_eepromVersion = xpath.evaluate(
327
                        String s_eepromVersion = xpath.evaluate(
323
                                        "/parametertemplate/@eepromVersion", doc);
328
                                        "/parametertemplate/@eepromVersion", doc);
324
                        int eepromVersion = Integer.parseInt(s_eepromVersion);
329
                        int eepromVersion = Integer.parseInt(s_eepromVersion);
-
 
330
 
-
 
331
                        String s_declaredLength = xpath.evaluate(
-
 
332
                                        "/parametertemplate/@length", doc);
-
 
333
                        int declaredLength = Integer.parseInt(s_declaredLength);
325
 
334
 
326
                        if (eepromVersion != version) {
335
                        if (eepromVersion != version) {
327
                                throw new IOException(
336
                                throw new IOException(
328
                                                "Version mismatch between file name ("
337
                                                "Version mismatch between file name ("
329
                                                                + fileName
338
                                                                + fileName
330
                                                                + ") and the version in the parametertemplate/@eepromVersion attribute("
339
                                                                + ") and the version in the parametertemplate/@eepromVersion attribute("
331
                                                                + s_eepromVersion + ")");
340
                                                                + s_eepromVersion + ")");
332
                        }
341
                        }
333
 
342
 
334
                        ConfigSet result = new ConfigSet(eepromVersion);
343
                        ConfigSet result = new ConfigSet(eepromVersion);
335
 
344
 
336
                        NodeList sectionNodes = (NodeList) xpath.evaluate(
345
                        NodeList sectionNodes = (NodeList) xpath.evaluate(
337
                                        "/parametertemplate/section", doc, XPathConstants.NODESET);
346
                                        "/parametertemplate/section", doc, XPathConstants.NODESET);
338
 
347
 
339
                        for (int i = 0; i < sectionNodes.getLength(); i++) {
348
                        for (int i = 0; i < sectionNodes.getLength(); i++) {
340
                                Element sectionNode = (Element) sectionNodes.item(i);
349
                                Element sectionNode = (Element) sectionNodes.item(i);
341
                                Section section = new Section(sectionNode.getAttribute("name"),
350
                                Section section = new Section(sectionNode.getAttribute("name"),
342
                                                sectionNode.getAttribute("title"));
351
                                                sectionNode.getAttribute("title"));
343
                                result.declaredSections.add(section);
352
                                result.declaredSections.add(section);
344
 
353
 
345
                                NodeList parameterNodes = (NodeList) xpath.evaluate(
354
                                NodeList parameterNodes = (NodeList) xpath.evaluate(
346
                                                "parameter", sectionNode, XPathConstants.NODESET);
355
                                                "parameter", sectionNode, XPathConstants.NODESET);
347
 
356
 
348
                                for (int j = 0; j < parameterNodes.getLength(); j++) {
357
                                for (int j = 0; j < parameterNodes.getLength(); j++) {
349
                                        Element parameterNode = (Element) parameterNodes.item(j);
358
                                        Element parameterNode = (Element) parameterNodes.item(j);
350
 
359
 
351
                                        ConfigEntry entry;
360
                                        ConfigEntry entry;
352
 
361
 
353
                                        if (!sectionNode.hasAttribute("name")) {
362
                                        if (!sectionNode.hasAttribute("name")) {
354
                                                throw new IOException("A parameter element (the " + j
363
                                                throw new IOException("A parameter element (the " + j
355
                                                                + "th in section "
364
                                                                + "th in section "
356
                                                                + sectionNode.getAttribute("name")
365
                                                                + sectionNode.getAttribute("name")
357
                                                                + ") had no name attribute!");
366
                                                                + ") had no name attribute!");
358
                                        }
367
                                        }
359
 
368
 
360
                                        String s_name = parameterNode.getAttribute("name");
369
                                        String s_name = parameterNode.getAttribute("name");
361
                                        String s_type;
370
                                        String s_type;
362
 
371
 
363
                                        if (parameterNode.hasAttribute("type")) {
372
                                        if (parameterNode.hasAttribute("type")) {
364
                                                s_type = parameterNode.getAttribute("type");
373
                                                s_type = parameterNode.getAttribute("type");
365
                                        } else {
374
                                        } else {
366
                                                s_type = "static";
375
                                                s_type = "static";
367
                                        }
376
                                        }
368
 
377
 
369
                                        if ("static".equals(s_type)) {
378
                                        if ("static".equals(s_type)) {
370
                                                entry = new ConfigSet.StaticByteEntry(s_name);
379
                                                entry = new ConfigSet.StaticByteEntry(s_name);
371
                                        } else if ("dynamic".equals(s_type)) {
380
                                        } else if ("dynamic".equals(s_type)) {
372
                                                ConfigSet.DynamicByteEntry de = new ConfigSet.DynamicByteEntry(s_name);
381
                                                ConfigSet.DynamicByteEntry de = new ConfigSet.DynamicByteEntry(s_name);
373
                                                if (parameterNode.hasAttribute("minValue")) {
382
                                                if (parameterNode.hasAttribute("minValue")) {
374
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("minValue")));
383
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("minValue")));
375
                                                }
384
                                                }
376
                                                if (parameterNode.hasAttribute("maxValue")) {
385
                                                if (parameterNode.hasAttribute("maxValue")) {
377
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("maxValue")));
386
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("maxValue")));
378
                                                }
387
                                                }
379
                                                if (parameterNode.hasAttribute("staticCodeName")) {
388
                                                if (parameterNode.hasAttribute("staticCodeName")) {
380
                                                        de.setStaticCodeName(parameterNode.getAttribute("staticCodeName"));
389
                                                        de.setStaticCodeName(parameterNode.getAttribute("staticCodeName"));
381
                                                } else de.setStaticCodeName(de.getName());
390
                                                } else de.setStaticCodeName(de.getName());
382
                                                if (parameterNode.hasAttribute("dynamicCodeName")) {
391
                                                if (parameterNode.hasAttribute("dynamicCodeName")) {
383
                                                        de.setDynamicCodeName(parameterNode.getAttribute("dynamicCodeName"));
392
                                                        de.setDynamicCodeName(parameterNode.getAttribute("dynamicCodeName"));
384
                                                } else de.setDynamicCodeName(de.getName());
393
                                                } else de.setDynamicCodeName(de.getName());
385
                                                entry = de;
394
                                                entry = de;
386
                                        } else if ("bitset".equals(s_type)) {
395
                                        } else if ("bitset".equals(s_type)) {
387
                                                NodeList bitNodes = (NodeList) xpath.evaluate("bit",
396
                                                NodeList bitNodes = (NodeList) xpath.evaluate("bit",
388
                                                                parameterNode, XPathConstants.NODESET);
397
                                                                parameterNode, XPathConstants.NODESET);
389
                                                String[] bitNames = new String[8];
398
                                                String[] bitNames = new String[8];
390
                                                for (int k = 0; k < 8; k++) {
399
                                                for (int k = 0; k < 8; k++) {
391
                                                        Element bitNode = (Element) bitNodes.item(k);
400
                                                        Element bitNode = (Element) bitNodes.item(k);
392
                                                        if (bitNode != null) {
401
                                                        if (bitNode != null) {
393
                                                                bitNames[k] = bitNode.getAttribute("name");
402
                                                                bitNames[k] = bitNode.getAttribute("name");
394
                                                        } else {
403
                                                        } else {
395
                                                                bitNames[k] = "Unused";
404
                                                                bitNames[k] = "Unused";
396
                                                        }
405
                                                        }
397
                                                }
406
                                                }
398
                                                entry = new ConfigSet.BitSetEntry(s_name, bitNames);
407
                                                entry = new ConfigSet.BitSetEntry(s_name, bitNames);
399
                                        } else {
408
                                        } else {
400
                                                throw new IOException("Unknown parameter type: "
409
                                                throw new IOException("Unknown parameter type: "
401
                                                                + s_type);
410
                                                                + s_type);
402
                                        }
411
                                        }
403
 
412
 
404
                                        result.entries.add(entry);
413
                                        result.entries.add(entry);
405
                                        section.addConfigEntry(entry);
414
                                        section.addConfigEntry(entry);
406
                                }
415
                                }
407
                        }
416
                        }
408
                        result.name = "" + version;
417
                        result.name = "" + version;
-
 
418
                        if (result.getByteCount() != declaredLength) {
-
 
419
                                throw new IOException("The number of parameters in the set (" + result.getEntries().size() + ") was not equal to the declared length (" + declaredLength + ").");
-
 
420
                        }
409
                        return result;
421
                        return result;
410
                } catch (IOException ex) {
422
                } catch (IOException ex) {
411
                        throw ex;
423
                        throw ex;
412
                } catch (XPathExpressionException ex) {
424
                } catch (XPathExpressionException ex) {
413
                        throw new IOException(ex);
425
                        throw new IOException(ex);
414
                } catch (SAXException ex) {
426
                } catch (SAXException ex) {
415
                        throw new IOException(ex);
427
                        throw new IOException(ex);
416
                } catch (ParserConfigurationException ex) {
428
                } catch (ParserConfigurationException ex) {
417
                        throw new IOException(ex);
429
                        throw new IOException(ex);
418
                }
430
                }
419
        }
431
        }
420
 
432
 
421
        public String generateDynamicSubstitutionCode() {
433
        public String generateDynamicSubstitutionCode() {
422
                StringBuilder result = new StringBuilder(
434
                StringBuilder result = new StringBuilder(
423
                                "const MMXLATION XLATIONS[] = {\n");
435
                                "const MMXLATION XLATIONS[] = {\n");
424
                boolean hasEntries = false;
436
                boolean hasEntries = false;
425
                for (ConfigEntry entry : entries) {
437
                for (ConfigEntry entry : entries) {
426
                        if (entry instanceof ConfigSet.DynamicByteEntry) {
438
                        if (entry instanceof ConfigSet.DynamicByteEntry) {
427
                                if (hasEntries)
439
                                if (hasEntries)
428
                                        result.append(",\n");
440
                                        result.append(",\n");
429
                                else
441
                                else
430
                                        hasEntries = true;
442
                                        hasEntries = true;
431
                                ConfigSet.DynamicByteEntry de = (ConfigSet.DynamicByteEntry) entry;
443
                                ConfigSet.DynamicByteEntry de = (ConfigSet.DynamicByteEntry) entry;
432
                                result.append("{offsetof(ParamSet_t, ");
444
                                result.append("{offsetof(ParamSet_t, ");
433
                                result.append(de.getStaticCodeName());
445
                                result.append(de.getStaticCodeName());
434
                                result.append("), offsetof(DynamicParams_t, ");
446
                                result.append("), offsetof(DynamicParams_t, ");
435
                                result.append(de.getDynamicCodeName());
447
                                result.append(de.getDynamicCodeName());
436
                                result.append("),");
448
                                result.append("),");
437
                                result.append(Integer.toString(de.getMinValue()));
449
                                result.append(Integer.toString(de.getMinValue()));
438
                                result.append(",");
450
                                result.append(",");
439
                                result.append(Integer.toString(de.getMaxValue()));
451
                                result.append(Integer.toString(de.getMaxValue()));
440
                                result.append("}");
452
                                result.append("}");
441
                        }
453
                        }
442
                }
454
                }
443
                result.append("};");
455
                result.append("};");
444
                return result.toString();
456
                return result.toString();
445
        }
457
        }
446
}
458
}