[jsword-devel] Changes to SwordBookDriver

Joe Walker jsword-devel@crosswire.org
Sat, 20 Mar 2004 20:47:55 +0000


Hi,

Thanks for this patch - there was quite a lot to take in but I like it. 
ModuleType is quite new, and I was avoiding putting non-static 
functionality in there which is why I'd resisted doing what you've done, 
however now I see the results, I like it.

I've also had the inheritance problem with apache Enum. I have fixed it 
by hacking the Enum source - I think it only took a couple of lines, but 
I didn't ever submit it because I thought it broke the concept of 
knowing how many elements you had in your Enum.
When I looked at JDK 1.5 enums I'm fairly sure that they are little more 
than some like syntactic sugar on an Apache Enum so I hope moving across 
will be easy.

Thanks,

Joe.

DM Smith wrote:

> I have made the changes that I mentioned in the earlier note. The key 
> upshot is that it is now possible to run the program from a clean 
> install, not change any configuraton values, download one or more 
> books and they will be seen the next time the program starts up.
>
> I also moved some code out of SwordBookDriver and into ModuleType and 
> this required a change in SwordBookMetaData.
>
> In the method createBook there was a large, cascading if/then/else 
> which many times is an indication that there is an opportunity for 
> better placement of code.
>
> It seemed to me that the generation of the Backend and the Book was 
> closely tied to the kind of ModuleType. So I moved the functionality 
> into each of the ModuleTypes. I was really pleased that the ModuleType 
> class implemented the Enum pattern. Besides being a slick way of 
> creating an enumeration (until JDK1.5), it also allows for the 
> addition of behavior to the enumerated objects (which I hope will be a 
> part of the jdk1.5 enum facility).
>
> Each ModuleType was given the methods getBackend and getBook. The 
> class was given the method createBook, which contained the core logic 
> of the original createBook, but now was reduced to a few lines of 
> code. I also moved the method getCompressedBackend.
>
> The one difficulty I had with it was that apache's Enum class cannot 
> handle objects which are created as "adapters". I had to use a pattern 
> that I had used previously. The problem is that when you create an 
> object and (re)define some methods, it essentially is a subclass. But 
> it is the superclass that does the lookup based upon its class name. 
> If the Enum class had used a local hash rather than a global one and 
> used the name of the object as a key, it would have worked.
>
> I have attached a zip of the patch and the actual changed files.
>
> _________________________________________________________________
> Free up your inbox with MSN Hotmail Extra Storage. Multiple plans 
> available. http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/