Remove the Daos interface and have the Application hold the ComponentPresetDao itself...
[debian/openrocket] / core / src / net / sf / openrocket / database / ComponentPresetDao.java
index d76e71df2a3b1daf4ad913b9a73f021cafff8211..0cbdb1b543f43cf3b78f57097382e3e2e80a439e 100644 (file)
@@ -7,22 +7,30 @@ import java.util.List;
 
 import net.sf.openrocket.file.preset.PresetCSVReader;
 import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
+import net.sf.openrocket.preset.TypedPropertyMap;
+import net.sf.openrocket.util.BugException;
 
 public class ComponentPresetDao {
 
        private final List<ComponentPreset> templates = new ArrayList<ComponentPreset>();
 
        // Package scope constructor to control creation pattern.
-       ComponentPresetDao() {}
+       public ComponentPresetDao() {}
        
-       void initialize() throws IOException {
+       public void initialize() throws IOException {
                
                InputStream is = ComponentPresetDao.class.getResourceAsStream("/datafiles/bodytubepresets.csv");
                
                PresetCSVReader parser = new PresetCSVReader(is);
-               List<ComponentPreset> list = parser.parse();
-               for( ComponentPreset preset : list ) {
-                       templates.add(preset);
+               List<TypedPropertyMap> list = parser.parse();
+               for( TypedPropertyMap o : list ) {
+                       try {
+                               ComponentPreset preset = ComponentPreset.create(o);
+                               this.insert(preset);
+                       } catch ( InvalidComponentPresetException ex ) {
+                               throw new BugException( ex );
+                       }
                }
        }
        
@@ -30,4 +38,8 @@ public class ComponentPresetDao {
                return templates;
        }
        
+       public void insert( ComponentPreset preset ) {
+               templates.add(preset);
+       }
+       
 }