Class ModelTypeValidator
- java.lang.Object
-
- org.jboss.as.controller.operations.validation.ModelTypeValidator
-
- All Implemented Interfaces:
ParameterValidator
- Direct Known Subclasses:
BytesValidator
,CharsetValidator
,EnumValidator
,InetAddressValidator
,IntAllowedValuesValidator
,IntRangeValidator
,ListValidator
,LongRangeValidator
,MapValidator
,MaskedAddressValidator
,ObjectTypeValidator
,PropertyValidator
,StringAllowedValuesValidator
,StringBytesLengthValidator
,StringLengthValidator
,TimeUnitValidator
public class ModelTypeValidator extends Object implements ParameterValidator
Validates that the given parameter is of the correct type.Note on strict type matching:
The constructor takes a parameter
strictType
. IfstrictType
isfalse
, nodes being validated do not need to precisely match the type(s) passed to the constructor; rather a limited set of value conversions will be attempted, and if the node value can be converted, the node is considered to match the required type. The conversions are:- For BIG_DECIMAL, BIG_INTEGER, DOUBLE, INT, LONG and PROPERTY, the related ModelNode.asXXX() method is invoked; if no exception is thrown the type is considered to match.
- For BOOLEAN, if the node is of type BOOLEAN it is considered to match. If it is of type STRING with a value ignoring case of "true" or "false" it is considered to match.
- For OBJECT, if the node is of type OBJECT or PROPERTY it is considered to match. If it is of type LIST and each element in the list is of type PROPERTY it is considered to match.
- For STRING, if the node is of type STRING, BIG_DECIMAL, BIG_INTEGER, DOUBLE, INT or LONG it is considered to match.
- Author:
- Brian Stansberry (c) 2011 Red Hat Inc.
-
-
Field Summary
Fields Modifier and Type Field Description protected static BigDecimal
BIGDECIMAL_MAX
protected static BigDecimal
BIGDECIMAL_MIN
protected static BigInteger
BIGINTEGER_MAX
protected static BigInteger
BIGINTEGER_MIN
protected boolean
nullable
protected boolean
strictType
protected Set<org.jboss.dmr.ModelType>
validTypes
-
Constructor Summary
Constructors Constructor Description ModelTypeValidator(boolean nullable, boolean allowExpressions, boolean strictType, org.jboss.dmr.ModelType firstValidType, org.jboss.dmr.ModelType... otherValidTypes)
Creates a ModelTypeValidator that allows potentially more than one type.ModelTypeValidator(org.jboss.dmr.ModelType type)
Same asModelTypeValidator(type, false, false, false)
.ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable)
Same asModelTypeValidator(type, nullable, false, false)
.ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable, boolean allowExpressions)
Same asModelTypeValidator(type, nullable, allowExpressions, false)
.ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable, boolean allowExpressions, boolean strictType)
Creates a ModelTypeValidator that allows the given type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
validateParameter(String parameterName, org.jboss.dmr.ModelNode value)
Validate the parameter with the given name.
-
-
-
Field Detail
-
BIGDECIMAL_MAX
protected static final BigDecimal BIGDECIMAL_MAX
-
BIGDECIMAL_MIN
protected static final BigDecimal BIGDECIMAL_MIN
-
BIGINTEGER_MAX
protected static final BigInteger BIGINTEGER_MAX
-
BIGINTEGER_MIN
protected static final BigInteger BIGINTEGER_MIN
-
validTypes
protected final Set<org.jboss.dmr.ModelType> validTypes
-
nullable
protected final boolean nullable
-
strictType
protected final boolean strictType
-
-
Constructor Detail
-
ModelTypeValidator
public ModelTypeValidator(org.jboss.dmr.ModelType type)
Same asModelTypeValidator(type, false, false, false)
.- Parameters:
type
- the valid type. Cannot benull
-
ModelTypeValidator
public ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable)
Same asModelTypeValidator(type, nullable, false, false)
.- Parameters:
type
- the valid type. Cannot benull
nullable
- whetherModelType.UNDEFINED
is allowed
-
ModelTypeValidator
public ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable, boolean allowExpressions)
Same asModelTypeValidator(type, nullable, allowExpressions, false)
.- Parameters:
type
- the valid type. Cannot benull
nullable
- whetherModelType.UNDEFINED
is allowedallowExpressions
- whetherModelType.EXPRESSION
is allowed
-
ModelTypeValidator
public ModelTypeValidator(org.jboss.dmr.ModelType type, boolean nullable, boolean allowExpressions, boolean strictType)
Creates a ModelTypeValidator that allows the given type.- Parameters:
type
- the valid type. Cannot benull
nullable
- whetherModelType.UNDEFINED
is allowedallowExpressions
- whetherModelType.EXPRESSION
is allowedstrictType
-true
if the type of a node must precisely matchtype
;false
if the value conversions described in the class javadoc can be performed to check for compatible types
-
ModelTypeValidator
public ModelTypeValidator(boolean nullable, boolean allowExpressions, boolean strictType, org.jboss.dmr.ModelType firstValidType, org.jboss.dmr.ModelType... otherValidTypes)
Creates a ModelTypeValidator that allows potentially more than one type.- Parameters:
nullable
- whetherModelType.UNDEFINED
is allowedallowExpressions
- whetherModelType.EXPRESSION
is allowedstrictType
-true
if the type of a node must precisely matchtype
;false
if the value conversions described in the class javadoc can be performed to check for compatible typesfirstValidType
- a valid type. Cannot benull
otherValidTypes
- additional valid types. May benull
-
-
Method Detail
-
validateParameter
public void validateParameter(String parameterName, org.jboss.dmr.ModelNode value) throws OperationFailedException
Validate the parameter with the given name.- Specified by:
validateParameter
in interfaceParameterValidator
- Parameters:
parameterName
- the name of the parameter. Cannot benull
value
- the parameter value. Cannot benull
- Throws:
OperationFailedException
- if the value is not valid
-
-