unmarshal XML (*.orc) to ComponentPresets.
[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 double outsideDiameter;
24     @XmlElement(name = "Length")
25     private double 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;
45     }
46
47     public void setOutsideDiameter(final double theOutsideDiameter) {
48         outsideDiameter = theOutsideDiameter;
49     }
50
51     public double getLength() {
52         return length;
53     }
54
55     public void setLength(final double theLength) {
56         length = theLength;
57     }
58
59     public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
60         TypedPropertyMap props = new TypedPropertyMap();
61         addProps(props, materials);
62         props.put(ComponentPreset.OUTER_DIAMETER, this.getOutsideDiameter());
63         props.put(ComponentPreset.LENGTH, this.getLength());
64         props.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
65
66         return ComponentPresetFactory.create(props);
67     }
68
69 }