/hudson-core/src/main/java/hudson/model/listeners/SaveableListener.java

http://github.com/hudson/hudson · Java · 88 lines · 24 code · 7 blank · 57 comment · 1 complexity · bb6923c8ede170dbbcd9ffef88cf8170 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts,
  5. * Andrew Bayer
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. package hudson.model.listeners;
  26. import hudson.ExtensionPoint;
  27. import hudson.Extension;
  28. import hudson.ExtensionList;
  29. import hudson.XmlFile;
  30. import hudson.model.Hudson;
  31. import hudson.model.Saveable;
  32. /**
  33. * Receives notifications about save actions on {@link Saveable} objects in Hudson.
  34. *
  35. * <p>
  36. * This is an abstract class so that methods added in the future won't break existing listeners.
  37. *
  38. * @author Andrew Bayer
  39. * @since 1.334
  40. */
  41. public abstract class SaveableListener implements ExtensionPoint {
  42. /**
  43. * Called when a change is made to a {@link Saveable} object.
  44. *
  45. * @param o
  46. * The saveable object.
  47. * @param file
  48. * The {@link XmlFile} for this saveable object.
  49. */
  50. public void onChange(Saveable o, XmlFile file) {}
  51. /**
  52. * Registers this object as an active listener so that it can start getting
  53. * callbacks invoked.
  54. *
  55. * @deprecated as of 1.281
  56. * Put {@link Extension} on your class to get it auto-registered.
  57. */
  58. public void register() {
  59. all().add(this);
  60. }
  61. /**
  62. * Reverse operation of {@link #register()}.
  63. */
  64. public void unregister() {
  65. all().remove(this);
  66. }
  67. /**
  68. * Fires the {@link #onChange} event.
  69. */
  70. public static void fireOnChange(Saveable o, XmlFile file) {
  71. for (SaveableListener l : all()) {
  72. l.onChange(o,file);
  73. }
  74. }
  75. /**
  76. * Returns all the registered {@link SaveableListener} descriptors.
  77. */
  78. public static ExtensionList<SaveableListener> all() {
  79. return Hudson.getInstance().getExtensionList(SaveableListener.class);
  80. }
  81. }