Subversion Repositories svn.mios

Rev

Rev 808 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
808 adamjking 1
package org.midibox.midi.xml;
2
 
3
import java.util.Iterator;
4
import java.util.Vector;
5
 
6
import org.midibox.midi.SysexSendReceive;
7
import org.midibox.midi.SysexSendReceiveManager;
8
import org.midibox.utils.xml.XMLUtils;
9
import org.w3c.dom.Element;
10
import org.w3c.dom.Node;
11
 
12
public class SysexSendReceiveManagerXML extends XMLUtils {
13
 
850 adamjking 14
    public final static String TAG_ROOT_ELEMENT = "sysexSendReceiveManager";
808 adamjking 15
 
850 adamjking 16
    public final static String TAG_SYSEX_SEND_RECEIVES = "sysexSendReceives";
808 adamjking 17
 
18
    protected SysexSendReceiveManager sysexSendReceiveManager;
19
 
20
    public SysexSendReceiveManagerXML(
21
            SysexSendReceiveManager sysexSendReceiveManager,
22
            String rootElementTag) {
23
 
24
        super(rootElementTag);
25
 
26
        this.sysexSendReceiveManager = sysexSendReceiveManager;
27
 
850 adamjking 28
        addTag(TAG_SYSEX_SEND_RECEIVES);
808 adamjking 29
        addTag(SysexSendReceiveXML.TAG_ROOT_ELEMENT);
30
    }
31
 
32
    protected void parseElement(Element element) {
33
 
34
        super.parseElement(element);
35
 
36
        String name = element.getNodeName();
37
 
38
        if (name == rootElementTag) {
39
 
850 adamjking 40
        } else if (name == TAG_SYSEX_SEND_RECEIVES) {
808 adamjking 41
 
42
            Iterator it = ((Vector) sysexSendReceiveManager
43
                    .getSysexSendReceives().clone()).iterator();
44
 
45
            while (it.hasNext()) {
46
 
47
                SysexSendReceive sysexSendReceive = (SysexSendReceive) it
48
                        .next();
49
 
50
                sysexSendReceiveManager
51
                        .removeSysexSendReceive(sysexSendReceive);
52
            }
53
 
54
        } else if (name == SysexSendReceiveXML.TAG_ROOT_ELEMENT) {
55
 
56
            SysexSendReceive sysexSendReceive = new SysexSendReceive(null);
57
 
58
            SysexSendReceiveXML sysexSendReceiveXML = new SysexSendReceiveXML(
59
                    sysexSendReceive, SysexSendReceiveXML.TAG_ROOT_ELEMENT);
60
 
850 adamjking 61
            sysexSendReceiveManager.addSysexSendReceive(sysexSendReceive);
808 adamjking 62
 
63
            sysexSendReceiveXML.loadXML(element);
64
        }
65
    }
66
 
67
    public void saveXML(Node node) {
68
 
69
        super.saveXML(node);
70
 
71
        Element hexFileUploadDevicesElement = document
850 adamjking 72
                .createElement(TAG_SYSEX_SEND_RECEIVES);
808 adamjking 73
 
74
        rootElement.appendChild(hexFileUploadDevicesElement);
75
 
76
        Iterator it = sysexSendReceiveManager.getSysexSendReceives().iterator();
77
 
78
        while (it.hasNext()) {
79
 
80
            SysexSendReceive sysexSendReceive = (SysexSendReceive) it.next();
81
 
82
            SysexSendReceiveXML sysexSendReceiveXML = new SysexSendReceiveXML(
83
                    sysexSendReceive, SysexSendReceiveXML.TAG_ROOT_ELEMENT);
84
 
85
            sysexSendReceiveXML.saveXML(hexFileUploadDevicesElement);
86
        }
87
    }
88
}