File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\TopLevelItemDescriptor.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.ExtensionList;
27 import jenkins.model.Jenkins;
28 import org.kohsuke.stapler.StaplerRequest;
29
30 /**
31 * {@link Descriptor} for {@link TopLevelItem}s.
32 *
33 * @author Kohsuke Kawaguchi
34 */
35 public abstract class TopLevelItemDescriptor extends Descriptor<TopLevelItem> {
36 protected TopLevelItemDescriptor(Class<? extends TopLevelItem> clazz) {
37 super(clazz);
38 }
39
40 /**
41 * Infers the type of the corresponding {@link TopLevelItem} from the outer class.
42 * This version works when you follow the common convention, where a descriptor
43 * is written as the static nested class of the describable class.
44 *
45 * @since 1.278
46 */
47 protected TopLevelItemDescriptor() {
48 }
49
50 /**
51 * {@link TopLevelItemDescriptor}s often uses other descriptors to decorate itself.
52 * This method allows the subtype of {@link TopLevelItemDescriptor}s to filter them out.
53 *
54 * <p>
55 * This is useful for a workflow/company specific job type that wants to eliminate
56 * options that the user would see.
57 *
58 * @since 1.294
59 */
60 public boolean isApplicable(Descriptor descriptor) {
61 return true;
62 }
63
64 /**
65 * Tests if the given instance belongs to this descriptor, in the sense
66 * that this descriptor can produce items like the given one.
67 *
68 * <p>
69 * {@link TopLevelItemDescriptor}s that act like a wizard and produces different
70 * object types than {@link #clazz} can override this method to augment
71 * instance-descriptor relationship.
72 */
73 public boolean testInstance(TopLevelItem i) {
74 return clazz.isInstance(i);
75 }
76
77 /**
78 * {@inheritDoc}
79 *
80 * <p>
81 * Used as the caption when the user chooses what job type to create.
82 * The descriptor implementation also needs to have <tt>newJobDetail.jelly</tt>
83 * script, which will be used to render the text below the caption
84 * that explains the job type.
85 */
86 public abstract String getDisplayName();
87
88 /**
89 * @deprecated since 2007-01-19.
90 * This is not a valid operation for {@link Job}s.
91 */
92 @Deprecated
93 public TopLevelItem newInstance(StaplerRequest req) throws FormException {
94 throw new UnsupportedOperationException();
95 }
96
97 /**
98 * Creates a new {@link TopLevelItem}.
99 *
100 * @deprecated as of 1.390
101 * Use {@link #newInstance(ItemGroup, String)}
102 */
103 public TopLevelItem newInstance(String name) {
104 return newInstance(Jenkins.getInstance(), name);
105 }
106
107 /**
108 * Creates a new {@link TopLevelItem} for the specified parent.
109 *
110 * @since 1.390
111 */
112 public abstract TopLevelItem newInstance(ItemGroup parent, String name);
113
114 /**
115 * Returns all the registered {@link TopLevelItem} descriptors.
116 */
117 public static ExtensionList<TopLevelItemDescriptor> all() {
118 return Items.all();
119 }
120
121 }
122