From: Jody G. <jga...@re...> - 2005-03-07 06:38:19
|
Martin Desruisseaux wrote: > no build-in mechanism like 'setOrdering'. But in my opinion, > org.geotools.factory.FactoryFinder should be replaced by a > javax.imageio.spi.ServiceRegistry based solution. Yep - I got that part. We should have a consistent mechaism for registering Factories. > - the point of these hints is to sort out the current unpredictability > and place it under user control. > > Agree for the goal, but I don't see (yet) a reason for Hints managed > by FactoryFinder; this is ServiceRegistry.setOrdering(...)'s job. So here is the *only* point I need to make sure of. I need to ensure that ServiceRegistry.setOrdering( ... ) is not GLOBAL. And is indeed limited to a single use (say for a single instnaceof of a FactoryFinder used by a DataStore). > I think that Hints should be used by users of FactoryFinder, not > FactoryFinder itself. > However, I agree that a FactoryFinder may be itself a user of other > FactoryFinder, in why case Hints may be relevant for managing usage of > other FactoryFinder (but not for the Factories that this FactoryFinder > manage directly; again this is 'setOrdering' job). Okay - let's think about the use of setOrdering. Given CarFactory and WheelFactory - WheelFactoryFinder - CarFactory (makes use of a WheelFactoryFinder to locate a WheelFactory) Either: 1) User create a CarFactoryFinder 2) User calls carFactoryFinder.setOrdering( "european", "japanese" ) 3) User creates a hints map 3.1) User set a wheel ordering - hints.put( WHEEL_ORDERING, {"square","triangle") ) 4) User calls carFactoryFinder.create( Color.BLUE, hints ) 4.1) europeanCarFactory calls create a wheelFactoryFinder 4.2) europeanCarFactory calle wheelFactoryFinder.setOrdering( hints.get( WHEEL_ORDERING ) ) 4.3) europeanCarFactory calls wheelFactoryFinder.create() 4.3.1) triangleWheel.create() is called 4 times 4.4) ruopeanCarFactory creates a car with the 4 wheels 5) User drives away with a Blue car with 4 square wheels Or: 1) User creates a hints map 1.1) User sets a wheel ordering - hints.put( WHEEL_ORDERING), {"circle","square"} ) 1.2) User sets a car ordering - hints.put( CAR_ORDERING, {"japanese","american"} ) 2) User creates a CarFactoryFinder( hints ) 3) User calls CarFactoryFinder.create( Color.Red ) 3.1) CarFactoryFinder locates japaneseCarFactory using the CAR_ORDERING hint 3.2) japaneseCarFactory.create( Color.Red, hints ) is called 3.2.1) japaneseCarFactory creates WheelFactoryFinder( hints ) 3.2.2) japaneseCarFactory uses WheelFactoryFinder.create( 4 ) 3.2.3) circleFWheelFactory is found and create() is called 4 times 3.3) japaneseCarFactory makes a car with the 4 wheels 4) User drives away with a Red japanese car with 4 circle wheels Comments - if I have the above usecases wrong please answer with another use case. > - Either the hints provide a direct reference to a particular > Factory (or a list of Factory implementations in preference > order), in which case I can't see any reason for using > FactoryFinder at all. You are mostly correct on this, when the user has a specific factory in mind they will know about it (and be able to supply us with it). The problem is all the other code in the code base which uses FactoryFinder to locate the "appropriate" factory for the job. > - Either the user wants to modify FactoryFinder behaviour. > Usual answer: 'setOrdering'. > > However, it may requires API changes. For example, all static methods > in FactoryFinder may needs to become class members. We could certaintly do "constructor injection" that is all the static methods become class members and a Map of Factories is supplied as an argument. We just need to be sure that the Factories pass the "hints" along (giving other FactoryFinders a chance to take direction from the user). Note Factory Finder really is playing the roll of a container (and has been for some time), it is just the scope of this container has been the entire application. Narrowing this down to a single Query, DataStore or FeatureType is what is proving hard. Martin should we go play in a branch? Much like Chris Holmes suggested. I don't want to recomend either of these solutions with out a trial run. One of the off the shelf solutions may still be better for our needs. The origional imageio.spi.ServiceRegistry - how does it handle these kinds of isses? Jody |