Package nzilbb.configure
Class Parameter
- java.lang.Object
-
- nzilbb.configure.Parameter
-
- All Implemented Interfaces:
CloneableBean
public class Parameter extends Object implements CloneableBean
A parameter that needs to be set for a some operation or configuration.- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Constructor Summary
Constructors Constructor Description Parameter()
Default constructor.Parameter(String name, Class type)
Constructor from attributes.Parameter(String name, Class type, String label)
Constructor from attributes.Parameter(String name, Class type, String label, String hint)
Constructor from attributes.Parameter(String name, Class type, String label, String hint, boolean required)
Constructor from attributes.Parameter(String name, Class type, String label, String hint, boolean required, Object value)
Constructor from attributes.Parameter(String name, Class type, String label, String hint, Object value)
Constructor from attributes.Parameter(String name, Object value)
Constructor from attributes.Parameter(String name, String label, String hint, boolean required, Object value)
Constructor from attributes.Parameter(String name, String label, String hint, Object value)
Constructor from attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.json.JsonObjectBuilder
addExtraJsonAttributes(javax.json.JsonObjectBuilder json)
Called at the end of the default implementation ofCloneableBean.toJson()
, this method allows the Parameter to use a String to represent Layer values.void
addPossibleValue(Object value)
Add a value topossibleValues
.void
apply(Object bean)
Sets the value of the attribute named aftername
of the given bean with the parameter'svalue
.Object
extractValue(Object bean)
Sets thevalue
of the parameter with the value of the attribute named aftername
of the given bean.CloneableBean
fromJson(javax.json.JsonObject json)
Initializes the bean with the given JSON representation.String
getHint()
Getter forhint
: A text hint that might be displayed to a user.String
getLabel()
Getter forlabel
: A label that might be presented to a user.String
getName()
Getter forname
: The paramater's name.Collection
getPossibleValues()
Getter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.Object[]
getPossibleValuesArray()
Array getter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.boolean
getRequired()
Getter forrequired
: Whether the parameter is required (true) or optional (false - the default).Class
getType()
Getter fortype
: The type of the parameter.Object
getValue()
Getter forvalue
: The value (or default value) of the parameter.Parameter
setHint(String newHint)
Setter forhint
: A text hint that might be displayed to a user.Parameter
setLabel(String newLabel)
Setter forlabel
: A label that might be presented to a user.Parameter
setName(String newName)
Setter forname
: The paramater's name.Parameter
setPossibleValues(Collection newPossibleValues)
Setter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.Parameter
setRequired(boolean newRequired)
Setter forrequired
: Whether the parameter is required (true) or optional (false).Parameter
setType(Class newType)
Setter fortype
: The type of the parameter.Parameter
setValue(Object newValue)
Setter forvalue
: The value (or default value) of the parameter.String
toString()
String representation of the parameter.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface nzilbb.util.CloneableBean
clonePropertiesFrom, getClonedAttributes, getter, setter, toJson
-
-
-
-
Constructor Detail
-
Parameter
public Parameter()
Default constructor.
-
Parameter
public Parameter(String name, Class type, String label, String hint, boolean required, Object value)
Constructor from attributes.- Parameters:
name
- The paramater's name.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.type
- The type of the parameter.required
- Whether the parameter is required (true) or optional (false).value
- The value (or default value) of the parameter.
-
Parameter
public Parameter(String name, String label, String hint, boolean required, Object value)
Constructor from attributes.- Parameters:
name
- The paramater's name.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.required
- Whether the parameter is required (true) or optional (false).value
- The value (or default value) of the parameter.
-
Parameter
public Parameter(String name, Class type, String label, String hint, boolean required)
Constructor from attributes.- Parameters:
name
- The paramater's name.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.type
- The type of the parameter.required
- Whether the parameter is required (true) or optional (false).
-
Parameter
public Parameter(String name, Class type, String label, String hint, Object value)
Constructor from attributes.- Parameters:
name
- The paramater's name.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.type
- The type of the parameter.value
- The value (or default value) of the parameter.
-
Parameter
public Parameter(String name, String label, String hint, Object value)
Constructor from attributes.- Parameters:
name
- The paramater's name.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.value
- The value (or default value) of the parameter.
-
Parameter
public Parameter(String name, Class type, String label, String hint)
Constructor from attributes.- Parameters:
name
- The paramater's name.type
- The type of the parameter.label
- A label that might be presented to a user.hint
- A text hint that might be displayed to a user.
-
Parameter
public Parameter(String name, Class type, String label)
Constructor from attributes.- Parameters:
name
- The paramater's name.type
- The type of the parameter.label
- A label that might be presented to a user.
-
Parameter
public Parameter(String name, Class type)
Constructor from attributes.- Parameters:
name
- The paramater's name.type
- The type of the parameter.
-
-
Method Detail
-
getName
@ClonedProperty public String getName()
Getter forname
: The paramater's name.- Returns:
- The paramater's name.
-
setName
public Parameter setName(String newName)
Setter forname
: The paramater's name.- Parameters:
newName
- The paramater's name.
-
getLabel
@ClonedProperty public String getLabel()
Getter forlabel
: A label that might be presented to a user.- Returns:
- A label that might be presented to a user.
-
setLabel
public Parameter setLabel(String newLabel)
Setter forlabel
: A label that might be presented to a user.- Parameters:
newLabel
- A label that might be presented to a user.
-
getHint
@ClonedProperty public String getHint()
Getter forhint
: A text hint that might be displayed to a user.- Returns:
- A text hint that might be displayed to a user.
-
setHint
public Parameter setHint(String newHint)
Setter forhint
: A text hint that might be displayed to a user.- Parameters:
newHint
- A text hint that might be displayed to a user.
-
getType
@ClonedProperty public Class getType()
Getter fortype
: The type of the parameter.- Returns:
- The type of the parameter.
-
setType
public Parameter setType(Class newType)
Setter fortype
: The type of the parameter.- Parameters:
newType
- The type of the parameter.
-
getValue
public Object getValue()
Getter forvalue
: The value (or default value) of the parameter.- Returns:
- The value (or default value) of the parameter.
-
setValue
public Parameter setValue(Object newValue)
Setter forvalue
: The value (or default value) of the parameter.- Parameters:
newValue
- The value (or default value) of the parameter.If newWalue is a String but
getType()
is not java.lang.String, this method will endevor to coerce a value of the correct type.
-
getRequired
@ClonedProperty public boolean getRequired()
Getter forrequired
: Whether the parameter is required (true) or optional (false - the default).- Returns:
- Whether the parameter is required (true) or optional (false).
-
setRequired
public Parameter setRequired(boolean newRequired)
Setter forrequired
: Whether the parameter is required (true) or optional (false).- Parameters:
newRequired
- Whether the parameter is required (true) or optional (false).
-
getPossibleValues
public Collection getPossibleValues()
Getter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.- Returns:
- A list of possible values for
value
, or null if the possible values is not a closed set.
-
setPossibleValues
public Parameter setPossibleValues(Collection newPossibleValues)
Setter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.- Parameters:
newPossibleValues
- A list of possible values forvalue
, or null if the possible values is not a closed set.
-
getPossibleValuesArray
public Object[] getPossibleValuesArray()
Array getter forpossibleValues
: A list of possible values forvalue
, or null if the possible values is not a closed set.- Returns:
- An array of possible values for
value
, or null if the possible values is not a closed set.
-
addPossibleValue
public void addPossibleValue(Object value)
Add a value topossibleValues
.- Parameters:
value
- The possible value to add.
-
addExtraJsonAttributes
public javax.json.JsonObjectBuilder addExtraJsonAttributes(javax.json.JsonObjectBuilder json)
Called at the end of the default implementation ofCloneableBean.toJson()
, this method allows the Parameter to use a String to represent Layer values.- Specified by:
addExtraJsonAttributes
in interfaceCloneableBean
- Parameters:
json
- The JSON object being built.- Returns:
- The builder with any added properties.
-
fromJson
public CloneableBean fromJson(javax.json.JsonObject json)
Initializes the bean with the given JSON representation. This method parses "value" and "possibleValues" before invoking the default implementation to parse the rest.- Specified by:
fromJson
in interfaceCloneableBean
- Parameters:
json
-- Returns:
- A reference to this bean.
-
apply
public void apply(Object bean) throws NoSuchMethodException, SecurityException, IllegalAccessException, InvocationTargetException
Sets the value of the attribute named aftername
of the given bean with the parameter'svalue
.e.g. if the parameter's name is "foo" and it's value is "bar", then the effect of this method is the same as invoking
bean.setFoo("bar")
.- Parameters:
bean
- The object whose bean attribute should be set.- Throws:
NoSuchMethodException
- If the bean has no setter named aftername
.SecurityException
- On error.InvocationTargetException
- On error.IllegalAccessException
- If the setter is nopublic
.
-
extractValue
public Object extractValue(Object bean)
Sets thevalue
of the parameter with the value of the attribute named aftername
of the given bean.e.g. if the parameter's name is "foo" and the bean has a getter called "getFoo()", then the effect of this method is the same as invoking
setValue(bead.getFoo())
, if the value is not null.- Parameters:
bean
- The object whose bean attribute should be set.- Returns:
- The value that was set.
-
-