
hudson.model.JobPropertyDescriptor Maven / Gradle / Ivy
package hudson.model;
import org.kohsuke.stapler.StaplerRequest;
import java.util.List;
import java.util.ArrayList;
import net.sf.json.JSONObject;
/**
* {@link Descriptor} for {@link JobProperty}.
*
* @author Kohsuke Kawaguchi
* @see Jobs#PROPERTIES
* @since 1.72
*/
public abstract class JobPropertyDescriptor extends Descriptor> {
protected JobPropertyDescriptor(Class extends JobProperty>> clazz) {
super(clazz);
}
/**
* {@inheritDoc}
*
* @return
* null to avoid setting an instance of {@link JobProperty} to the target project.
*/
public JobProperty> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return super.newInstance(req, formData);
}
/**
* Returns true if this {@link JobProperty} type is applicable to the
* given job type.
*
*
* Normally, this method is implemented like
* {@code return AbstractProject.class.isAssignableFrom(jobType)}
* where "AbstractProject" is the J of {@link JobProperty}<J>.
*
* @return
* true to indicate applicable, in which case the property will be
* displayed in the configuration screen of this job.
*/
public abstract boolean isApplicable(Class extends Job> jobType);
/**
* Gets the {@link JobPropertyDescriptor}s applicable for a given job type.
*/
public static List getPropertyDescriptors(Class extends Job> clazz) {
List r = new ArrayList();
for (JobPropertyDescriptor p : Jobs.PROPERTIES)
if(p.isApplicable(clazz))
r.add(p);
return r;
}
}