Jody Garnett a écrit :
> In my understanding there are three steps:
> 1- it needs the no argument constructor so that the FactorySPI system
> can return an Object (if the user explicitly specified an exact
> implementation it would be found and returned directly
Yes. Note that the no-argument constructor is never invoked explicitly by
org.geotools.factory.FactoryRegistry. It is invoked by
javax.imageio.spi.ServiceRegistry.
> 2- It would then ask the object for its class
> 3- And then finally perform reflection on that class in order to look
> for a constructor that creates hints
There is a missing step:
2.5- It ask for Factory.getImplementationHints() and checks if the hints used
by
the Factory match the hints specified by the users.
> Step 1 seems broken; when I commented out step 1 I was able to confirm
> that step 2 and 3 work as expected.
I'm not sure that it is broken; It seems to work with the referencing module,
which uses many hints. Can you point me to a code I could look at?
> We implemented the GeoTools Factory interface - it has the
> getImplementationHints method and was suited for our purpose. Do you
> really want us to extend the AbstractFactory?
Right, you don't have to extends AbstractFactory. You can do as you wish as
long
as getImplementationHints() returns all relevant hints, but it must returns
those hints (not an empty map). The hint must be declared even if its value is
null. For example if a Factory cares about Hints.COORDINATE_REFERENCE_SYSTEM,
then we must have something functionnaly equivalent to:
public Map getImplementationHints() {
Map hints = new HashMap();
hints.put(Hints.COORDINATE_REFERENCE_SYSTEM, crs);
return hints;
}
even if "crs" is null. Workflow example:
* A user ask for a GeometryFactory with the following hints:
userHints.put(Hints.COORDINATE_REFERENCE_SYSTEM, WGS_84);
* FactoryRegistry scans for GeometryFactory in priority order. If
it find a GeometryFactory of appropriate class (if a particular
class was requested), it call its getImplementationHints() method.
Then there is a choice:
- If the getImplementationHints() do *not* contains a
Hints.COORDINATE_REFERENCE_SYSTEM key (no matter if the associated
value is null or not), then FactoryRegistry said "this factory don't
care about the CRS. It is suitable for the user needs, since the user
COORDINATE_REFERENCE_SYSTEM hint will not make any difference for this
factory". No GeometryFactory(Hints) constructor is invoked since the
existing factory is considered suitable and returned (as a cached
factory).
- If the getImplementationHints() do contains a
Hints.COORDINATE_REFERENCE_SYSTEM key, then the value for this key
is compared with the value provided in the "userHints" map. Then there
is a choice:
* If the values are equal (and assuming that all other relevant hints
have been checked in the same way), then the GeometryFactory is
considered suitable to user needs. No GeometryFactory(Hints)
constructor is invoked since the existing factory is considered
suitable and returned (as a cached factory).
* If the values are not equal, then FactoryFinder continue the search
for an other GeometryFactory. If no suitable GeometryFactory is found,
then an exception is thrown. If we are actually using FactoryCreator
instead of FactoryRegistry, only then the exception is caugh and a
new factory is created using the GeometryFactory(Hints) constructor.
This factory is then cached. Next time that a user will ask for a
GeometryFactory, the new GeometryFactory just created will be one
more candidate in the process described above.
Martin
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel