Martin Desruisseaux ha scritto:
> Andrea Aime a écrit :
>> The whole thing uses the getServiceProviderByClass(Class)
>> method, which returns the one and only factory instance
>> registered for a certain factory class...
> 
> 
> I can confirm that GeoTools FactoryRegistry requires a different class 
> for each factory. Actually this is the way that the JDK service registry 
> works - both javax.imageio.spi.ServiceRegistry and the new 
> java.util.ServiceLoader introduced in Java 6. This is maybe in order to 
> be consistent with the fact that factories are expected to be registered 
> in the META-INF/services/ directory and are instantiated by invoking 
> their no-argument constructor, with no way to pass parameters (if we 
> forget about the hints which are a GeoTools-specific extension).

Eh, very simple, quite rigid... any lightweight dependency injection
container can do better than this (think pico container, guice,
spring... ok, spring is not that lightweight anymore).

> If there is many factories of the same class, then I guess that 
> something distinguish those instances. Maybe a parameter given to the 
> constructor, or something similar. What is distinguishing the various 
> instances?

A parameter given to the constructor, yep, which in this case is
the Sextante algorithm (in Sextante there is only one class per
algorithm, the algorithm itself, which is self-describing).

> Once the aspect that distinguish the instances is identified, is there 
> any way to create a class thats look like the following?
> 
>    public class AlgorithmFactory extends AbstractFactory {
>        public Algorithm getAlgorithm(TheAspectThatDistinguish...) {
>             return ...
>        }
>    }
> 
> and register only the above class as the factory? This is a bit similar 
> to AuthorityFactory working.

So you have a single factory creating many algorithms? It would be
possible, but it's not how the process api has been designed,
the factory does not only create the algorithm but provides
informations about its parameters and a few other informations,
making it cumbersome to have the algorithm name as a parameter
in all requests...

Jody, what about this kind of change? Makes sense to me, but it would
be an API break, thought gt-process is still unsupported.
In the meantime I'm working around this mess in GeoServer creating a
temporary meta-lookup utility that directly knows about Sextante
and GeoTools process APIs and knows how to look them up
(so not very puggable to new API, thought each one is able
to plugin new algorithms).

Cheers
Andrea


-- 
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to