org.rhq.enterprise.communications.command.param
Class FixedValuesParameterDefinition

java.lang.Object
  extended by org.rhq.enterprise.communications.command.param.ParameterDefinition
      extended by org.rhq.enterprise.communications.command.param.FixedValuesParameterDefinition
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DynamicFixedValuesParameterDefinition

public class FixedValuesParameterDefinition
extends ParameterDefinition

An extenstion to a parameter definition that defines a limited, fixed set of values that are allowed to be assigned to the parameter.

Note that only non-array types may have fixed values.

Author:
John Mazzitelli
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.rhq.enterprise.communications.command.param.ParameterDefinition
HIDDEN, NOT_HIDDEN, NOT_NULLABLE, NULLABLE, OPTIONAL, REQUIRED
 
Constructor Summary
FixedValuesParameterDefinition(String name, String type, boolean required, boolean nullable, boolean hidden, List<Object> allowed, String description)
          Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.
FixedValuesParameterDefinition(String name, String type, boolean required, boolean nullable, boolean hidden, List<Object> allowed, String description, ParameterRenderingInformation renderingInfo)
          Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.
FixedValuesParameterDefinition(String name, String type, boolean required, boolean nullable, boolean hidden, Object[] allowed, String description)
          Constructor for FixedValuesParameterDefinition that allows for an optional description to be set and allows the caller to specify an array, as opposed to a List of allowed objects.
FixedValuesParameterDefinition(String name, String type, boolean hidden, List<Object> allowed, String description)
          Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.
FixedValuesParameterDefinition(String name, String type, boolean hidden, List<Object> allowed, String description, ParameterRenderingInformation renderingInfo)
          Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.
 
Method Summary
protected  boolean allowZeroFixedValues()
          Returns true if this parameter definition object allows an empty set of allowed values.
 Object convertObject(Object objectToConvert)
          Makes sure that, after conversion, the object still matches one of the fixed, allowed values.
 List<Object> getAllowedValues()
          Returns the list of the parameter's only allowed values.
protected  ParameterRenderingInformation getDefaultRenderingInfo()
          This parameter definition class will, by default, rendering the parameter as an option list.
 boolean isValidValue(Object valueToCheck)
          Ensures that the parameter's value is one of the fixed set of allowed values.
protected  void setAllowedValues(List<Object> newAllowedValues)
          This method allows subclasses to replace this object's fixed set of allowed values with a new set.
 String toString()
           
 
Methods inherited from class org.rhq.enterprise.communications.command.param.ParameterDefinition
equals, getDescription, getName, getRenderingInfo, getType, hashCode, isHidden, isNullable, isRequired, setDefaultRenderingAttributes, setRenderingInfo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixedValuesParameterDefinition

public FixedValuesParameterDefinition(String name,
                                      String type,
                                      boolean required,
                                      boolean nullable,
                                      boolean hidden,
                                      Object[] allowed,
                                      String description)
                               throws IllegalArgumentException
Constructor for FixedValuesParameterDefinition that allows for an optional description to be set and allows the caller to specify an array, as opposed to a List of allowed objects.

Parameters:
name - the name of the parameter (this is the name you use to look up the parameter value via Command.getParameterValue(String) (must not be null)
type - the parameter data type specified "the Java way"; e.g. "java.lang.String"," [Ljava.util.Date;" (must not be null)
required - if true, this parameter is required to successfully execute a command
nullable - if true, this parameter is allowed to be null
hidden - if true, this parameter should be hidden from users (though it doesn't prohibit users from setting the parameter, it only hides it from user interfaces)
allowed - contains elements that define the only values that are allowed for this parameter (must not be null or empty)
description - a human readable description string that describes the function of the parameter (may be null)
Throws:
IllegalArgumentException - if name or type is null or allowed is null, empty or contains an element whose type is not convertible to type. Also, if type represents an unknown class or an array type.

FixedValuesParameterDefinition

public FixedValuesParameterDefinition(String name,
                                      String type,
                                      boolean hidden,
                                      List<Object> allowed,
                                      String description)
                               throws IllegalArgumentException
Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.

Parameters:
name - the name of the parameter (this is the name you use to look up the parameter value via Command.getParameterValue(String) (must not be null)
type - the parameter data type specified "the Java way"; e.g. "java.lang.String"," [Ljava.util.Date;" (must not be null)
hidden - if true, this parameter should be hidden from users (though it doesn't prohibit users from setting the parameter, it only hides it from user interfaces)
allowed - contains elements that define the only values that are allowed for this parameter (must not be null or empty)
description - a human readable description string that describes the function of the parameter (may be null)
Throws:
IllegalArgumentException - if name or type is null or allowed is null, empty or contains an element whose type is not convertible to type. Also, if type represents an unknown class or an array type.

FixedValuesParameterDefinition

public FixedValuesParameterDefinition(String name,
                                      String type,
                                      boolean hidden,
                                      List<Object> allowed,
                                      String description,
                                      ParameterRenderingInformation renderingInfo)
                               throws IllegalArgumentException
Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.

Parameters:
name - the name of the parameter (this is the name you use to look up the parameter value via Command.getParameterValue(String) (must not be null)
type - the parameter data type specified "the Java way"; e.g. "java.lang.String"," [Ljava.util.Date;" (must not be null)
hidden - if true, this parameter should be hidden from users (though it doesn't prohibit users from setting the parameter, it only hides it from user interfaces)
allowed - contains elements that define the only values that are allowed for this parameter (must not be null or empty)
description - a human readable description string that describes the function of the parameter (may be null)
renderingInfo - information relating to how the parameter should be rendered by clients. See ParameterRenderingInformation
Throws:
IllegalArgumentException - if name or type is null or allowed is null, empty or contains an element whose type is not convertible to type. Also, if type represents an unknown class or an array type.

FixedValuesParameterDefinition

public FixedValuesParameterDefinition(String name,
                                      String type,
                                      boolean required,
                                      boolean nullable,
                                      boolean hidden,
                                      List<Object> allowed,
                                      String description)
                               throws IllegalArgumentException
Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.

Parameters:
name - the name of the parameter (this is the name you use to look up the parameter value via Command.getParameterValue(String) (must not be null)
type - the parameter data type specified "the Java way"; e.g. "java.lang.String"," [Ljava.util.Date;" (must not be null)
required - if true, this parameter is required to successfully execute a command
nullable - if true, this parameter is allowed to be null
hidden - if true, this parameter should be hidden from users (though it doesn't prohibit users from setting the parameter, it only hides it from user interfaces)
allowed - contains elements that define the only values that are allowed for this parameter (must not be null or empty)
description - a human readable description string that describes the function of the parameter (may be null)
Throws:
IllegalArgumentException - if name or type is null or allowed is null, empty or contains an element whose type is not convertible to type. Also, if type represents an unknown class or an array type.

FixedValuesParameterDefinition

public FixedValuesParameterDefinition(String name,
                                      String type,
                                      boolean required,
                                      boolean nullable,
                                      boolean hidden,
                                      List<Object> allowed,
                                      String description,
                                      ParameterRenderingInformation renderingInfo)
                               throws IllegalArgumentException
Constructor for FixedValuesParameterDefinition that allows for an optional description to be set.

Parameters:
name - the name of the parameter (this is the name you use to look up the parameter value via Command.getParameterValue(String) (must not be null)
type - the parameter data type specified "the Java way"; e.g. "java.lang.String"," [Ljava.util.Date;" (must not be null)
required - if true, this parameter is required to successfully execute a command
nullable - if true, this parameter is allowed to be null
hidden - if true, this parameter should be hidden from users (though it doesn't prohibit users from setting the parameter, it only hides it from user interfaces)
allowed - contains elements that define the only values that are allowed for this parameter (must not be null or empty)
description - a human readable description string that describes the function of the parameter (may be null)
renderingInfo - information relating to how the parameter should be rendered by clients. See ParameterRenderingInformation
Throws:
IllegalArgumentException - if name or type is null or allowed is null, empty or contains an element whose type is not convertible to type. Also, if type represents an unknown class or an array type.
Method Detail

getAllowedValues

public List<Object> getAllowedValues()
Returns the list of the parameter's only allowed values. These fixed values may not be changed. The returned list is only a copy; changes to the returned list do not affect the internal list.

Returns:
allowedValues contains elements defining the only allowed values this parameter may be

setAllowedValues

protected void setAllowedValues(List<Object> newAllowedValues)
                         throws IllegalArgumentException
This method allows subclasses to replace this object's fixed set of allowed values with a new set. The items in allowedValues will be copied into this object's own storage area. The old allowed values will be removed - they will no longer be valid.

Parameters:
newAllowedValues - the new list of allowed values
Throws:
IllegalArgumentException - if failed to convert the values to the parameter definition's type or allowedValues was null or empty and this parameter definition object does not accept that (see allowZeroFixedValues()).

isValidValue

public boolean isValidValue(Object valueToCheck)
Ensures that the parameter's value is one of the fixed set of allowed values. The value is checked against the list of allowed values using Object.equals(Object).

Overrides:
isValidValue in class ParameterDefinition
Parameters:
valueToCheck - checking the type validity of this object
Returns:
true if the given object conforms to this parameter definition, false otherwise
See Also:
ParameterDefinition.isValidValue(Object)

convertObject

public Object convertObject(Object objectToConvert)
                     throws InvalidParameterValueException
Makes sure that, after conversion, the object still matches one of the fixed, allowed values.

Overrides:
convertObject in class ParameterDefinition
Parameters:
objectToConvert - the object to convert to the given type
Returns:
the converted object
Throws:
InvalidParameterValueException - if the given object is null but this parameter definition does not allow for null, or the parameter's type specifies a primitive type, or the conversion failed due to a problem occurring while instantiating the new typed object
See Also:
ParameterDefinition.convertObject(Object)

toString

public String toString()
Overrides:
toString in class ParameterDefinition
See Also:
ParameterDefinition.toString()

getDefaultRenderingInfo

protected ParameterRenderingInformation getDefaultRenderingInfo()
This parameter definition class will, by default, rendering the parameter as an option list.

Overrides:
getDefaultRenderingInfo in class ParameterDefinition
Returns:
a default rendering information object that can be used by this parameter definition object
See Also:
ParameterDefinition.getDefaultRenderingInfo()

allowZeroFixedValues

protected boolean allowZeroFixedValues()
Returns true if this parameter definition object allows an empty set of allowed values. It will return false if the fixed set of allowed values must have at least one value. This implementation always returns false since this class does not allow for the list of fixed values to change dynamically at runtime (thus, having an empty set of fixed values essentially renders this definition useless since no values will ever be considered valid). This is only useful if the parameter definition allows the fixed list of allowed values to be changed dynamically - if subclasses do allow for this use-case, those subclasses should override this method to have it return true.

Returns:
this method implementation always returns false


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.