committed Doug's Rocksim loader
[debian/openrocket] / src / net / sf / openrocket / file / rocksim / RocksimLoader.java
1 /*
2  * RocksimLoader.java
3  */
4 package net.sf.openrocket.file.rocksim;
5
6 import net.sf.openrocket.file.RocketLoader;
7 import net.sf.openrocket.file.RocketLoadException;
8 import net.sf.openrocket.file.simplesax.SimpleSAX;
9 import net.sf.openrocket.document.OpenRocketDocument;
10
11 import java.io.InputStream;
12 import java.io.IOException;
13
14 import org.xml.sax.InputSource;
15 import org.xml.sax.SAXException;
16
17 /**
18  * This class is the main entry point for Rocksim design file imported to OpenRocket.  Currently only Rocksim v9
19  * file formats are supported, although it is possible that v8 formats will work for most components.
20  * 
21  * In the cases of v9 components that exist in Rocksim but have no corollary in OpenRocket a message is added to
22  * a warning set and presented to the user.  In effect, this loading is a 'best-effort' mapping and is not meant to
23  * be an exact representation of any possible Rocksim design in an OpenRocket format.
24  * 
25  * Rocksim simulations are not imported.
26  * 
27  * Wish List:
28  *       Material interface (or at least make them abstract in RocketComponent)
29  *          setMaterial
30  *          getMaterial
31  */
32 public class RocksimLoader extends RocketLoader {
33     /**
34      * This method is called by the default implementations of {@link #load(java.io.File)}
35      * and {@link #load(java.io.InputStream)} to load the rocket.
36      *
37      * @throws net.sf.openrocket.file.RocketLoadException
38      *          if an error occurs during loading.
39      */
40     @Override 
41     protected OpenRocketDocument loadFromStream(InputStream source) throws IOException, RocketLoadException {
42
43         InputSource xmlSource = new InputSource(source);
44
45         RocksimHandler handler = new RocksimHandler();
46                 
47         try {
48             SimpleSAX.readXML(xmlSource, handler, warnings);
49         } catch (SAXException e) {
50             throw new RocketLoadException("Malformed XML in input.", e);
51         }
52
53         final OpenRocketDocument document = handler.getDocument();
54         document.setFile(null);
55         return document;
56     }
57 }