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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2011, CloudBees, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import hudson.model.Descriptor.FormException;
27 import hudson.slaves.NodeProperty;
28 import net.sf.json.JSONObject;
29 import org.kohsuke.stapler.StaplerRequest;
30
31 /**
32 * Marks modern {@link Describable}s that allow the current instances to pass information down to the next
33 * instance when the configuration is submitted.
34 *
35 * <p>
36 * As the generics signature implies, it isn't up to individual {@link Describable} implementation to
37 * implement this. Rather, it is up to the designer of an extension point to mark the extension point
38 * as {@link ReconfigurableDescribable}, as it requires coordination at the owner of the extension point.
39 *
40 * <h1>Use Cases</h1>
41 * <h2>Invisible Property</h2>
42 * <p>
43 * This mechanism can be used to create an entirely invisible {@link Describable}, which is handy
44 * for {@link NodeProperty}, {@link JobProperty}, etc. To do so, define a descriptor with null
45 * {@linkplain Descriptor#getDisplayName() display name} and empty config.jelly to prevent it from
46 * showing up in the config UI, then implement {@link #reconfigure(StaplerRequest, JSONObject)}
47 * and simply return {@code this}.
48 *
49 * <h2>Passing some values without going through clients</h2>
50 * <p>
51 * Sometimes your {@link Describable} object may have some expensive objects that you might want to
52 * hand over to the next instance. This hook lets you do that.
53 *
54 * @author Kohsuke Kawaguchi
55 * @since 1.406
56 */
57 public interface ReconfigurableDescribable<T extends ReconfigurableDescribable<T>> extends Describable<T> {
58
59 /**
60 * When a parent/owner object of a Describable gets a config form submission and instances are
61 * recreated, this method is invoked on the existing instance (meaning the 'this' reference
62 * points to the existing instance) to create a new instance to be added to the parent/owner object.
63 *
64 * <p>
65 * The default implementation of this should be the following:
66 * <pre>
67 * return form==null ? null : getDescriptor().newInstance(req, form);
68 * </pre>
69 *
70 * @param req
71 * The current HTTP request being processed.
72 * @param form
73 * JSON fragment that corresponds to this describable object.
74 * If the newly submitted form doesn't include a fragment for this describable
75 * (meaning the user has de-selected your descriptor), then this argument is null.
76 *
77 * @return
78 * The new instance. To not to create an instance of a describable, return null.
79 */
80 T reconfigure(StaplerRequest req, JSONObject form) throws FormException;
81 }
82