Package net.sf.basedb.core
Class ParameterType<T>
- java.lang.Object
-
- net.sf.basedb.core.ParameterType<T>
-
- Direct Known Subclasses:
BooleanParameterType
,DateParameterType
,DoubleParameterType
,FileParameterType
,FloatParameterType
,IntegerParameterType
,ItemParameterType
,LongParameterType
,PathParameterType
,StringParameterType
,TimestampParameterType
public abstract class ParameterType<T> extends Object
This is the base class for all parameter types. AParameterType
is used by objects that take some kind of parameter input from an user.- Version:
- 2.0
- Author:
- Samuel, Nicklas, Enell
- Last modified
- $Date: 2015-10-30 09:42:18 +0100 (fr, 30 okt 2015) $
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
checkValues
private Class<T>
clazz
The class of allowed parameter values.private T
defaultValue
Default value of the parameter.private Enumeration<T,String>
enumeration
List of allowed values.private int
height
Height of the input field for the parameter in the GUI.private List<T>
items
List of allowed values.private int
multiplicity
How many values that can be tied to this parameter. 0 is unlimited values and 1 is default.private boolean
notNull
If the parameter can be null or not.private Type
valueType
The matching type of parameter values (can be null)private int
width
Width of the input field for the parameter in the GUI.
-
Constructor Summary
Constructors Constructor Description ParameterType(Type valueType, Class<T> clazz)
Creates a parameter type with no default value and allowing null values.ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull)
Creates a new parameter type.ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height)
ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, List<T> items)
ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, Enumeration<T,String> enumeration, boolean checkValues)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
getDefaultValue()
Get the default value.Enumeration<T,String>
getEnumeration()
Get the list of values to choose from as an enumeration.int
getHeight()
Get the height of the input field for the parameter in the GUI.List<T>
getItems()
Get the list of values to choose from.int
getMultiplicity()
Get how many values that can be tied to this parameter. 0 is unlimited values and 1 is default.boolean
getNotNull()
Check if the parameter can be null.Class<T>
getParameterClass()
Get the class a value must have to match this parameter type.Type
getValueType()
Get the date type of values that can be stored in this parameter.int
getWidth()
Get the width of the input field in the GUI.boolean
isEnumeration()
Check if the parameter type enumerates the allowed values or not.boolean
isMasked()
Should this parameter be masked in the GUI?(package private) abstract ParameterValueData<?>
newParameterValueData()
Create a newParameterValueData
subclass which is used to store values of this value type in the database.void
validate(String name, Object value)
Check if a value is valid according to the settings of this parameter type.void
validate(String name, List<?> values)
Check if a list of values contain invalid values.(package private) abstract void
validateValue(String name, T value)
Validate a value.
-
-
-
Field Detail
-
enumeration
private Enumeration<T,String> enumeration
List of allowed values.
-
checkValues
private boolean checkValues
-
valueType
private final Type valueType
The matching type of parameter values (can be null)
-
defaultValue
private final T defaultValue
Default value of the parameter.
-
notNull
private final boolean notNull
If the parameter can be null or not.
-
height
private final int height
Height of the input field for the parameter in the GUI. Only used as a hint for the client.
-
width
private final int width
Width of the input field for the parameter in the GUI. Only used as a hint for the client.
-
multiplicity
private final int multiplicity
How many values that can be tied to this parameter. 0 is unlimited values and 1 is default.
-
-
Constructor Detail
-
ParameterType
ParameterType(Type valueType, Class<T> clazz)
Creates a parameter type with no default value and allowing null values.- Parameters:
clazz
- The class of the parameters that this type holds
-
ParameterType
ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull)
Creates a new parameter type.- Parameters:
clazz
- The class of the parameters that this type holds.defaultValue
- The parameters default value.notNull
- If the parameter is allowed to be null.
-
ParameterType
ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height)
-
ParameterType
ParameterType(Type valueType, Class<T> clazz, T defaultValue, boolean notNull, int multiplicity, int width, int height, List<T> items)
-
-
Method Detail
-
getValueType
public Type getValueType()
Get the date type of values that can be stored in this parameter. May return null if there is no matching Type definition.- Returns:
- A Type object or null
- Since:
- 2.16
-
getParameterClass
public Class<T> getParameterClass()
Get the class a value must have to match this parameter type.
-
getHeight
public int getHeight()
Get the height of the input field for the parameter in the GUI. Only used as a hint for the client.- Returns:
- The height of the input field.
-
getWidth
public int getWidth()
Get the width of the input field in the GUI. Only used as a hint for the client.- Returns:
- The width of the input field.
-
getNotNull
public boolean getNotNull()
Check if the parameter can be null. Will return true if it can't be null.- Returns:
- True if not null, otherwise false.
-
getMultiplicity
public int getMultiplicity()
Get how many values that can be tied to this parameter. 0 is unlimited values and 1 is default.- Returns:
- The multiplicity.
-
isMasked
public boolean isMasked()
Should this parameter be masked in the GUI?- Returns:
- FALSE, unless overridden by subclass
- Since:
- 3.7
-
getDefaultValue
public T getDefaultValue()
Get the default value.- Returns:
- The default value or null if none i set.
-
validate
public void validate(String name, Object value) throws InvalidDataException
Check if a value is valid according to the settings of this parameter type.- Parameters:
name
- The name of the parameter, used for better exception messagesvalue
- The value to test- Throws:
InvalidDataException
- If the value is invalid
-
validate
public void validate(String name, List<?> values) throws InvalidDataException
Check if a list of values contain invalid values.- Parameters:
name
- The name of the parameter, used for better exception messages.values
- A list of objects to check- Throws:
InvalidDataException
- If the list contains too many values as specified by thegetMultiplicity()
setting or has invalid values as checked byvalidate(String, Object)
-
newParameterValueData
abstract ParameterValueData<?> newParameterValueData()
Create a newParameterValueData
subclass which is used to store values of this value type in the database.
-
validateValue
abstract void validateValue(String name, T value) throws InvalidDataException
Validate a value. The validate methods in this class checks for not-null and multiplicity (if needed). Each subclass must implement checks for other properties, such as maximum string length, lower and upper limits, etc. By the time this method is called, it is certain that the value is of the correct class and isn't null.- Parameters:
name
- The name of the parameter, use the name if there is need to throw an exceptionvalue
- The value- Throws:
InvalidDataException
- If the value is not valid
-
isEnumeration
public boolean isEnumeration()
Check if the parameter type enumerates the allowed values or not. If the parameter is an enumeration the values can be retreived bygetItems()
orgetEnumeration()
. NOTE! If anEnumeration
has been supplied thegetItems
method will return a list of the keys of the enumeration.- Returns:
- TRUE if the parameter type is an enumeration, FALSE otherwise
-
getItems
public List<T> getItems()
Get the list of values to choose from.- Returns:
- List of values
- See Also:
getEnumeration()
-
getEnumeration
public Enumeration<T,String> getEnumeration()
Get the list of values to choose from as an enumeration. An enumeration is different from the regular list returned bygetItems()
in that it has second value attached to each value. The second value should be used for display purposes only while the first value is the one that is used.- Returns:
- The enumeration of values or null
- See Also:
getItems()
-
-