[josm-dev] OsmPrimitive.timestamp API change problem

Martijn van Oosterhout kleptog at gmail.com
Mon Mar 23 12:06:09 GMT 2009


2009/3/22 Martin Garbe <martin.garbe at informatik.uni-rostock.de>:
> Hi
>
> I have a problem with the new OsmPrimitive class. In the old class (before
> Josm r1499) there was   public String timestamp = null;
> In SVN now it is private. This is a good design decision but now plugin
> programmers have a problem to make compatible plugins for old Josm und the
> new one.
>

<snip>

> Is there a way to write one plugin which is compatible with old and new API
> of OsmPrimitive? Another possibility would be to create one plugin version
> for old Josm and another for the new one.

Well, it's possible, but really really ugly. I did it once in the
UtilsPlugin a long time ago. You write the way that works normally and
catch the exception and use introspection otherwise. Very evil, but it
does work.

For example:

                        try { Main.ds.addSelectionChangedListener(this); }
                        catch( NoSuchMethodError e )
                        {
                                try {
                                java.lang.reflect.Field f =
DataSet.class.getDeclaredField("listeners");

((Collection<SelectionChangedListener>)f.get(Main.ds)).add(this);
                                } catch (Exception x) {
System.out.println( e ); }
                        }

Have a nice day,
-- 
Martijn van Oosterhout <kleptog at gmail.com> http://svana.org/kleptog/




More information about the josm-dev mailing list