Class DescribableModel<T>
- java.lang.Object
-
- org.jenkinsci.plugins.structs.describable.DescribableModel<T>
-
- All Implemented Interfaces:
Serializable
public final class DescribableModel<T> extends Object implements Serializable
Introspects aDescribable
withDataBoundConstructor
andDataBoundSetter
.Provides such operations like
- instantiate this class from a JSON-like map
- take an existing instance and produces a JSON-like map that can be then fed back to the above instantiation call
-
enumerate parameters of this Describable that are defined
either through
DataBoundConstructor
orDataBoundSetter
. SeeDescribableParameter
for more details - access help file
- Author:
- Jesse Glick, Andrew Bayer, Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLAZZ
static boolean
STRICT_PARAMETER_CHECKING
-
Constructor Summary
Constructors Constructor Description DescribableModel(Class<T> clazz)
Loads a definition of the structure of a class: what kind of data you might get back fromuninstantiate(T)
on an instance, or might want to pass toinstantiate(Map)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
getDisplayName()
Corresponds toDescriptor.getDisplayName()
where available.DescribableParameter
getFirstRequiredParameter()
If this model has any required parameter, return the first one.String
getHelp()
Loads help defined for this object as a wholeDescribableParameter
getParameter(String name)
Collection<DescribableParameter>
getParameters()
A map from parameter names to types.DescribableParameter
getSoleRequiredParameter()
If this model has one and only one required parameter, return it.Class<T>
getType()
A concrete class, usuallyDescribable
.boolean
hasSingleRequiredParameter()
Returns true if this model has one and only one required parameter.T
instantiate(Map<String,?> arguments)
Deprecated.instead useinstantiate(Map, TaskListener)
T
instantiate(Map<String,?> arguments, TaskListener listener)
Creates an instance of a class viaDataBoundConstructor
andDataBoundSetter
.boolean
isDeprecated()
True if this model's type is deprecated.static <T> DescribableModel<T>
of(Class<T> clazz)
Binds type parameter, preferred means of obtaining a DescribableModel.String
toString()
Map<String,Object>
uninstantiate(T o)
Deprecated.as of 1.2 Useuninstantiate2(Object)
static Map<String,Object>
uninstantiate_(Object o)
Deprecated.as of 1.2.UninstantiatedDescribable
uninstantiate2(T o)
Disects a given instance intoUninstantiatedDescribable
that you can re-instantiate viaUninstantiatedDescribable.instantiate()
.static UninstantiatedDescribable
uninstantiate2_(Object o)
In case if you just need to uninstantiate one object and be done with it.
-
-
-
Field Detail
-
STRICT_PARAMETER_CHECKING
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean STRICT_PARAMETER_CHECKING
-
CLAZZ
public static final String CLAZZ
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DescribableModel
public DescribableModel(Class<T> clazz)
Loads a definition of the structure of a class: what kind of data you might get back fromuninstantiate(T)
on an instance, or might want to pass toinstantiate(Map)
. Useof(Class)
instead -- that will returned cached instances.
-
-
Method Detail
-
of
public static <T> DescribableModel<T> of(Class<T> clazz)
Binds type parameter, preferred means of obtaining a DescribableModel.
-
getType
public Class<T> getType()
A concrete class, usuallyDescribable
.
-
getParameters
public Collection<DescribableParameter> getParameters()
A map from parameter names to types. A parameter name is either the name of an argument to aDataBoundConstructor
, or the JavaBeans property name corresponding to aDataBoundSetter
.Sorted by the mandatory parameters first (in the order they are specified in the code), followed by optional arguments.
-
getParameter
public DescribableParameter getParameter(String name)
-
hasSingleRequiredParameter
public boolean hasSingleRequiredParameter()
Returns true if this model has one and only one required parameter.- See Also:
UninstantiatedDescribable.ANONYMOUS_KEY
-
getSoleRequiredParameter
@CheckForNull public DescribableParameter getSoleRequiredParameter()
If this model has one and only one required parameter, return it. Otherwise null.- See Also:
UninstantiatedDescribable.ANONYMOUS_KEY
-
getFirstRequiredParameter
@CheckForNull public DescribableParameter getFirstRequiredParameter()
If this model has any required parameter, return the first one. Otherwise null.
-
getDisplayName
public String getDisplayName()
Corresponds toDescriptor.getDisplayName()
where available.
-
instantiate
@Deprecated public T instantiate(Map<String,?> arguments) throws IllegalArgumentException
Deprecated.instead useinstantiate(Map, TaskListener)
- Throws:
IllegalArgumentException
-
instantiate
public T instantiate(Map<String,?> arguments, @CheckForNull TaskListener listener) throws IllegalArgumentException
Creates an instance of a class viaDataBoundConstructor
andDataBoundSetter
.The arguments may be primitives (as wrappers) or
String
s if that is their declared type.Character
s,Enum
s, andURL
s may be represented byString
s. Other object types may be passed in “raw” as well, but JSON-like structures are encouraged instead. Specifically aList
may be used to represent any list- or array-valued argument. AMap
withString
keys may be used to represent any class which is itself data-bound. In that case the special keyCLAZZ
is used to specify theClass.getName()
; or it may be omitted if the argument is declared to take a concrete type; orClass.getSimpleName()
may be used in case the argument type isDescribable
and only one subtype is registered (as aDescriptor
) with that simple name.- Parameters:
arguments
- The arguments used to create the instancelistener
- Listener to record any instantiation warnings- Returns:
- The instantiated object
- Throws:
IllegalArgumentException
-
uninstantiate
@Deprecated public Map<String,Object> uninstantiate(T o) throws UnsupportedOperationException
Deprecated.as of 1.2 Useuninstantiate2(Object)
Computes arguments suitable to pass toinstantiate(java.util.Map<java.lang.String, ?>)
to reconstruct this object.- Parameters:
o
- a data-bound object- Returns:
- constructor and/or setter parameters
- Throws:
UnsupportedOperationException
- if the class does not follow the expected structure
-
uninstantiate2
public UninstantiatedDescribable uninstantiate2(T o) throws UnsupportedOperationException
Disects a given instance intoUninstantiatedDescribable
that you can re-instantiate viaUninstantiatedDescribable.instantiate()
.- Parameters:
o
- a data-bound object- Returns:
- constructor and/or setter parameters
- Throws:
UnsupportedOperationException
- if the class does not follow the expected structure
-
uninstantiate_
@Deprecated public static Map<String,Object> uninstantiate_(Object o)
Deprecated.as of 1.2. Useuninstantiate2_(Object)
In case if you just need to uninstantiate one object and be done with it.
-
uninstantiate2_
public static UninstantiatedDescribable uninstantiate2_(Object o)
In case if you just need to uninstantiate one object and be done with it.
-
isDeprecated
public boolean isDeprecated()
True if this model's type is deprecated. A model is deprecated if it'stype
is marked asDeprecated
.
-
getHelp
@CheckForNull public String getHelp() throws IOException
Loads help defined for this object as a whole- Returns:
- some HTML (in English locale), if available, else null
- Throws:
IOException
- See Also:
Descriptor.doHelp(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)
-
-