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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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.ExtensionPoint;
27 import hudson.Plugin;
28 import hudson.DescriptorExtensionList;
29 import hudson.model.Descriptor.FormException;
30 import jenkins.model.Jenkins;
31 import net.sf.json.JSONObject;
32
33 import org.kohsuke.stapler.StaplerRequest;
34 import org.kohsuke.stapler.export.ExportedBean;
35
36 /**
37 * Extensible property of {@link User}.
38 *
39 * <p>
40 * {@link Plugin}s can extend this to define custom properties
41 * for {@link User}s. {@link UserProperty}s show up in the user
42 * configuration screen, and they are persisted with the user object.
43 *
44 * <p>
45 * Configuration screen should be defined in <tt>config.jelly</tt>.
46 * Within this page, the {@link UserProperty} instance is available
47 * as <tt>instance</tt> variable (while <tt>it</tt> refers to {@link User}.
48 * See {@link UserSearchProperty.UserProperty}'s <tt>config.jelly</tt> for an example.
49 *
50 *
51 * @author Kohsuke Kawaguchi
52 */
53 @ExportedBean
54 public abstract class UserProperty implements ReconfigurableDescribable<UserProperty>, ExtensionPoint {
55 /**
56 * The user object that owns this property.
57 * This value will be set by the Hudson code.
58 * Derived classes can expect this value to be always set.
59 */
60 protected transient User user;
61
62 /*package*/ final void setUser(User u) {
63 this.user = u;
64 }
65
66 // descriptor must be of the UserPropertyDescriptor type
67 public UserPropertyDescriptor getDescriptor() {
68 return (UserPropertyDescriptor) Jenkins.getInstance().getDescriptorOrDie(getClass());
69 }
70
71 /**
72 * Returns all the registered {@link UserPropertyDescriptor}s.
73 */
74 public static DescriptorExtensionList<UserProperty,UserPropertyDescriptor> all() {
75 return Jenkins.getInstance().<UserProperty,UserPropertyDescriptor>getDescriptorList(UserProperty.class);
76 }
77
78 public UserProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException {
79 return form==null ? null : getDescriptor().newInstance(req, form);
80 }
81 }
82