This works fine, but what is a pity is that in theory there is no absolute guarantee that the iterator will be closed. It is possible to do a break inside a collection loop in your template, and not finishing with the last item. I don't see why you would do that with features, and it is not done in any of the existing template I think, but... can we maybe include in the documentation that it is not advised to a break when looping over the features in a HTML template?

On 25/01/11 15:34, Niels wrote:

Well one evil thing to do would be to scan through once and collect the feature ids (perhaps you could do that efficiently?); and then make a collection that produces an iterator that fetches the matching feature for each feature id in turn?

Not the best idea; but something.

The problem with that would be performance again.

But I'm looking at something now that might work. Textmarker actually has its own Iterator model, and what I am doing is implementing that one, which wraps a FeatureIterator and automatically closes after the last read. Something like this:

|public TemplateModel next() throws TemplateModelException {
        if (!hasNext) {
            return null;
        }
        Object o = iterator.next();
        hasNext = iterator.hasNext();
        if (!hasNext) {
            iterator.close();
        }
        return new BeanModel(o, wrapper);
    }|

--
*Niels Charlier*

Software Engineer
CSIRO Earth Science and Resource Engineering
Phone: +61 8 6436 8914

Australian Resources Research Centre
26 Dick Perry Avenue, Kensington WA 6151


--
*Niels Charlier*

Software Engineer
CSIRO Earth Science and Resource Engineering
Phone: +61 8 6436 8914

Australian Resources Research Centre
26 Dick Perry Avenue, Kensington WA 6151
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to