4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.ElementHandler;
8 import net.sf.openrocket.file.simplesax.PlainTextHandler;
9 import net.sf.openrocket.material.Material;
10 import net.sf.openrocket.rocketcomponent.CenteringRing;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import org.xml.sax.SAXException;
14 import java.util.HashMap;
17 * A SAX handler for centering rings and bulkheads.
19 class RingHandler extends PositionDependentHandler<CenteringRing> {
22 * The OpenRocket Ring.
24 private final CenteringRing ring;
29 * @param c the parent component
30 * @param warnings the warning set
31 * @throws IllegalArgumentException thrown if <code>c</code> is null
33 public RingHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
35 throw new IllegalArgumentException("The parent of a ring may not be null.");
37 ring = new CenteringRing();
38 if (isCompatible(c, CenteringRing.class, warnings)) {
44 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
45 return PlainTextHandler.INSTANCE;
49 public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
51 super.closeElement(element, attributes, content, warnings);
54 if ("OD".equals(element)) {
55 ring.setOuterRadius(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS);
57 if ("ID".equals(element)) {
58 ring.setInnerRadius(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS);
60 if ("Len".equals(element)) {
61 ring.setLength(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
63 if ("Material".equals(element)) {
64 setMaterialName(content);
67 catch (NumberFormatException nfe) {
68 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
73 * Get the ring component this handler is working upon.
78 public CenteringRing getComponent() {
83 * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
84 * public in all components.
86 * @param position the OpenRocket position
89 public void setRelativePosition(RocketComponent.Position position) {
90 ring.setRelativePosition(position);
94 * Get the required type of material for this component.
99 public Material.Type getMaterialType() {
100 return Material.Type.BULK;