create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / BulkHeadDTO.java
1
2 package net.sf.openrocket.preset.xml;
3
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;
8
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;
14
15 /**
16  * Bulkhead preset XML handler.
17  */
18 @XmlRootElement(name = "BulkHead")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class BulkHeadDTO extends BaseComponentDTO {
21
22     @XmlElement(name = "OutsideDiameter")
23     private AnnotatedLengthDTO outsideDiameter;
24     @XmlElement(name = "Length")
25     private AnnotatedLengthDTO length;
26
27     public BulkHeadDTO() {
28     }
29
30     /**
31      * Most-useful constructor that maps a BulkHead preset to a BulkHeadDTO.
32      *
33      * @param thePreset  the preset
34      *
35      * @throws net.sf.openrocket.util.BugException thrown if the expected bulk head keys are not in the preset
36      */
37     public BulkHeadDTO(final ComponentPreset thePreset) {
38         super(thePreset);
39         setOutsideDiameter(thePreset.get(ComponentPreset.OUTER_DIAMETER));
40         setLength(thePreset.get(ComponentPreset.LENGTH));
41     }
42
43     public double getOutsideDiameter() {
44         return outsideDiameter.getValue();
45     }
46
47     public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
48         outsideDiameter = theOutsideDiameter;
49     }
50
51     public void setOutsideDiameter(final double theOutsideDiameter) {
52         outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
53     }
54
55     public double getLength() {
56         return length.getValue();
57     }
58
59     public void setLength(final AnnotatedLengthDTO theLength) {
60         length = theLength;
61     }
62
63     public void setLength(final double theLength) {
64         length = new AnnotatedLengthDTO(theLength);
65     }
66
67     @Override
68     public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
69         TypedPropertyMap props = new TypedPropertyMap();
70         addProps(props, materials);
71         props.put(ComponentPreset.OUTER_DIAMETER, this.getOutsideDiameter());
72         props.put(ComponentPreset.LENGTH, this.getLength());
73         props.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
74
75         return ComponentPresetFactory.create(props);
76     }
77
78 }