]> git.gag.com Git - debian/openrocket/commitdiff
Added filled property. Made Filled and Mass optional by using objects instead of...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 26 Apr 2012 18:18:00 +0000 (18:18 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 26 Apr 2012 18:18:00 +0000 (18:18 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@616 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java

index 2c07d890d66286f4783b7518000fad5a6ca79251..b646f7f7790d1b5ddb32a10c52476c9b44231f5c 100644 (file)
@@ -21,112 +21,139 @@ import java.util.List;
 @XmlAccessorType(XmlAccessType.FIELD)
 public abstract class BaseComponentDTO {
 
-    @XmlElement(name = "Manufacturer")
-    private String manufacturer;
-    @XmlElement(name = "PartNumber")
-    private String partNo;
-    @XmlElement(name = "Description")
-    private String description;
-    @XmlElement(name = "Material")
-    private AnnotatedMaterialDTO material;
-    @XmlElement(name = "Mass")
-    private double mass;
-
-    /**
-     * Default constructor.
-     */
-    protected BaseComponentDTO() {
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param preset  the preset to use to pull data values out of
-     *
-     * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
-     */
-    protected BaseComponentDTO(final ComponentPreset preset) {
-        setManufacturer(preset.getManufacturer().getSimpleName());
-        setPartNo(preset.getPartNo());
-        setDescription(preset.get(ComponentPreset.DESCRIPTION));
-        setMaterial(new AnnotatedMaterialDTO(preset.get(ComponentPreset.MATERIAL)));
-        if (preset.has(ComponentPreset.MASS)) {
-            setMass(preset.get(ComponentPreset.MASS));
-        }
-    }
-
-    public String getManufacturer() {
-        return manufacturer;
-    }
-
-    public void setManufacturer(final String theManufacturer) {
-        manufacturer = theManufacturer;
-    }
-
-    public String getPartNo() {
-        return partNo;
-    }
-
-    public void setPartNo(final String thePartNo) {
-        partNo = thePartNo;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(final String theDescription) {
-        description = theDescription;
-    }
-
-    public AnnotatedMaterialDTO getMaterial() {
-        return material;
-    }
-
-    public void setMaterial(final AnnotatedMaterialDTO theMaterial) {
-        material = theMaterial;
-    }
-
-    public double getMass() {
-        return mass;
-    }
-
-    public void setMass(final double theMass) {
-        mass = theMass;
-    }
-
-    public abstract ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException;
-
-    void addProps(TypedPropertyMap props, List<MaterialDTO> materialList) {
-        props.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer(manufacturer));
-        props.put(ComponentPreset.PARTNO, partNo);
-        props.put(ComponentPreset.DESCRIPTION, description);
-        props.put(ComponentPreset.MATERIAL, find(materialList, material));
-        props.put(ComponentPreset.MASS, mass);
-    }
-
-    private Material find(List<MaterialDTO> materialList, AnnotatedMaterialDTO dto) {
-        for (int i = 0; i < materialList.size(); i++) {
-            MaterialDTO materialDTO =  materialList.get(i);
-            if (materialDTO.getType().name().equals(dto.type) && materialDTO.getName().equals(dto.material)) {
-                return materialDTO.asMaterial();
-            }
-        }
-        //Otherwise fallback and look at factory default materials.
-        return Databases.findMaterial(Material.Type.valueOf(material.type), material.material);
-    }
-
-    static class AnnotatedMaterialDTO {
-        @XmlAttribute(name = "Type")
-        private String type;
-        @XmlValue
-        private String material;
-
-        AnnotatedMaterialDTO() {}
-
-        AnnotatedMaterialDTO(Material theMaterial) {
-            type = theMaterial.getType().name();
-            material = theMaterial.getName();
-        }
-    }
+       @XmlElement(name = "Manufacturer")
+       private String manufacturer;
+       @XmlElement(name = "PartNumber")
+       private String partNo;
+       @XmlElement(name = "Description")
+       private String description;
+       @XmlElement(name = "Material")
+       private AnnotatedMaterialDTO material;
+       @XmlElement(name = "Mass")
+       private Double mass;
+       @XmlElement(name="Filled")
+       private Boolean filled;
+
+       /**
+        * Default constructor.
+        */
+       protected BaseComponentDTO() {
+       }
+
+       /**
+        * Constructor.
+        *
+        * @param preset  the preset to use to pull data values out of
+        *
+        * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
+        */
+       protected BaseComponentDTO(final ComponentPreset preset) {
+               setManufacturer(preset.getManufacturer().getSimpleName());
+               setPartNo(preset.getPartNo());
+               if ( preset.has(ComponentPreset.DESCRIPTION )) {
+                       setDescription(preset.get(ComponentPreset.DESCRIPTION));
+               }
+               if ( preset.has(ComponentPreset.MATERIAL)) {
+                       setMaterial(new AnnotatedMaterialDTO(preset.get(ComponentPreset.MATERIAL)));
+               }
+               if (preset.has(ComponentPreset.MASS)) {
+                       setMass(preset.get(ComponentPreset.MASS));
+               }
+               if ( preset.has(ComponentPreset.FILLED) ) {
+                       setFilled( preset.get(ComponentPreset.FILLED));
+               }
+       }
+
+       public String getManufacturer() {
+               return manufacturer;
+       }
+
+       public void setManufacturer(final String theManufacturer) {
+               manufacturer = theManufacturer;
+       }
+
+       public String getPartNo() {
+               return partNo;
+       }
+
+       public void setPartNo(final String thePartNo) {
+               partNo = thePartNo;
+       }
+
+       public String getDescription() {
+               return description;
+       }
+
+       public void setDescription(final String theDescription) {
+               description = theDescription;
+       }
+
+       public AnnotatedMaterialDTO getMaterial() {
+               return material;
+       }
+
+       public void setMaterial(final AnnotatedMaterialDTO theMaterial) {
+               material = theMaterial;
+       }
+
+       public double getMass() {
+               return mass;
+       }
+
+       public void setMass(final double theMass) {
+               mass = theMass;
+       }
+
+       public Boolean getFilled() {
+               return filled;
+       }
+
+       public void setFilled(Boolean filled) {
+               this.filled = filled;
+       }
+
+       public abstract ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException;
+
+       void addProps(TypedPropertyMap props, List<MaterialDTO> materialList) {
+               props.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer(manufacturer));
+               props.put(ComponentPreset.PARTNO, partNo);
+               if ( description != null ) {
+                       props.put(ComponentPreset.DESCRIPTION, description);
+               }
+               Material m = find(materialList, material);
+               if ( m != null ) {
+                       props.put(ComponentPreset.MATERIAL, find(materialList, material));
+               }
+               if ( mass != null ) {
+                       props.put(ComponentPreset.MASS, mass);
+               }
+               if ( filled != null ) {
+                       props.put(ComponentPreset.FILLED, filled);
+               }
+       }
+
+       private Material find(List<MaterialDTO> materialList, AnnotatedMaterialDTO dto) {
+               for (int i = 0; i < materialList.size(); i++) {
+                       MaterialDTO materialDTO =  materialList.get(i);
+                       if (materialDTO.getType().name().equals(dto.type) && materialDTO.getName().equals(dto.material)) {
+                               return materialDTO.asMaterial();
+                       }
+               }
+               //Otherwise fallback and look at factory default materials.
+               return Databases.findMaterial(Material.Type.valueOf(material.type), material.material);
+       }
+
+       static class AnnotatedMaterialDTO {
+               @XmlAttribute(name = "Type")
+               private String type;
+               @XmlValue
+               private String material;
+
+               AnnotatedMaterialDTO() {}
+
+               AnnotatedMaterialDTO(Material theMaterial) {
+                       type = theMaterial.getType().name();
+                       material = theMaterial.getName();
+               }
+       }
 }