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

Last change on this file since 13670 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 3.3 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[626]2package org.openstreetmap.josm.plugins;
3
4import java.util.List;
5
6import org.openstreetmap.josm.gui.MapFrame;
7import org.openstreetmap.josm.gui.download.DownloadSelection;
8import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
[12620]9import org.openstreetmap.josm.tools.Logging;
[10055]10import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
[626]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
[8953]21 /**
22 * The plugin.
23 */
[12322]24 private final Object plugin;
25 private final PluginClassLoader classLoader;
[626]26
[8953]27 /**
28 * Constructs a new {@code PluginProxy}.
29 * @param plugin the plugin
30 * @param info the associated plugin info
[12322]31 * @param classLoader the class loader for the plugin
32 * @since 12322
[8953]33 */
[12322]34 public PluginProxy(Object plugin, PluginInformation info, PluginClassLoader classLoader) {
[2830]35 super(info);
[1169]36 this.plugin = plugin;
[12322]37 this.classLoader = classLoader;
[626]38 }
39
[12322]40 /**
41 * Get the plugin object.
42 * @return the plugin object
43 * @since 12322
44 */
45 public Object getPlugin() {
46 return plugin;
47 }
48
49 /**
50 * Get the class loader for the plugin.
51 * @return the plugin class loader
52 * @since 12322
53 */
54 public PluginClassLoader getClassLoader() {
55 return classLoader;
56 }
57
[12599]58 private void handlePluginException(Throwable e) {
[8953]59 PluginHandler.pluginLoadingExceptions.put(getPluginInformation().name, e);
60 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
61 }
62
63 @Override
64 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
[1169]65 try {
66 plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
[626]67 } catch (NoSuchMethodException e) {
[12620]68 Logging.trace(e);
69 Logging.debug("Plugin "+plugin+" does not define mapFrameInitialized");
[12599]70 } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
[8953]71 handlePluginException(e);
[626]72 }
73 }
74
[8953]75 @Override
76 public PreferenceSetting getPreferenceSetting() {
[1169]77 try {
[8510]78 return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
[1169]79 } catch (NoSuchMethodException e) {
[12620]80 Logging.trace(e);
81 Logging.debug("Plugin "+plugin+" does not define getPreferenceSetting");
[1169]82 return null;
[12599]83 } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
[8953]84 handlePluginException(e);
[1169]85 }
[1326]86 return null;
[626]87 }
[1169]88
[8953]89 @Override
90 public void addDownloadSelection(List<DownloadSelection> list) {
[1169]91 try {
92 plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
93 } catch (NoSuchMethodException e) {
[12620]94 Logging.trace(e);
95 Logging.debug("Plugin "+plugin+" does not define addDownloadSelection");
[12599]96 } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
[8953]97 handlePluginException(e);
[1169]98 }
99 }
[626]100}
Note: See TracBrowser for help on using the repository browser.