Hi

On Friday 28 May 2010 19:25:12 Enamul wrote:
> I might have found a bug with Cloneable implementation of Style. The issue
> seems to be with the cloning of rules. Here is a very simple test case that
> fails with the trunk code:
> 
> Style clonedStyle = (Style) ((Cloneable) style).clone();

I guess that Style.clone does only a "shallow copy"; e.g. it created only a 
new Style object, but all children are the same objects as in the original. 
That would explain your described behaviour:

> // get the first rule of the original style
> Rule rule = style.featureTypeStyles().get(0).rules().get(0);
> 
> // get the first rule of the cloned style
> Rule clonedRule = clonedStyle.featureTypeStyles().get(0).rules().get(0);
> 
> // let's remove all the symbolizers from the cloned rule
> clonedRule.symbolizers().clear();
> 
> System.out.println(rule.symbolizers().size());
> 
> The output of this test case would be 0, which is not the expected
> behavior. The issue seems to be in RuleImpl.clone():

In GeoTools you should use the DuplicatingStyleVisitor class, and not the 
clone() method:

http://docs.codehaus.org/display/GEOTDOC/08+StyleVisitor+use+with+DuplicatingStyleVisitor+and+RescaleStyleVisitor

It can not only be used to duplicate a Style, but also duplicates Rules, 
Symbolizers etc..

 DuplicatingStyleVisitor xerox = new DuplicatingStyleVisitor();
 style.accepts( xerox ); 
 Style copy = (Style) xerox.getCopy();

Greetings,
Steve
-- 
Geotools-based SLD editor: 
http://en.geopblushing.org/AtlasStyler
Stefan Tzeggai (geb. Krüger)

reclaim your net - http://tor.eff.org
enforce privacy - http://www.pgpi.org
pgp key id: 51B576FD - http://pgp.mit.edu

Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.


------------------------------------------------------------------------------

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

Reply via email to