Uploaded image for project: 'Spatial Information Systems'
  1. Spatial Information Systems
  2. SIS-166

Replace repetition of private getter/setters in CRS classes by @XmlElements annotation

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.4, 0.5
    • 0.6
    • Referencing

    Description

      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:

          /**
           * 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);}
      

      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:

          /**
           * 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);
          }
      

      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.

      Attachments

        Issue Links

          Activity

            People

              desruisseaux Martin Desruisseaux
              desruisseaux Martin Desruisseaux
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: