package rocketpower.library;

import java.util.logging.Logger;


/*
 * Implements "connection" with exported sync data files.
 */
class PlayerDevice extends RocketDevice {
    /*
     * Read syncdata from given path
     */
    public PlayerDevice(Logger logger, TrackContainer tracks, RocketController controller, String path) {
        super(logger, tracks, controller);

    }

    public void update() {
        // Data loaded; do nothing
        return;
    }


}

@@ -56,16 +56,285 @@
 Logger;%0A
+import java.util.logging.Level;%0A%0Aimport java.io.File;%0Aimport org.w3c.dom.Document;%0Aimport org.w3c.dom.*;%0A%0Aimport javax.xml.parsers.DocumentBuilderFactory;%0Aimport javax.xml.parsers.DocumentBuilder;%0Aimport org.xml.sax.SAXException;%0Aimport org.xml.sax.SAXParseException; %0A
 %0A%0A/*%0A * 
@@ -589,16 +589,33 @@
 ng path)
+ throws Exception
  %7B%0A     
@@ -653,16 +653,1976 @@
 ller);%0A%0A
+        try %7B%0A            // This can throw if reading fails%0A            readAndLoadTracks(path);%0A        %7D catch (Exception e) %7B%0A            close();%0A            throw e;%0A        %7D%0A%0A        // All good; start controller%0A        controller.play();%0A    %7D%0A%0A    /**%0A     * Loads syncdata from Rocket's project file at given path%0A     */%0A    private void readAndLoadTracks(String path) throws Exception %7B%0A        logger.info(%22Loading tracks from '%22 + path + %22'.%22);%0A%0A        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();%0A        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();%0A        Document doc = docBuilder.parse(new File(path));%0A%0A        NodeList trackList = doc.getElementsByTagName(%22track%22);%0A        int totalTracks = trackList.getLength();%0A        logger.finer(%22Total number of tracks: %22 + totalTracks);%0A%0A        // Read all tracks%0A        for(int s = 0; s %3C totalTracks; s++)%7B%0A            Element trackElement = (Element)trackList.item(s);%0A            NodeList keyList = trackElement.getElementsByTagName(%22key%22);%0A%0A            if (keyList.getLength() %3E 0) %7B%0A                // Create new track%0A                Track track = tracks.getOrCreate(trackElement.getAttribute(%22name%22));%0A                int totalKeys = keyList.getLength();%0A%0A                logger.finest(%22Loading track (name=%22 + trackElement.getAttribute(%22name%22) +%0A                        %22 keys=%22 + totalKeys + %22)%22);%0A%0A                // Add all found keys%0A                for (int i = 0; i %3C keyList.getLength(); i++) %7B%0A                    Element key = (Element)keyList.item(i);%0A%0A                    int row = Integer.parseInt(key.getAttribute(%22row%22));%0A                    float value = Float.parseFloat(key.getAttribute(%22value%22));%0A                    int keyType = Integer.parseInt(key.getAttribute(%22interpolation%22));%0A%0A                    track.addOrUpdateKey(new TrackKey(row, value, keyType));%0A                %7D%0A%0A            %7D%0A        %7D%0A
     %7D%0A%0A 

Implement PlayerDevice (reads syncdata from Rocket's project file)