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

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

sonar - squid:S2221 - "Exception" should not be caught when not required by called methods

  • Property svn:eol-style set to native
File size: 2.7 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.debug("Plugin "+plugin+" does not define mapFrameInitialized");
48 } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
49 handlePluginException(e);
50 }
51 }
52
53 @Override
54 public PreferenceSetting getPreferenceSetting() {
55 try {
56 return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
57 } catch (NoSuchMethodException e) {
58 Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
59 return null;
60 } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
61 handlePluginException(e);
62 }
63 return null;
64 }
65
66 @Override
67 public void addDownloadSelection(List<DownloadSelection> list) {
68 try {
69 plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
70 } catch (NoSuchMethodException e) {
71 Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
72 } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
73 handlePluginException(e);
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.