2 package net.sf.openrocket.preset.xml;
4 import net.sf.openrocket.preset.ComponentPreset;
5 import net.sf.openrocket.preset.ComponentPresetFactory;
6 import net.sf.openrocket.preset.InvalidComponentPresetException;
7 import net.sf.openrocket.preset.TypedPropertyMap;
9 import javax.xml.bind.annotation.XmlAccessType;
10 import javax.xml.bind.annotation.XmlAccessorType;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import java.util.List;
16 * Transition preset XML handler.
18 @XmlRootElement(name = "Transition")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class TransitionDTO extends BaseComponentDTO {
22 @XmlElement(name = "Shape")
23 private ShapeDTO shape;
25 @XmlElement(name = "ForeOutsideDiameter")
26 private double foreOutsideDiameter;
27 @XmlElement(name = "ForeShoulderDiameter")
28 private double foreShoulderDiameter;
29 @XmlElement(name = "ForeShoulderLength")
30 private double foreShoulderLength;
32 @XmlElement(name = "AftOutsideDiameter")
33 private double aftOutsideDiameter;
34 @XmlElement(name = "AftShoulderDiameter")
35 private double aftShoulderDiameter;
36 @XmlElement(name = "AftShoulderLength")
37 private double aftShoulderLength;
39 @XmlElement(name = "Length")
40 private double length;
42 @XmlElement(name = "Thickness")
43 private Double thickness;
47 * Default constructor.
49 public TransitionDTO() {
53 * Most-useful constructor that maps a Transition preset to a TransitionDTO.
55 * @param thePreset the preset
57 * @throws net.sf.openrocket.util.BugException thrown if the expected transition keys are not in the preset
59 public TransitionDTO(final ComponentPreset thePreset) {
61 setShape(ShapeDTO.asDTO(thePreset.get(ComponentPreset.SHAPE)));
62 setForeOutsideDiameter(thePreset.get(ComponentPreset.FORE_OUTER_DIAMETER));
63 setForeShoulderDiameter(thePreset.get(ComponentPreset.FORE_SHOULDER_DIAMETER));
64 setForeShoulderLength(thePreset.get(ComponentPreset.FORE_SHOULDER_LENGTH));
65 setAftOutsideDiameter(thePreset.get(ComponentPreset.AFT_OUTER_DIAMETER));
66 setAftShoulderDiameter(thePreset.get(ComponentPreset.AFT_SHOULDER_DIAMETER));
67 setAftShoulderLength(thePreset.get(ComponentPreset.AFT_SHOULDER_LENGTH));
68 setLength(thePreset.get(ComponentPreset.LENGTH));
69 if ( thePreset.has(ComponentPreset.THICKNESS)) {
70 setThickness(thePreset.get(ComponentPreset.THICKNESS));
74 public ShapeDTO getShape() {
78 public void setShape(final ShapeDTO theShape) {
82 public double getForeOutsideDiameter() {
83 return foreOutsideDiameter;
86 public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
87 foreOutsideDiameter = theForeOutsideDiameter;
90 public double getForeShoulderDiameter() {
91 return foreShoulderDiameter;
94 public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
95 foreShoulderDiameter = theForeShoulderDiameter;
98 public double getForeShoulderLength() {
99 return foreShoulderLength;
102 public void setForeShoulderLength(final double theForeShoulderLength) {
103 foreShoulderLength = theForeShoulderLength;
106 public double getAftOutsideDiameter() {
107 return aftOutsideDiameter;
110 public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
111 aftOutsideDiameter = theAftOutsideDiameter;
114 public double getAftShoulderDiameter() {
115 return aftShoulderDiameter;
118 public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
119 aftShoulderDiameter = theAftShoulderDiameter;
122 public double getAftShoulderLength() {
123 return aftShoulderLength;
126 public void setAftShoulderLength(final double theAftShoulderLength) {
127 aftShoulderLength = theAftShoulderLength;
130 public double getLength() {
134 public void setLength(final double theLength) {
138 public Double getThickness() {
142 public void setThickness(Double thickness) {
143 this.thickness = thickness;
146 public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
147 TypedPropertyMap props = new TypedPropertyMap();
148 addProps(props, materials);
149 props.put(ComponentPreset.SHAPE, shape.getORShape());
150 props.put(ComponentPreset.FORE_OUTER_DIAMETER, this.getForeOutsideDiameter());
151 props.put(ComponentPreset.FORE_SHOULDER_DIAMETER, this.getForeShoulderDiameter());
152 props.put(ComponentPreset.FORE_SHOULDER_LENGTH, this.getForeShoulderLength());
153 props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getAftOutsideDiameter());
154 props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getAftShoulderDiameter());
155 props.put(ComponentPreset.AFT_SHOULDER_LENGTH, this.getAftShoulderLength());
156 props.put(ComponentPreset.LENGTH, this.getLength());
157 props.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
158 if ( thickness != null ) {
159 props.put(ComponentPreset.THICKNESS, thickness);
162 return ComponentPresetFactory.create(props);