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 * Body tube preset XML handler.
18 @XmlRootElement(name = "LaunchLug")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class LaunchLugDTO extends BaseComponentDTO {
22 @XmlElement(name = "InsideDiameter")
23 private AnnotatedLengthDTO insideDiameter;
24 @XmlElement(name = "OutsideDiameter")
25 private AnnotatedLengthDTO outsideDiameter;
26 @XmlElement(name = "Length")
27 private AnnotatedLengthDTO length;
30 * Default constructor.
32 public LaunchLugDTO() {
36 * Most-useful constructor that maps a LaunchLug preset to a LaunchLugDTO.
38 * @param preset the preset
40 * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
42 public LaunchLugDTO(final ComponentPreset preset) {
44 setInsideDiameter(preset.get(ComponentPreset.INNER_DIAMETER));
45 setOutsideDiameter(preset.get(ComponentPreset.OUTER_DIAMETER));
46 setLength(preset.get(ComponentPreset.LENGTH));
49 public double getInsideDiameter() {
50 return insideDiameter.getValue();
53 public void setInsideDiameter( final AnnotatedLengthDTO theLength ) {
54 insideDiameter = theLength;
57 public void setInsideDiameter(final double theId) {
58 insideDiameter = new AnnotatedLengthDTO(theId);
61 public double getOutsideDiameter() {
62 return outsideDiameter.getValue();
65 public void setOutsideDiameter(final AnnotatedLengthDTO theOd) {
66 outsideDiameter = theOd;
69 public void setOutsideDiameter(final double theOd) {
70 outsideDiameter = new AnnotatedLengthDTO(theOd);
73 public double getLength() {
74 return length.getValue();
77 public void setLength(final AnnotatedLengthDTO theLength) {
81 public void setLength(final double theLength) {
82 length = new AnnotatedLengthDTO(theLength);
86 public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
87 return asComponentPreset(ComponentPreset.Type.LAUNCH_LUG, materials);
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);
98 return ComponentPresetFactory.create(props);