Skip to content

Commit

Permalink
fix #josm17152 - fix JAXB initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
don-vip committed May 27, 2019
1 parent a90b9ea commit c14ba7b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions dataimport/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<classpathentry kind="src" path="resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
<classpathentry combineaccessrules="false" kind="src" path="/JOSM-jaxb"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <a
* href="https://jaxb.dev.java.net/">https://jaxb.dev.java.net/</a>. This class
Expand All @@ -50,9 +48,6 @@
* The command used to generate the code is:
* {@code xjc.bat -p org.openstreetmap.josm.io.tcx TrainingCenterDatabasev2.xsd -d <path to the src folder of JOSM>}
* <p>
* 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 \<program files>\Java\jre<java version>\lib\endorsed}
*
* @author adrian &lt;[email protected]&gt;
*
Expand All @@ -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
Expand All @@ -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<TrainingCenterDatabaseT> element = (JAXBElement<TrainingCenterDatabaseT>) unmarshaller
.unmarshal(tcxFile);

TrainingCenterDatabaseT tcd = element.getValue();
TrainingCenterDatabaseT tcd = ((JAXBElement<TrainingCenterDatabaseT>)
jc.createUnmarshaller().unmarshal(tcxFile)).getValue();

gpxData = new GpxData();

Expand Down

0 comments on commit c14ba7b

Please sign in to comment.