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

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

sonar - squid:S1166 - Exception handlers should preserve the original exceptions

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