Subversion Repositories svn.mios

Rev

Rev 727 | 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.HexFileUploadDevice;
7
import org.midibox.mios.HexFileUploadDeviceManager;
8
import org.midibox.utils.xml.XMLUtils;
9
import org.w3c.dom.Element;
10
import org.w3c.dom.Node;
11
 
12
public class HexFileUploadDeviceManagerXML extends XMLUtils {
13
 
722 adamjking 14
    public final static String TAG_ROOT_ELEMENT = "hexFileUploadDeviceManager";
721 adamjking 15
 
722 adamjking 16
    public final static String TAG_HEX_FILE_UPLOAD_DEVICES = "hexFileUploadDevices";
721 adamjking 17
 
727 adamjking 18
    public final static String ATTR_MIOS_32_MODE = "mios32Mode";
19
 
722 adamjking 20
    protected HexFileUploadDeviceManager hexFileUploadDeviceManager;
721 adamjking 21
 
22
    public HexFileUploadDeviceManagerXML(
23
            HexFileUploadDeviceManager hexFileUploadDeviceManager,
24
            String rootElementTag) {
25
 
26
        super(rootElementTag);
27
 
28
        this.hexFileUploadDeviceManager = hexFileUploadDeviceManager;
738 adamjking 29
 
727 adamjking 30
        tags.add(TAG_HEX_FILE_UPLOAD_DEVICES);
31
        tags.add(HexFileUploadDeviceXML.TAG_ROOT_ELEMENT);
721 adamjking 32
    }
33
 
727 adamjking 34
    protected void parseElement(Element element) {
35
 
36
        super.parseElement(element);
37
 
38
        String name = element.getNodeName();
39
 
40
        if (name == rootElementTag) {
41
 
42
            hexFileUploadDeviceManager.setMIOS32Mode(stringToBoolean(element
43
                    .getAttribute(ATTR_MIOS_32_MODE)));
44
 
45
        } else if (name == TAG_HEX_FILE_UPLOAD_DEVICES) {
46
 
47
            Iterator it = ((Vector) hexFileUploadDeviceManager
48
                    .getHexFileUploadDevices().clone()).iterator();
49
 
50
            while (it.hasNext()) {
51
 
52
                HexFileUploadDevice hexFileUploadDevice = (HexFileUploadDevice) it
53
                        .next();
54
 
55
                hexFileUploadDeviceManager
56
                        .removeHexFileUploadDevice(hexFileUploadDevice);
57
            }
58
 
59
        } else if (name == HexFileUploadDeviceXML.TAG_ROOT_ELEMENT) {
60
 
61
            HexFileUploadDevice hexFileUploadDevice = new HexFileUploadDevice(
62
                    element.getAttribute(HexFileUploadDeviceXML.ATTR_NAME));
63
 
64
            HexFileUploadDeviceXML hexFileUploadDeviceXML = new HexFileUploadDeviceXML(
65
                    hexFileUploadDevice,
66
                    HexFileUploadDeviceXML.TAG_ROOT_ELEMENT);
738 adamjking 67
 
68
            hexFileUploadDeviceManager
69
                    .addHexFileUploadDevice(hexFileUploadDevice);
70
 
727 adamjking 71
            hexFileUploadDeviceXML.loadXML(element);
72
        }
73
    }
74
 
721 adamjking 75
    public void saveXML(Node node) {
76
 
77
        super.saveXML(node);
78
 
79
        Element hexFileUploadDevicesElement = document
722 adamjking 80
                .createElement(TAG_HEX_FILE_UPLOAD_DEVICES);
721 adamjking 81
 
727 adamjking 82
        rootElement.setAttribute(ATTR_MIOS_32_MODE,
83
                booleanToString(hexFileUploadDeviceManager.isMIOS32Mode()));
84
 
721 adamjking 85
        rootElement.appendChild(hexFileUploadDevicesElement);
86
 
87
        Iterator it = hexFileUploadDeviceManager.getHexFileUploadDevices()
88
                .iterator();
89
 
90
        while (it.hasNext()) {
91
 
92
            HexFileUploadDevice hexFileUploadDevice = (HexFileUploadDevice) it
93
                    .next();
94
 
95
            HexFileUploadDeviceXML hexFileUploadDeviceXML = new HexFileUploadDeviceXML(
722 adamjking 96
                    hexFileUploadDevice,
97
                    HexFileUploadDeviceXML.TAG_ROOT_ELEMENT);
721 adamjking 98
 
99
            hexFileUploadDeviceXML.saveXML(hexFileUploadDevicesElement);
100
        }
101
    }
709 adamjking 102
}