source: josm/trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java@ 9309

Last change on this file since 9309 was 8953, checked in by Don-vip, 8 years ago

better detection of plugin loading failures for unit test

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins;
3
4import java.util.List;
5
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.gui.MapFrame;
8import org.openstreetmap.josm.gui.download.DownloadSelection;
9import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
10import org.openstreetmap.josm.tools.BugReportExceptionHandler;
11
12/**
13 * Helper class for the JOSM system to communicate with the plugin.
14 *
15 * This class should be of no interest for sole plugin writer.
16 *
17 * @author Immanuel.Scholz
18 */
19public class PluginProxy extends Plugin {
20
21 /**
22 * The plugin.
23 */
24 public final Object plugin;
25
26 /**
27 * Constructs a new {@code PluginProxy}.
28 * @param plugin the plugin
29 * @param info the associated plugin info
30 */
31 public PluginProxy(Object plugin, PluginInformation info) {
32 super(info);
33 this.plugin = plugin;
34 }
35
36 private void handlePluginException(Exception e) {
37 PluginHandler.pluginLoadingExceptions.put(getPluginInformation().name, e);
38 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
39 }
40
41 @Override
42 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
43 try {
44 plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
45 } catch (NoSuchMethodException e) {
46 Main.debug("Plugin "+plugin+" does not define mapFrameInitialized");
47 } catch (Exception e) {
48 handlePluginException(e);
49 }
50 }
51
52 @Override
53 public PreferenceSetting getPreferenceSetting() {
54 try {
55 return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
56 } catch (NoSuchMethodException e) {
57 Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
58 return null;
59 } catch (Exception e) {
60 handlePluginException(e);
61 }
62 return null;
63 }
64
65 @Override
66 public void addDownloadSelection(List<DownloadSelection> list) {
67 try {
68 plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
69 } catch (NoSuchMethodException e) {
70 Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
71 } catch (Exception e) {
72 handlePluginException(e);
73 }
74 }
75}
Note: See TracBrowser for help on using the repository browser.