[EMAIL PROTECTED] a écrit :
> The reader would check if a hint was provided in the constructor,
> otherwise it will fall back on the system hint, and if that one is not
> defined either, assume a default behaviour.
> 
> We are wondering if this follows the "best practices" on how to use hints
> in GeoTools.

Yes with a slight nuance. If we want to apply the same approach than referencing
(for example) then:

- The constructor do not looks for system hint. It uses user-provided hints
  exactly as provided, and assume default behavior for non-specified hints.

- The System hints are added by the FactoryFinder.

Example:

The DefaultCoordinateOperationFactory constructor looks for
Hints.LENIENT_DATUM_SHIFT as specified in the user-provided Hints. If the user
didn't privided a value for this hints, then the factory default to
Boolean.FALSE. It does *not* looks into the system hints - it uses the hints
exactly as specified by the users.

    public DefaultCoordinateOperationFactory(Hints userHints) {
        super(userHints);
        boolean lenientDatumShift = false;
        if (userHints != null) {
            Object candidate = userHints.get(Hints.LENIENT_DATUM_SHIFT);
            if (candidate instanceof Boolean) {
                lenientDatumShift = ((Boolean) candidate).booleanValue();
            }
        }
        this.lenientDatumShift = lenientDatumShift;
    }



In ReferencingFactoryFinder, the 'getCoordinateOperationFactory' method is
basically implemented as below:

    CoordinateOperationFactory getCoordinateOperationFactory(Hints hints) {
        hints = addDefaultHints(hints);
        return getServiceRegistry().getServiceProvider(
            CoordinateOperationFactory.class, null, hints,
            Hints.COORDINATE_OPERATION_FACTORY);
    }

where 'addDefaultHints' is a private helper method as below:

    private static Hints addDefaultHints(final Hints hints) {
        final Hints completed = GeoTools.getDefaultHints();
        if (hints != null) {
            completed.add(hints);
        }
        return completed;
    }


        Martin

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to