diff --git a/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java b/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java index 2c07d890d..b646f7f77 100644 --- a/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/BaseComponentDTO.java @@ -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; + @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() { - } + /** + * 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)); - } - } + /** + * 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 String getManufacturer() { + return manufacturer; + } - public void setManufacturer(final String theManufacturer) { - manufacturer = theManufacturer; - } + public void setManufacturer(final String theManufacturer) { + manufacturer = theManufacturer; + } - public String getPartNo() { - return partNo; - } + public String getPartNo() { + return partNo; + } - public void setPartNo(final String thePartNo) { - partNo = thePartNo; - } + public void setPartNo(final String thePartNo) { + partNo = thePartNo; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(final String theDescription) { - description = theDescription; - } + public void setDescription(final String theDescription) { + description = theDescription; + } - public AnnotatedMaterialDTO getMaterial() { - return material; - } + public AnnotatedMaterialDTO getMaterial() { + return material; + } - public void setMaterial(final AnnotatedMaterialDTO theMaterial) { - material = theMaterial; - } + public void setMaterial(final AnnotatedMaterialDTO theMaterial) { + material = theMaterial; + } - public double getMass() { - return mass; - } + public double getMass() { + return mass; + } - public void setMass(final double theMass) { - mass = theMass; - } + public void setMass(final double theMass) { + mass = theMass; + } - public abstract ComponentPreset asComponentPreset(List materials) throws InvalidComponentPresetException; + public Boolean getFilled() { + return filled; + } - void addProps(TypedPropertyMap props, List 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); - } + public void setFilled(Boolean filled) { + this.filled = filled; + } - private Material find(List 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); - } + public abstract ComponentPreset asComponentPreset(List materials) throws InvalidComponentPresetException; - static class AnnotatedMaterialDTO { - @XmlAttribute(name = "Type") - private String type; - @XmlValue - private String material; + void addProps(TypedPropertyMap props, List 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); + } + } - AnnotatedMaterialDTO() {} + private Material find(List 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); + } - AnnotatedMaterialDTO(Material theMaterial) { - type = theMaterial.getType().name(); - material = theMaterial.getName(); - } - } + static class AnnotatedMaterialDTO { + @XmlAttribute(name = "Type") + private String type; + @XmlValue + private String material; + + AnnotatedMaterialDTO() {} + + AnnotatedMaterialDTO(Material theMaterial) { + type = theMaterial.getType().name(); + material = theMaterial.getName(); + } + } }