Subversion Repositories svn.mios

Rev

Rev 727 | 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;
709 adamjking 4
 
721 adamjking 5
import org.midibox.mios.DebugFunction;
6
import org.midibox.mios.DebugFunctionParameters;
7
import org.w3c.dom.Element;
8
import org.w3c.dom.Node;
727 adamjking 9
import org.w3c.dom.NodeList;
721 adamjking 10
 
11
public class DebugFunctionXML extends MIOSSysexSendReceiveXML {
12
 
13
    protected DebugFunction debugFunction;
14
 
722 adamjking 15
    public final static String TAG_ROOT_ELEMENT = "debugFunction";
721 adamjking 16
 
722 adamjking 17
    public static final String TAG_DEBUG_FUNCTION_PARAMETERS_LIST = "debugFunctionParametersList";
721 adamjking 18
 
722 adamjking 19
    public static final String ATTR_MODE = "mode";
721 adamjking 20
 
722 adamjking 21
    public static final String ATTR_DELAY_TIME = "delayTime";
721 adamjking 22
 
722 adamjking 23
    public static final String ATTR_SRAM_READ_ADDRESS = "sramReadAddress";
721 adamjking 24
 
722 adamjking 25
    public static final String ATTR_SRAM_READ_COUNTER = "sramReadCounter";
721 adamjking 26
 
722 adamjking 27
    public static final String ATTR_SRAM_WRITE_ADDRESS = "sramWriteAddress";
721 adamjking 28
 
722 adamjking 29
    public static final String ATTR_SRAM_WRITE_DATA = "sramWriteData";
721 adamjking 30
 
31
    public DebugFunctionXML(DebugFunction debugFunction, String rootElementTag) {
32
 
33
        super(debugFunction, rootElementTag);
34
 
35
        this.debugFunction = debugFunction;
727 adamjking 36
 
37
        tags.add(TAG_DEBUG_FUNCTION_PARAMETERS_LIST);
721 adamjking 38
    }
39
 
727 adamjking 40
    protected void parseElement(Element element) {
41
 
42
        super.parseElement(element);
43
 
44
        String name = element.getNodeName();
45
 
46
        if (name == rootElementTag) {
47
 
48
            debugFunction.setDeviceID(stringToInt(element
49
                    .getAttribute(ATTR_DEVICE_ID)));
50
 
51
            debugFunction.setMIOS32Mode(stringToBoolean(element
52
                    .getAttribute(ATTR_MIOS32_MODE)));
53
 
54
            debugFunction.setMode(stringToInt(element.getAttribute(ATTR_MODE)));
55
 
56
            debugFunction.setDelayTime(stringToInt(element
57
                    .getAttribute(ATTR_DELAY_TIME)));
58
 
59
            debugFunction.setSramReadAddress(stringToInt(element
60
                    .getAttribute(ATTR_SRAM_READ_ADDRESS)));
61
 
62
            debugFunction.setSramReadCounter(stringToInt(element
63
                    .getAttribute(ATTR_SRAM_READ_COUNTER)));
64
 
65
            debugFunction.setSramWriteAddress(stringToInt(element
66
                    .getAttribute(ATTR_SRAM_WRITE_ADDRESS)));
67
 
68
            debugFunction.setSramWriteData(stringToInt(element
69
                    .getAttribute(ATTR_SRAM_WRITE_DATA)));
70
 
71
        } else if (name == TAG_DEBUG_FUNCTION_PARAMETERS_LIST) {
72
 
73
            debugFunction.getDebugFunctionParameters().removeAllElements();
738 adamjking 74
 
727 adamjking 75
            NodeList children = element.getChildNodes();
738 adamjking 76
 
77
            DebugFunctionParameters[] params = new DebugFunctionParameters[children
78
                    .getLength()];
79
 
727 adamjking 80
            for (int p = 0; p < children.getLength(); p++) {
738 adamjking 81
 
727 adamjking 82
                DebugFunctionParameters debugFunctionParameters = new DebugFunctionParameters();
738 adamjking 83
 
727 adamjking 84
                DebugFunctionParametersXML debugFunctionParametersXML = new DebugFunctionParametersXML(
85
                        debugFunctionParameters,
86
                        DebugFunctionParametersXML.TAG_ROOT_ELEMENT);
738 adamjking 87
 
727 adamjking 88
                debugFunctionParametersXML.loadXML(children.item(p));
738 adamjking 89
 
727 adamjking 90
                params[p] = debugFunctionParameters;
91
            }
738 adamjking 92
 
727 adamjking 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
}