[ https://issues.apache.org/jira/browse/SIS-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14730606#comment-14730606 ]
Martin Desruisseaux commented on SIS-166: ----------------------------------------- Actually the above approach works for {{DefaultEngineeringCRS}}, but not for {{DefaultImageCRS}} or for {{DefaultGeodeticCRS}}. A possible explanation may be that the type covariance (overriding the {{getCoordinateSystem()}} method with a more specific return type) is causing some confusion for JAXB. > Replace repetition of private getter/setters in CRS classes by @XmlElements > annotation > -------------------------------------------------------------------------------------- > > Key: SIS-166 > URL: https://issues.apache.org/jira/browse/SIS-166 > Project: Spatial Information Systems > Issue Type: Task > Components: Referencing > Affects Versions: 0.4, 0.5 > Reporter: Martin Desruisseaux > Assignee: Martin Desruisseaux > Priority: Minor > Labels: JAXB > Fix For: 0.6 > > > Some CRS implementation classes in {{org.apache.sis.referencing.crs}} package > contain many private getter and setter methods for coordinate system > marshalling/unmarshalling with JAXB. For example {{DefaultEngineeringCRS}} > has the following methods: > {code:java} > /** > * Invoked by JAXB at marshalling time. > */ > @XmlElement(name="affineCS") private AffineCS getAffineCS() > {return getCoordinateSystem(AffineCS .class);} > @XmlElement(name="cartesianCS") private CartesianCS getCartesianCS() > {return getCoordinateSystem(CartesianCS .class);} > @XmlElement(name="cylindricalCS") private CylindricalCS > getCylindricalCS() {return getCoordinateSystem(CylindricalCS.class);} > @XmlElement(name="linearCS") private LinearCS getLinearCS() > {return getCoordinateSystem(LinearCS .class);} > @XmlElement(name="polarCS") private PolarCS getPolarCS() > {return getCoordinateSystem(PolarCS .class);} > @XmlElement(name="sphericalCS") private SphericalCS getSphericalCS() > {return getCoordinateSystem(SphericalCS .class);} > @XmlElement(name="userDefinedCS") private UserDefinedCS > getUserDefinedCS() {return getCoordinateSystem(UserDefinedCS.class);} > /** > * Invoked by JAXB at unmarshalling time. > */ > private void setAffineCS (final AffineCS cs) > {super.setCoordinateSystem("affineCS", cs);} > private void setCartesianCS (final CartesianCS cs) > {super.setCoordinateSystem("cartesianCS", cs);} > private void setCylindricalCS(final CylindricalCS cs) > {super.setCoordinateSystem("cylindricalCS", cs);} > private void setLinearCS (final LinearCS cs) > {super.setCoordinateSystem("linearCS", cs);} > private void setPolarCS (final PolarCS cs) > {super.setCoordinateSystem("polarCS", cs);} > private void setSphericalCS (final SphericalCS cs) > {super.setCoordinateSystem("sphericalCS", cs);} > private void setUserDefinedCS(final UserDefinedCS cs) > {super.setCoordinateSystem("userDefinedCS", cs);} > {code} > This is an ugly hack, since there is really only one coordinate system > property, which may have different names in a GML document depending of its > type. A more elegant solution would be to declare all the names in a single > method, like below: > {code:java} > /** > * Returns the coordinate system. > * > * @return The coordinate system. > */ > @Override > @XmlElements({ > @XmlElement(name = "cartesianCS", type = DefaultCartesianCS.class), > @XmlElement(name = "affineCS", type = DefaultAffineCS.class), > @XmlElement(name = "cylindricalCS", type = DefaultCylindricalCS.class), > @XmlElement(name = "linearCS", type = DefaultLinearCS.class), > @XmlElement(name = "polarCS", type = DefaultPolarCS.class), > @XmlElement(name = "sphericalCS", type = DefaultSphericalCS.class), > @XmlElement(name = "userDefinedCS", type = DefaultUserDefinedCS.class) > }) > public CoordinateSystem getCoordinateSystem() { > return super.getCoordinateSystem(); > } > /** > * Used by JAXB only (invoked by reflection). > */ > private void setCoordinateSystem(final CoordinateSystem cs) { > super.setCoordinateSystem("coordinateSystem", cs); > } > {code} > However it didn't worked in our experiment. For a unknown reason, the > unmarshalled coordinate system was empty. We need more investigation about > this problem in order to replace the hack by the above-cited cleaner strategy. -- This message was sent by Atlassian JIRA (v6.3.4#6332)