X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fpreset%2Fxml%2FMaterialDTO.java;h=405596a446fe5ee0034391dd7ce96efda7cd83ff;hb=4da92a4e994992a78d62a7ca21c88d6c41292d6f;hp=929d84954032a0fac04be54d3296cd385b596291;hpb=753a606973adc7b48f84a831f7f695e6b6502105;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java index 929d8495..405596a4 100644 --- a/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java +++ b/core/src/net/sf/openrocket/preset/xml/MaterialDTO.java @@ -1,15 +1,17 @@ package net.sf.openrocket.preset.xml; -import net.sf.openrocket.database.Databases; -import net.sf.openrocket.material.Material; - +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import net.sf.openrocket.material.Material; +import net.sf.openrocket.util.Chars; + /** * XML handler for materials. */ @@ -77,6 +79,36 @@ public class MaterialDTO { } Material asMaterial() { - return Databases.findMaterial(type.getORMaterialType(), name, density, false); + return Material.newUserMaterial(type.getORMaterialType(), name, density); + } + + + /** + * Special directive to the JAXB system. After the object is parsed from xml, + * we replace the '2' with Chars.SQUARED, and '3' with Chars.CUBED. Just the + * opposite transformation as doen in beforeMarshal. + * @param unmarshaller + * @param parent + */ + @SuppressWarnings("unused") + private void afterUnmarshal( Unmarshaller unmarshaller, Object parent ) { + if (uom != null) { + uom = uom.replace('2', Chars.SQUARED); + uom = uom.replace('3', Chars.CUBED); + } + } + + /** + * Special directive to the JAXB system. Before the object is serialized into xml, + * we strip out the special unicode characters for cubed and squared so they appear + * as simple "3" and "2" chars. The reverse transformation is done in afterUnmarshal. + * @param marshaller + */ + @SuppressWarnings("unused") + private void beforeMarshal( Marshaller marshaller ) { + if (uom != null ) { + uom = uom.replace(Chars.SQUARED, '2'); + uom = uom.replace(Chars.CUBED, '3'); + } } }