You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Plugin.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. /**
  20. * This class will be extended by all plugins and
  21. * serve as the common class between a plugin and the application.
  22. * <p>
  23. * Create (it's optional) a Plugin class if you are interested in plugin's lifecycle events (start, stop, ...)
  24. * or you want to pass some context to the plugin.
  25. *
  26. * @author Decebal Suiu
  27. */
  28. public class Plugin {
  29. /**
  30. * Makes logging service available for descending classes.
  31. */
  32. protected final Logger log = LoggerFactory.getLogger(getClass());
  33. /**
  34. * Wrapper of the plugin.
  35. * @deprecated Use application custom {@code PluginContext} instead of {@code PluginWrapper}.
  36. * See demo for more details.
  37. */
  38. @Deprecated
  39. protected PluginWrapper wrapper;
  40. /**
  41. * Constructor to be used by plugin manager for plugin instantiation.
  42. * Your plugins have to provide constructor with this exact signature to
  43. * be successfully loaded by manager.
  44. * @deprecated Use application custom {@code PluginContext} instead of {@code PluginWrapper}.
  45. * See demo for more details.
  46. */
  47. @Deprecated
  48. public Plugin(final PluginWrapper wrapper) {
  49. if (wrapper == null) {
  50. throw new IllegalArgumentException("Wrapper cannot be null");
  51. }
  52. this.wrapper = wrapper;
  53. }
  54. public Plugin() {
  55. }
  56. /**
  57. * Retrieves the wrapper of this plug-in.
  58. * @deprecated Use application custom {@code PluginContext} instead of {@code PluginWrapper}.
  59. * See demo for more details.
  60. */
  61. @Deprecated
  62. public final PluginWrapper getWrapper() {
  63. return wrapper;
  64. }
  65. /**
  66. * This method is called by the application when the plugin is started.
  67. * See {@link PluginManager#startPlugin(String)}.
  68. */
  69. public void start() {
  70. }
  71. /**
  72. * This method is called by the application when the plugin is stopped.
  73. * See {@link PluginManager#stopPlugin(String)}.
  74. */
  75. public void stop() {
  76. }
  77. /**
  78. * This method is called by the application when the plugin is deleted.
  79. * See {@link PluginManager#deletePlugin(String)}.
  80. */
  81. public void delete() {
  82. }
  83. }