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 * Bulkhead preset XML handler.
18 @XmlRootElement(name = "BulkHead")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class BulkHeadDTO extends BaseComponentDTO {
22 @XmlElement(name = "OutsideDiameter")
23 private AnnotatedLengthDTO outsideDiameter;
24 @XmlElement(name = "Length")
25 private AnnotatedLengthDTO length;
27 public BulkHeadDTO() {
31 * Most-useful constructor that maps a BulkHead preset to a BulkHeadDTO.
33 * @param thePreset the preset
35 * @throws net.sf.openrocket.util.BugException thrown if the expected bulk head keys are not in the preset
37 public BulkHeadDTO(final ComponentPreset thePreset) {
39 setOutsideDiameter(thePreset.get(ComponentPreset.OUTER_DIAMETER));
40 setLength(thePreset.get(ComponentPreset.LENGTH));
43 public double getOutsideDiameter() {
44 return outsideDiameter.getValue();
47 public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
48 outsideDiameter = theOutsideDiameter;
51 public void setOutsideDiameter(final double theOutsideDiameter) {
52 outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
55 public double getLength() {
56 return length.getValue();
59 public void setLength(final AnnotatedLengthDTO theLength) {
63 public void setLength(final double theLength) {
64 length = new AnnotatedLengthDTO(theLength);
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);
75 return ComponentPresetFactory.create(props);