create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / LaunchLugDTO.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  * Body tube preset XML handler.
17  */
18 @XmlRootElement(name = "LaunchLug")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class LaunchLugDTO extends BaseComponentDTO {
21
22     @XmlElement(name = "InsideDiameter")
23     private AnnotatedLengthDTO insideDiameter;
24     @XmlElement(name = "OutsideDiameter")
25     private AnnotatedLengthDTO outsideDiameter;
26     @XmlElement(name = "Length")
27     private AnnotatedLengthDTO length;
28
29     /**
30      * Default constructor.
31      */
32     public LaunchLugDTO() {
33     }
34
35     /**
36      * Most-useful constructor that maps a LaunchLug preset to a LaunchLugDTO.
37      *
38      * @param preset  the preset
39      *
40      * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
41      */
42     public LaunchLugDTO(final ComponentPreset preset) {
43         super(preset);
44         setInsideDiameter(preset.get(ComponentPreset.INNER_DIAMETER));
45         setOutsideDiameter(preset.get(ComponentPreset.OUTER_DIAMETER));
46         setLength(preset.get(ComponentPreset.LENGTH));
47     }
48
49     public double getInsideDiameter() {
50         return insideDiameter.getValue();
51     }
52
53     public void setInsideDiameter( final AnnotatedLengthDTO theLength ) {
54         insideDiameter = theLength;
55     }
56     
57     public void setInsideDiameter(final double theId) {
58         insideDiameter = new AnnotatedLengthDTO(theId);
59     }
60
61     public double getOutsideDiameter() {
62         return outsideDiameter.getValue();
63     }
64
65     public void setOutsideDiameter(final AnnotatedLengthDTO theOd) {
66         outsideDiameter = theOd;
67     }
68
69     public void setOutsideDiameter(final double theOd) {
70         outsideDiameter = new AnnotatedLengthDTO(theOd);
71     }
72
73     public double getLength() {
74         return length.getValue();
75     }
76
77     public void setLength(final AnnotatedLengthDTO theLength) {
78         length = theLength;
79     }
80
81     public void setLength(final double theLength) {
82         length = new AnnotatedLengthDTO(theLength);
83     }
84
85     @Override
86     public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
87         return asComponentPreset(ComponentPreset.Type.LAUNCH_LUG, materials);
88     }
89
90     public ComponentPreset asComponentPreset(ComponentPreset.Type type, List<MaterialDTO> materials) throws InvalidComponentPresetException {
91         TypedPropertyMap props = new TypedPropertyMap();
92         addProps(props, materials);
93         props.put(ComponentPreset.INNER_DIAMETER, this.getInsideDiameter());
94         props.put(ComponentPreset.OUTER_DIAMETER, this.getOutsideDiameter());
95         props.put(ComponentPreset.LENGTH, this.getLength());
96         props.put(ComponentPreset.TYPE, type);
97
98         return ComponentPresetFactory.create(props);
99     }
100 }