Subversion Repositories svn.mios

Rev

Rev 722 | Rev 738 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
709 adamjking 1
package org.midibox.mios.xml;
2
 
721 adamjking 3
import java.util.Iterator;
727 adamjking 4
import java.util.Vector;
709 adamjking 5
 
721 adamjking 6
import org.midibox.mios.DebugFunction;
7
import org.midibox.mios.DebugFunctionParameters;
8
import org.w3c.dom.Element;
9
import org.w3c.dom.Node;
727 adamjking 10
import org.w3c.dom.NodeList;
721 adamjking 11
 
12
public class DebugFunctionXML extends MIOSSysexSendReceiveXML {
13
 
14
    protected DebugFunction debugFunction;
15
 
722 adamjking 16
    public final static String TAG_ROOT_ELEMENT = "debugFunction";
721 adamjking 17
 
722 adamjking 18
    public static final String TAG_DEBUG_FUNCTION_PARAMETERS_LIST = "debugFunctionParametersList";
721 adamjking 19
 
722 adamjking 20
    public static final String ATTR_MODE = "mode";
721 adamjking 21
 
722 adamjking 22
    public static final String ATTR_DELAY_TIME = "delayTime";
721 adamjking 23
 
722 adamjking 24
    public static final String ATTR_SRAM_READ_ADDRESS = "sramReadAddress";
721 adamjking 25
 
722 adamjking 26
    public static final String ATTR_SRAM_READ_COUNTER = "sramReadCounter";
721 adamjking 27
 
722 adamjking 28
    public static final String ATTR_SRAM_WRITE_ADDRESS = "sramWriteAddress";
721 adamjking 29
 
722 adamjking 30
    public static final String ATTR_SRAM_WRITE_DATA = "sramWriteData";
721 adamjking 31
 
32
    public DebugFunctionXML(DebugFunction debugFunction, String rootElementTag) {
33
 
34
        super(debugFunction, rootElementTag);
35
 
36
        this.debugFunction = debugFunction;
727 adamjking 37
 
38
        tags.add(TAG_DEBUG_FUNCTION_PARAMETERS_LIST);
721 adamjking 39
    }
40
 
727 adamjking 41
    protected void parseElement(Element element) {
42
 
43
        super.parseElement(element);
44
 
45
        String name = element.getNodeName();
46
 
47
        if (name == rootElementTag) {
48
 
49
            debugFunction.setDeviceID(stringToInt(element
50
                    .getAttribute(ATTR_DEVICE_ID)));
51
 
52
            debugFunction.setMIOS32Mode(stringToBoolean(element
53
                    .getAttribute(ATTR_MIOS32_MODE)));
54
 
55
            debugFunction.setMode(stringToInt(element.getAttribute(ATTR_MODE)));
56
 
57
            debugFunction.setDelayTime(stringToInt(element
58
                    .getAttribute(ATTR_DELAY_TIME)));
59
 
60
            debugFunction.setSramReadAddress(stringToInt(element
61
                    .getAttribute(ATTR_SRAM_READ_ADDRESS)));
62
 
63
            debugFunction.setSramReadCounter(stringToInt(element
64
                    .getAttribute(ATTR_SRAM_READ_COUNTER)));
65
 
66
            debugFunction.setSramWriteAddress(stringToInt(element
67
                    .getAttribute(ATTR_SRAM_WRITE_ADDRESS)));
68
 
69
            debugFunction.setSramWriteData(stringToInt(element
70
                    .getAttribute(ATTR_SRAM_WRITE_DATA)));
71
 
72
        } else if (name == TAG_DEBUG_FUNCTION_PARAMETERS_LIST) {
73
 
74
            debugFunction.getDebugFunctionParameters().removeAllElements();
75
 
76
            NodeList children = element.getChildNodes();
77
 
78
            DebugFunctionParameters[] params = new DebugFunctionParameters[children.getLength()];
79
 
80
            for (int p = 0; p < children.getLength(); p++) {
81
 
82
                DebugFunctionParameters debugFunctionParameters = new DebugFunctionParameters();
83
 
84
                DebugFunctionParametersXML debugFunctionParametersXML = new DebugFunctionParametersXML(
85
                        debugFunctionParameters,
86
                        DebugFunctionParametersXML.TAG_ROOT_ELEMENT);
87
 
88
                debugFunctionParametersXML.loadXML(children.item(p));
89
 
90
                params[p] = debugFunctionParameters;
91
            }
92
 
93
            debugFunction.insertDebugFunctionParameters(params, 0);
94
        }
95
    }
96
 
721 adamjking 97
    public void saveXML(Node node) {
98
 
99
        super.saveXML(node);
100
 
722 adamjking 101
        rootElement.setAttribute(ATTR_MODE,
102
                intToString(debugFunction.getMode()));
721 adamjking 103
 
722 adamjking 104
        rootElement.setAttribute(ATTR_DELAY_TIME, intToString(debugFunction
105
                .getDelayTime()));
721 adamjking 106
 
722 adamjking 107
        rootElement.setAttribute(ATTR_SRAM_READ_ADDRESS,
108
                intToString(debugFunction.getSramReadAddress()));
721 adamjking 109
 
722 adamjking 110
        rootElement.setAttribute(ATTR_SRAM_READ_COUNTER,
111
                intToString(debugFunction.getSramReadCounter()));
721 adamjking 112
 
722 adamjking 113
        rootElement.setAttribute(ATTR_SRAM_WRITE_ADDRESS,
114
                intToString(debugFunction.getSramWriteAddress()));
721 adamjking 115
 
722 adamjking 116
        rootElement.setAttribute(ATTR_SRAM_WRITE_DATA,
117
                intToString(debugFunction.getSramWriteData()));
721 adamjking 118
 
722 adamjking 119
        Element debugFunctionParametersListElement = document
120
                .createElement(TAG_DEBUG_FUNCTION_PARAMETERS_LIST);
721 adamjking 121
 
722 adamjking 122
        rootElement.appendChild(debugFunctionParametersListElement);
721 adamjking 123
 
124
        Iterator it = debugFunction.getDebugFunctionParameters().iterator();
125
 
126
        while (it.hasNext()) {
127
 
128
            DebugFunctionParameters debugFunctionParameters = (DebugFunctionParameters) it
129
                    .next();
130
 
131
            DebugFunctionParametersXML debugFunctionParametersXML = new DebugFunctionParametersXML(
722 adamjking 132
                    debugFunctionParameters,
133
                    DebugFunctionParametersXML.TAG_ROOT_ELEMENT);
721 adamjking 134
 
722 adamjking 135
            debugFunctionParametersXML
136
                    .saveXML(debugFunctionParametersListElement);
721 adamjking 137
        }
138
    }
709 adamjking 139
}