Changeset 35012 in osm


Ignore:
Timestamp:
2019-05-28T01:20:32+02:00 (5 years ago)
Author:
donvip
Message:

fix #josm17152 - fix JAXB initialization

Location:
applications/editors/josm/plugins/dataimport
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/dataimport/.classpath

    r34575 r35012  
    55        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    66        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
     7        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jaxb"/>
    78        <classpathentry kind="output" path="bin"/>
    89</classpath>
  • applications/editors/josm/plugins/dataimport/src/org/openstreetmap/josm/plugins/dataimport/DataImportPlugin.java

    r34475 r35012  
    33
    44import java.io.IOException;
     5
     6import javax.xml.bind.JAXBException;
    57
    68import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    1921     * @param info plugin information
    2022     * @throws IOException in case of I/O error
     23     * @throws JAXBException if JAXB cannot be initialized
    2124     */
    22     public DataImportPlugin(PluginInformation info) throws IOException {
     25    public DataImportPlugin(PluginInformation info) throws IOException, JAXBException {
    2326        super(info);
    2427
  • applications/editors/josm/plugins/dataimport/src/org/openstreetmap/josm/plugins/dataimport/io/Tcx.java

    r34749 r35012  
    1313import javax.xml.bind.JAXBElement;
    1414import javax.xml.bind.JAXBException;
    15 import javax.xml.bind.Unmarshaller;
    1615import javax.xml.datatype.XMLGregorianCalendar;
    1716
     
    3534import org.openstreetmap.josm.spi.preferences.Config;
    3635
    37 
    3836/**
    39  * TCX Reader. This class is based on code genarated by the Java Architecture
     37 * TCX Reader. This class is based on code generated by the Java Architecture
    4038 * for XML Binding (JAXB). For this class to work you will need the API und IMPL
    4139 * Jars from the RI. JAXB can be downloaded at <a
     
    5149 * {@code xjc.bat -p org.openstreetmap.josm.io.tcx TrainingCenterDatabasev2.xsd -d <path to the src folder of JOSM>}
    5250 * <p>
    53  * 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
    54  * to the endorsed directory (create it if necessary) of your JRE. Usually it is something like this:
    55  * {@code \<program files>\Java\jre<java version>\lib\endorsed}
    5651 *
    5752 * @author adrian &lt;as@nitegate.de&gt;
     
    6358
    6459    private GpxData gpxData;
     60    private final JAXBContext jc;
    6561
    66     public Tcx() {
     62    public Tcx() throws JAXBException {
    6763        super(new ExtensionFileFilter("tcx", "tcx", tr("TCX Files (*.tcx)")));
     64        // JAXB must be initialized at plugin construction to get access to JAXB plugin from JOSM plugin classloader
     65        jc = JAXBContext.newInstance(TrainingCenterDatabaseT.class);
    6866    }
    6967
     
    8482    }
    8583
    86     /**
    87      *
    88      */
    89     @SuppressWarnings("unchecked") private void parseFile(File tcxFile) {
     84    @SuppressWarnings("unchecked")
     85    private void parseFile(File tcxFile) {
    9086        try {
    91             JAXBContext jc = JAXBContext
    92                     .newInstance(TrainingCenterDatabaseT.class);
    93             Unmarshaller unmarshaller = jc.createUnmarshaller();
    94             JAXBElement<TrainingCenterDatabaseT> element = (JAXBElement<TrainingCenterDatabaseT>) unmarshaller
    95                     .unmarshal(tcxFile);
    96 
    97             TrainingCenterDatabaseT tcd = element.getValue();
     87            TrainingCenterDatabaseT tcd = ((JAXBElement<TrainingCenterDatabaseT>)
     88                    jc.createUnmarshaller().unmarshal(tcxFile)).getValue();
    9889
    9990            gpxData = new GpxData();
Note: See TracChangeset for help on using the changeset viewer.