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.

PluginStateEvent.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 java.util.EventObject;
  18. /**
  19. * Event object that indicates a change in the state of a plugin.
  20. * The event is propagated to all registered listeners.
  21. * The event source is the {@link PluginManager} that changed the state of the plugin.
  22. * The event object contains the plugin that changed its state and the old state.
  23. *
  24. * @see PluginStateListener
  25. * @author Decebal Suiu
  26. */
  27. public class PluginStateEvent extends EventObject {
  28. private PluginWrapper plugin;
  29. private PluginState oldState;
  30. public PluginStateEvent(PluginManager source, PluginWrapper plugin, PluginState oldState) {
  31. super(source);
  32. this.plugin = plugin;
  33. this.oldState = oldState;
  34. }
  35. /**
  36. * The object on which the Event initially occurred.
  37. *
  38. * @return the PluginManager that changed the state of the plugin
  39. */
  40. @Override
  41. public PluginManager getSource() {
  42. return (PluginManager) super.getSource();
  43. }
  44. /**
  45. * The plugin that changed its state.
  46. *
  47. * @return the plugin that changed its state
  48. */
  49. public PluginWrapper getPlugin() {
  50. return plugin;
  51. }
  52. /**
  53. * The new state of the plugin.
  54. *
  55. * @return the new state of the plugin
  56. */
  57. public PluginState getPluginState() {
  58. return plugin.getPluginState();
  59. }
  60. /**
  61. * The old state of the plugin.
  62. *
  63. * @return the old state of the plugin
  64. */
  65. public PluginState getOldState() {
  66. return oldState;
  67. }
  68. @Override
  69. public String toString() {
  70. return "PluginStateEvent [plugin=" + plugin.getPluginId() +
  71. ", newState=" + getPluginState() +
  72. ", oldState=" + oldState +
  73. ']';
  74. }
  75. }