package net.sf.openrocket.preset.xml;
-import net.sf.openrocket.database.Databases;
-import net.sf.openrocket.material.Material;
-import net.sf.openrocket.motor.Manufacturer;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.InvalidComponentPresetException;
-import net.sf.openrocket.preset.TypedPropertyMap;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlValue;
-import java.util.List;
+
+import net.sf.openrocket.database.Databases;
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.motor.Manufacturer;
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
+import net.sf.openrocket.preset.TypedPropertyMap;
+import net.sf.openrocket.unit.UnitGroup;
/**
* Base class for the external representation of all component presets.
@XmlElement(name = "Material")
private AnnotatedMaterialDTO material;
@XmlElement(name = "Mass")
- private Double mass;
+ private AnnotatedMassDTO mass;
@XmlElement(name="Filled")
private Boolean filled;
}
public double getMass() {
- return mass;
+ return mass.getValue();
}
- public void setMass(final double theMass) {
+ public void setMass(final AnnotatedMassDTO theMass) {
mass = theMass;
}
+ public void setMass(final double theMass) {
+ mass = new AnnotatedMassDTO(theMass);
+ }
+
public Boolean getFilled() {
return filled;
}
props.put(ComponentPreset.MATERIAL, find(materialList, material));
}
if ( mass != null ) {
- props.put(ComponentPreset.MASS, mass);
+ props.put(ComponentPreset.MASS, getMass());
}
if ( filled != null ) {
- props.put(ComponentPreset.FILLED, filled);
+ props.put(ComponentPreset.FILLED, getFilled());
}
}
material = theMaterial.getName();
}
}
+
+ static class AnnotatedLengthDTO {
+ @XmlAttribute(name="Unit", required=false)
+ private String unitName = "m";
+ @XmlValue
+ private double length;
+
+ AnnotatedLengthDTO() {}
+
+ AnnotatedLengthDTO( double length ) {
+ this.length = length;
+ }
+
+ public double getValue() {
+ return UnitGroup.UNITS_LENGTH.getUnit(unitName).fromUnit(length);
+ }
+ }
+
+ static class AnnotatedMassDTO {
+ @XmlAttribute(name="Unit", required=false)
+ private String unitName = "kg";
+ @XmlValue
+ private double mass;
+
+ AnnotatedMassDTO() {}
+
+ AnnotatedMassDTO( double mass ) {
+ this.mass = mass;
+ }
+
+ public double getValue() {
+ return UnitGroup.UNITS_MASS.getUnit(unitName).fromUnit(mass);
+ }
+ }
}
public class BodyTubeDTO extends BaseComponentDTO {
@XmlElement(name = "InsideDiameter")
- private double insideDiameter;
+ private AnnotatedLengthDTO insideDiameter;
@XmlElement(name = "OutsideDiameter")
- private double outsideDiameter;
+ private AnnotatedLengthDTO outsideDiameter;
@XmlElement(name = "Length")
- private double length;
+ private AnnotatedLengthDTO length;
/**
* Default constructor.
}
public double getInsideDiameter() {
- return insideDiameter;
+ return insideDiameter.getValue();
}
+ public void setInsideDiameter( final AnnotatedLengthDTO theLength ) {
+ insideDiameter = theLength;
+ }
+
public void setInsideDiameter(final double theId) {
- insideDiameter = theId;
+ insideDiameter = new AnnotatedLengthDTO(theId);
}
public double getOutsideDiameter() {
- return outsideDiameter;
+ return outsideDiameter.getValue();
}
- public void setOutsideDiameter(final double theOd) {
+ public void setOutsideDiameter(final AnnotatedLengthDTO theOd) {
outsideDiameter = theOd;
}
+ public void setOutsideDiameter(final double theOd) {
+ outsideDiameter = new AnnotatedLengthDTO(theOd);
+ }
+
public double getLength() {
- return length;
+ return length.getValue();
}
- public void setLength(final double theLength) {
+ public void setLength(final AnnotatedLengthDTO theLength) {
length = theLength;
}
+ public void setLength(final double theLength) {
+ length = new AnnotatedLengthDTO(theLength);
+ }
+
+ @Override
public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
return asComponentPreset(ComponentPreset.Type.BODY_TUBE, materials);
}
public class BulkHeadDTO extends BaseComponentDTO {
@XmlElement(name = "OutsideDiameter")
- private double outsideDiameter;
+ private AnnotatedLengthDTO outsideDiameter;
@XmlElement(name = "Length")
- private double length;
+ private AnnotatedLengthDTO length;
public BulkHeadDTO() {
}
}
public double getOutsideDiameter() {
- return outsideDiameter;
+ return outsideDiameter.getValue();
}
- public void setOutsideDiameter(final double theOutsideDiameter) {
+ public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
outsideDiameter = theOutsideDiameter;
}
+ public void setOutsideDiameter(final double theOutsideDiameter) {
+ outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
+ }
+
public double getLength() {
- return length;
+ return length.getValue();
}
- public void setLength(final double theLength) {
+ public void setLength(final AnnotatedLengthDTO theLength) {
length = theLength;
}
+ public void setLength(final double theLength) {
+ length = new AnnotatedLengthDTO(theLength);
+ }
+
+ @Override
public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
TypedPropertyMap props = new TypedPropertyMap();
addProps(props, materials);
package net.sf.openrocket.preset.xml;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.ComponentPresetFactory;
-import net.sf.openrocket.preset.InvalidComponentPresetException;
-import net.sf.openrocket.preset.TypedPropertyMap;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import java.util.List;
+
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
/**
- * Centering ring preset XML handler.
+ * Centering Ring preset XML handler.
*/
@XmlRootElement(name = "CenteringRing")
@XmlAccessorType(XmlAccessType.FIELD)
-public class CenteringRingDTO extends BaseComponentDTO {
-
- @XmlElement(name = "InsideDiameter")
- private double insideDiameter;
- @XmlElement(name = "OutsideDiameter")
- private double outsideDiameter;
- @XmlElement(name = "Length")
- private double length;
+public class CenteringRingDTO extends BodyTubeDTO {
/**
* Default constructor.
}
/**
- * Most-useful constructor that maps a CenteringRing preset to a CenteringRingDTO.
+ * Most-useful constructor that maps a TubeCoupler preset to a TubeCouplerDTO.
*
* @param thePreset the preset
*
- * @throws net.sf.openrocket.util.BugException thrown if the expected centering ring keys are not in the preset
+ * @throws net.sf.openrocket.util.BugException thrown if the expected tube coupler keys are not in the preset
*/
- public CenteringRingDTO(final ComponentPreset thePreset) {
+ public CenteringRingDTO(ComponentPreset thePreset) {
super(thePreset);
- setInsideDiameter(thePreset.get(ComponentPreset.INNER_DIAMETER));
- setOutsideDiameter(thePreset.get(ComponentPreset.OUTER_DIAMETER));
- setLength(thePreset.get(ComponentPreset.LENGTH));
- }
-
- public double getInsideDiameter() {
- return insideDiameter;
- }
-
- public void setInsideDiameter(final double theInsideDiameter) {
- insideDiameter = theInsideDiameter;
- }
-
- public double getOutsideDiameter() {
- return outsideDiameter;
- }
-
- public void setOutsideDiameter(final double theOutsideDiameter) {
- outsideDiameter = theOutsideDiameter;
- }
-
- public double getLength() {
- return length;
- }
-
- public void setLength(final double theLength) {
- length = theLength;
}
+ @Override
public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
- return asComponentPreset(ComponentPreset.Type.CENTERING_RING, materials);
- }
-
- public ComponentPreset asComponentPreset(ComponentPreset.Type type, List<MaterialDTO> materials) throws InvalidComponentPresetException {
- TypedPropertyMap props = new TypedPropertyMap();
- addProps(props, materials);
- props.put(ComponentPreset.INNER_DIAMETER, this.getInsideDiameter());
- props.put(ComponentPreset.OUTER_DIAMETER, this.getOutsideDiameter());
- props.put(ComponentPreset.LENGTH, this.getLength());
- props.put(ComponentPreset.TYPE, type);
-
- return ComponentPresetFactory.create(props);
+ return super.asComponentPreset(ComponentPreset.Type.CENTERING_RING, materials);
}
}
*/
@XmlRootElement(name = "EngineBlock")
@XmlAccessorType(XmlAccessType.FIELD)
-public class EngineBlockDTO extends CenteringRingDTO {
+public class EngineBlockDTO extends BodyTubeDTO {
/**
* Default constructor.
package net.sf.openrocket.preset.xml;
-import net.sf.openrocket.database.Databases;
-import net.sf.openrocket.material.Material;
-
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
+import net.sf.openrocket.database.Databases;
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.util.Chars;
+
/**
* XML handler for materials.
*/
Material asMaterial() {
return Databases.findMaterial(type.getORMaterialType(), name, density, false);
}
+
+
+ /**
+ * Special directive to the JAXB system. After the object is parsed from xml,
+ * we replace the '2' with Chars.SQUARED, and '3' with Chars.CUBED. Just the
+ * opposite transformation as doen in beforeMarshal.
+ * @param unmarshaller
+ * @param parent
+ */
+ @SuppressWarnings("unused")
+ private void afterUnmarshal( Unmarshaller unmarshaller, Object parent ) {
+ if (uom != null) {
+ uom = uom.replace('2', Chars.SQUARED);
+ uom = uom.replace('3', Chars.CUBED);
+ }
+ }
+
+ /**
+ * Special directive to the JAXB system. Before the object is serialized into xml,
+ * we strip out the special unicode characters for cubed and squared so they appear
+ * as simple "3" and "2" chars. The reverse transformation is done in afterUnmarshal.
+ * @param marshaller
+ */
+ @SuppressWarnings("unused")
+ private void beforeMarshal( Marshaller marshaller ) {
+ if (uom != null ) {
+ uom = uom.replace(Chars.SQUARED, '2');
+ uom = uom.replace(Chars.CUBED, '3');
+ }
+ }
}
package net.sf.openrocket.preset.xml;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.ComponentPresetFactory;
-import net.sf.openrocket.preset.InvalidComponentPresetException;
-import net.sf.openrocket.preset.TypedPropertyMap;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import java.util.List;
+
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.ComponentPresetFactory;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
+import net.sf.openrocket.preset.TypedPropertyMap;
/**
* A NoseCone preset XML handler.
@XmlElement(name = "Shape")
private ShapeDTO shape;
@XmlElement(name = "OutsideDiameter")
- private double outsideDiameter;
+ private AnnotatedLengthDTO outsideDiameter;
@XmlElement(name = "ShoulderDiameter")
- private double shoulderDiameter;
+ private AnnotatedLengthDTO shoulderDiameter;
+ @XmlElement(name = "ShoulderLength")
+ private AnnotatedLengthDTO shoulderLength;
@XmlElement(name = "Length")
- private double length;
+ private AnnotatedLengthDTO length;
@XmlElement(name = "Thickness")
- private Double thickness;
+ private AnnotatedLengthDTO thickness;
/**
* Default constructor.
super(thePreset);
setShape(ShapeDTO.asDTO(thePreset.get(ComponentPreset.SHAPE)));
setOutsideDiameter(thePreset.get(ComponentPreset.AFT_OUTER_DIAMETER));
- setShoulderDiameter(thePreset.get(ComponentPreset.AFT_SHOULDER_DIAMETER));
+ if ( thePreset.has(ComponentPreset.AFT_SHOULDER_DIAMETER)) {
+ setShoulderDiameter(thePreset.get(ComponentPreset.AFT_SHOULDER_DIAMETER));
+ }
+ if ( thePreset.has(ComponentPreset.AFT_SHOULDER_LENGTH)) {
+ setShoulderLength(thePreset.get(ComponentPreset.AFT_SHOULDER_LENGTH));
+ }
setLength(thePreset.get(ComponentPreset.LENGTH));
if ( thePreset.has(ComponentPreset.THICKNESS)) {
setThickness(thePreset.get(ComponentPreset.THICKNESS));
}
public double getOutsideDiameter() {
- return outsideDiameter;
+ return outsideDiameter.getValue();
}
- public void setOutsideDiameter(final double theOutsideDiameter) {
+ public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
outsideDiameter = theOutsideDiameter;
}
+ public void setOutsideDiameter(final double theOutsideDiameter) {
+ outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
+ }
+
public double getShoulderDiameter() {
- return shoulderDiameter;
+ return shoulderDiameter.getValue();
}
- public void setShoulderDiameter(final double theShoulderDiameter) {
+ public void setShoulderDiameter(final AnnotatedLengthDTO theShoulderDiameter) {
shoulderDiameter = theShoulderDiameter;
}
+ public void setShoulderDiameter(final double theShoulderDiameter) {
+ shoulderDiameter = new AnnotatedLengthDTO(theShoulderDiameter);
+ }
+
+ public double getShoulderLength() {
+ return shoulderLength.getValue();
+ }
+
+ public void setShoulderLength(final AnnotatedLengthDTO theShoulderLength) {
+ shoulderLength = theShoulderLength;
+ }
+
+ public void setShoulderLength(final double theShoulderLength) {
+ shoulderLength = new AnnotatedLengthDTO(theShoulderLength);
+ }
+
public double getLength() {
- return length;
+ return length.getValue();
}
- public void setLength(final double theLength) {
+ public void setLength(final AnnotatedLengthDTO theLength) {
length = theLength;
}
- public Double getThickness() {
- return thickness;
+ public void setLength(final double theLength) {
+ length = new AnnotatedLengthDTO(theLength);
+ }
+
+ public double getThickness() {
+ return thickness.getValue();
}
- public void setThickness(Double thickness) {
+ public void setThickness(AnnotatedLengthDTO thickness) {
this.thickness = thickness;
}
+ public void setThickness(double thickness) {
+ this.thickness = new AnnotatedLengthDTO(thickness);
+ }
+
+ @Override
public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
TypedPropertyMap props = new TypedPropertyMap();
addProps(props, materials);
props.put(ComponentPreset.SHAPE, shape.getORShape());
- props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getShoulderDiameter());
- props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getOutsideDiameter());
+ props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getOutsideDiameter());
+ if ( shoulderLength != null ) {
+ props.put(ComponentPreset.AFT_SHOULDER_LENGTH, this.getShoulderLength());
+ }
+ if ( shoulderDiameter != null ) {
+ props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getShoulderDiameter());
+ }
props.put(ComponentPreset.LENGTH, this.getLength());
props.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
if ( thickness != null ) {
- props.put(ComponentPreset.THICKNESS, thickness);
+ props.put(ComponentPreset.THICKNESS, this.getThickness());
}
return ComponentPresetFactory.create(props);
private ShapeDTO shape;
@XmlElement(name = "ForeOutsideDiameter")
- private double foreOutsideDiameter;
+ private AnnotatedLengthDTO foreOutsideDiameter;
@XmlElement(name = "ForeShoulderDiameter")
- private double foreShoulderDiameter;
+ private AnnotatedLengthDTO foreShoulderDiameter;
@XmlElement(name = "ForeShoulderLength")
- private double foreShoulderLength;
+ private AnnotatedLengthDTO foreShoulderLength;
@XmlElement(name = "AftOutsideDiameter")
- private double aftOutsideDiameter;
+ private AnnotatedLengthDTO aftOutsideDiameter;
@XmlElement(name = "AftShoulderDiameter")
- private double aftShoulderDiameter;
+ private AnnotatedLengthDTO aftShoulderDiameter;
@XmlElement(name = "AftShoulderLength")
- private double aftShoulderLength;
+ private AnnotatedLengthDTO aftShoulderLength;
@XmlElement(name = "Length")
- private double length;
+ private AnnotatedLengthDTO length;
@XmlElement(name = "Thickness")
- private Double thickness;
+ private AnnotatedLengthDTO thickness;
/**
}
public double getForeOutsideDiameter() {
- return foreOutsideDiameter;
+ return foreOutsideDiameter.getValue();
}
- public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
+ public void setForeOutsideDiameter(final AnnotatedLengthDTO theForeOutsideDiameter) {
foreOutsideDiameter = theForeOutsideDiameter;
}
+ public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
+ foreOutsideDiameter = new AnnotatedLengthDTO(theForeOutsideDiameter);
+ }
+
public double getForeShoulderDiameter() {
- return foreShoulderDiameter;
+ return foreShoulderDiameter.getValue();
}
- public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
+ public void setForeShoulderDiameter(final AnnotatedLengthDTO theForeShoulderDiameter) {
foreShoulderDiameter = theForeShoulderDiameter;
}
+ public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
+ foreShoulderDiameter = new AnnotatedLengthDTO(theForeShoulderDiameter);
+ }
+
public double getForeShoulderLength() {
- return foreShoulderLength;
+ return foreShoulderLength.getValue();
}
- public void setForeShoulderLength(final double theForeShoulderLength) {
+ public void setForeShoulderLength(final AnnotatedLengthDTO theForeShoulderLength) {
foreShoulderLength = theForeShoulderLength;
}
+ public void setForeShoulderLength(final double theForeShoulderLength) {
+ foreShoulderLength = new AnnotatedLengthDTO(theForeShoulderLength);
+ }
+
public double getAftOutsideDiameter() {
- return aftOutsideDiameter;
+ return aftOutsideDiameter.getValue();
}
- public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
+ public void setAftOutsideDiameter(final AnnotatedLengthDTO theAftOutsideDiameter) {
aftOutsideDiameter = theAftOutsideDiameter;
}
+ public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
+ aftOutsideDiameter = new AnnotatedLengthDTO(theAftOutsideDiameter);
+ }
+
public double getAftShoulderDiameter() {
- return aftShoulderDiameter;
+ return aftShoulderDiameter.getValue();
}
- public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
+ public void setAftShoulderDiameter(final AnnotatedLengthDTO theAftShoulderDiameter) {
aftShoulderDiameter = theAftShoulderDiameter;
}
+ public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
+ aftShoulderDiameter = new AnnotatedLengthDTO(theAftShoulderDiameter);
+ }
+
public double getAftShoulderLength() {
- return aftShoulderLength;
+ return aftShoulderLength.getValue();
}
- public void setAftShoulderLength(final double theAftShoulderLength) {
+ public void setAftShoulderLength(final AnnotatedLengthDTO theAftShoulderLength) {
aftShoulderLength = theAftShoulderLength;
}
+ public void setAftShoulderLength(final double theAftShoulderLength) {
+ aftShoulderLength = new AnnotatedLengthDTO(theAftShoulderLength);
+ }
+
public double getLength() {
- return length;
+ return length.getValue();
}
- public void setLength(final double theLength) {
+ public void setLength(final AnnotatedLengthDTO theLength) {
length = theLength;
}
- public Double getThickness() {
- return thickness;
+ public void setLength(final double theLength) {
+ length = new AnnotatedLengthDTO(theLength);
+ }
+
+ public double getThickness() {
+ return thickness.getValue();
}
- public void setThickness(Double thickness) {
+ public void setThickness(AnnotatedLengthDTO thickness) {
this.thickness = thickness;
}
+ public void setThickness(double thickness) {
+ this.thickness = new AnnotatedLengthDTO(thickness);
+ }
+
+ @Override
public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
TypedPropertyMap props = new TypedPropertyMap();
addProps(props, materials);
props.put(ComponentPreset.LENGTH, this.getLength());
props.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
if ( thickness != null ) {
- props.put(ComponentPreset.THICKNESS, thickness);
+ props.put(ComponentPreset.THICKNESS, this.getThickness());
}
return ComponentPresetFactory.create(props);