File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\listeners\SaveableListener.java.html

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
27 import hudson.ExtensionPoint;
28 import hudson.Extension;
29 import hudson.ExtensionList;
30 import hudson.XmlFile;
31 import jenkins.model.Jenkins;
32 import hudson.model.Saveable;
33
34 /**
35 * Receives notifications about save actions on {@link Saveable} objects in Hudson.
36 *
37 * <p>
38 * This is an abstract class so that methods added in the future won't break existing listeners.
39 *
40 * @author Andrew Bayer
41 * @since 1.334
42 */
43 public abstract class SaveableListener implements ExtensionPoint {
44
45 /**
46 * Called when a change is made to a {@link Saveable} object.
47 *
48 * @param o
49 * The saveable object.
50 * @param file
51 * The {@link XmlFile} for this saveable object.
52 */
53 public void onChange(Saveable o, XmlFile file) {}
54
55 /**
56 * Registers this object as an active listener so that it can start getting
57 * callbacks invoked.
58 *
59 * @deprecated as of 1.281
60 * Put {@link Extension} on your class to get it auto-registered.
61 */
62 public void register() {
63 all().add(this);
64 }
65
66 /**
67 * Reverse operation of {@link #register()}.
68 */
69 public void unregister() {
70 all().remove(this);
71 }
72
73 /**
74 * Fires the {@link #onChange} event.
75 */
76 public static void fireOnChange(Saveable o, XmlFile file) {
77 for (SaveableListener l : all()) {
78 l.onChange(o,file);
79 }
80 }
81
82 /**
83 * Returns all the registered {@link SaveableListener} descriptors.
84 */
85 public static ExtensionList<SaveableListener> all() {
86 return Jenkins.getInstance().getExtensionList(SaveableListener.class);
87 }
88 }
89