[
https://issues.apache.org/jira/browse/SIS-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14697515#comment-14697515
]
Martin Desruisseaux commented on SIS-166:
-----------------------------------------
An example of use of {{XmlElements}} is there:
http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html
However it is not sure that we can apply this pattern to our case. One reason
is that the {{type}} value apparently needs to be the implementation class,
while the actual type can be any class implementing the GeoAPI interface. So we
may not be able to use {{XmlElements}} after all.
> 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
> Reporter: Martin Desruisseaux
> Priority: Minor
> Labels: JAXB
>
> 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)