All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.tools.PropertyDescriptor Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2010 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *
 *******************************************************************************/ 

package hudson.tools;

import hudson.Functions;
import hudson.model.Describable;
import hudson.model.Descriptor;

import java.util.ArrayList;
import java.util.List;

/**
 * Base {@link Descriptor} type used for {@code XyzProperty} classes.
 *
 * @param 

Type of the {@code XyzProperty}. Called 'property type' * @param Type of the {@code Xyz}, that the property attaches to. Called * 'target type' * @author Kohsuke Kawaguchi * @since 1.305 */ public abstract class PropertyDescriptor

, T> extends Descriptor

{ protected PropertyDescriptor(Class clazz) { super(clazz); } protected PropertyDescriptor() { } /** * Infer the type parameterization 'P' */ private Class

getP() { return Functions.getTypeParameter(getClass(), Descriptor.class, 0); } /** * Returns true if this property type is applicable to the given target * type. * *

The default implementation of this method checks if the given node * type is assignable according to the parameterization, but subtypes can * extend this to change this behavior. * * @return true to indicate applicable, in which case the property will be * displayed in the configuration screen of the target, for example. */ public boolean isApplicable(Class targetType) { Class applicable = Functions.getTypeParameter(clazz, getP(), 0); return applicable.isAssignableFrom(targetType); } public static , T> List for_(List all, Class target) { List result = new ArrayList(); for (D d : all) { if (d.isApplicable(target)) { result.add(d); } } return result; } public static , T> List for_(List all, T target) { return for_(all, (Class) target.getClass()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy