From c14ba7bf028a6a6af5c3a226a54ae804f0ff2e82 Mon Sep 17 00:00:00 2001 From: donvip Date: Mon, 27 May 2019 23:20:32 +0000 Subject: [PATCH] fix #josm17152 - fix JAXB initialization git-svn-id: https://josm.openstreetmap.de/osmsvn/applications/editors/josm/plugins@35012 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4 --- dataimport/.classpath | 1 + .../plugins/dataimport/DataImportPlugin.java | 5 +++- .../josm/plugins/dataimport/io/Tcx.java | 27 +++++++------------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/dataimport/.classpath b/dataimport/.classpath index 51483d10c2..623019138e 100644 --- a/dataimport/.classpath +++ b/dataimport/.classpath @@ -4,5 +4,6 @@ + diff --git a/dataimport/src/org/openstreetmap/josm/plugins/dataimport/DataImportPlugin.java b/dataimport/src/org/openstreetmap/josm/plugins/dataimport/DataImportPlugin.java index 76be6ccdf2..d26d488577 100644 --- a/dataimport/src/org/openstreetmap/josm/plugins/dataimport/DataImportPlugin.java +++ b/dataimport/src/org/openstreetmap/josm/plugins/dataimport/DataImportPlugin.java @@ -3,6 +3,8 @@ import java.io.IOException; +import javax.xml.bind.JAXBException; + import org.openstreetmap.josm.actions.ExtensionFileFilter; import org.openstreetmap.josm.plugins.Plugin; import org.openstreetmap.josm.plugins.PluginInformation; @@ -18,8 +20,9 @@ public class DataImportPlugin extends Plugin { * Add new File import filter into open dialog * @param info plugin information * @throws IOException in case of I/O error + * @throws JAXBException if JAXB cannot be initialized */ - public DataImportPlugin(PluginInformation info) throws IOException { + public DataImportPlugin(PluginInformation info) throws IOException, JAXBException { super(info); ExtensionFileFilter.addImporter(new TangoGPS()); diff --git a/dataimport/src/org/openstreetmap/josm/plugins/dataimport/io/Tcx.java b/dataimport/src/org/openstreetmap/josm/plugins/dataimport/io/Tcx.java index 3d21cf279d..8a15acd27b 100644 --- a/dataimport/src/org/openstreetmap/josm/plugins/dataimport/io/Tcx.java +++ b/dataimport/src/org/openstreetmap/josm/plugins/dataimport/io/Tcx.java @@ -12,7 +12,6 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; import javax.xml.datatype.XMLGregorianCalendar; import org.openstreetmap.josm.actions.ExtensionFileFilter; @@ -34,9 +33,8 @@ import org.openstreetmap.josm.plugins.dataimport.io.tcx.TrainingCenterDatabaseT; import org.openstreetmap.josm.spi.preferences.Config; - /** - * TCX Reader. This class is based on code genarated by the Java Architecture + * TCX Reader. This class is based on code generated by the Java Architecture * for XML Binding (JAXB). For this class to work you will need the API und IMPL * Jars from the RI. JAXB can be downloaded at https://jaxb.dev.java.net/. This class @@ -50,9 +48,6 @@ * The command used to generate the code is: * {@code xjc.bat -p org.openstreetmap.josm.io.tcx TrainingCenterDatabasev2.xsd -d } *

- * Note: if you get an exception that JAXB 2.1 is not supported on your system, you will have to add the jaxb-api.jar - * to the endorsed directory (create it if necessary) of your JRE. Usually it is something like this: - * {@code \\Java\jre\lib\endorsed} * * @author adrian <as@nitegate.de> * @@ -62,9 +57,12 @@ public class Tcx extends FileImporter { //private File tcxFile; private GpxData gpxData; + private final JAXBContext jc; - public Tcx() { + public Tcx() throws JAXBException { super(new ExtensionFileFilter("tcx", "tcx", tr("TCX Files (*.tcx)"))); + // JAXB must be initialized at plugin construction to get access to JAXB plugin from JOSM plugin classloader + jc = JAXBContext.newInstance(TrainingCenterDatabaseT.class); } @Override @@ -83,18 +81,11 @@ public void importData(File tcxFile, ProgressMonitor progressMonitor) throws IOE } } - /** - * - */ - @SuppressWarnings("unchecked") private void parseFile(File tcxFile) { + @SuppressWarnings("unchecked") + private void parseFile(File tcxFile) { try { - JAXBContext jc = JAXBContext - .newInstance(TrainingCenterDatabaseT.class); - Unmarshaller unmarshaller = jc.createUnmarshaller(); - JAXBElement element = (JAXBElement) unmarshaller - .unmarshal(tcxFile); - - TrainingCenterDatabaseT tcd = element.getValue(); + TrainingCenterDatabaseT tcd = ((JAXBElement) + jc.createUnmarshaller().unmarshal(tcxFile)).getValue(); gpxData = new GpxData();