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,ModuleNameValidator,ObjectTypeValidator,PropertyValidator,StringAllowedValuesValidator,StringBytesLengthValidator,StringLengthValidator,TimeUnitValidator
Validates that the given parameter is of the correct type.
Note on strict type matching:
The constructor takes a parameter strictType. If strictType is false, 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
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimalprotected static final BigDecimalprotected static final BigIntegerprotected static final BigIntegerprotected final booleanprotected final booleanprotected final Set<org.jboss.dmr.ModelType> -
Constructor Summary
ConstructorsConstructorDescriptionModelTypeValidator(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
Modifier and TypeMethodDescriptionvoidvalidateParameter(String parameterName, org.jboss.dmr.ModelNode value) Validate the parameter with the given name.
-
Field Details
-
BIGDECIMAL_MAX
-
BIGDECIMAL_MIN
-
BIGINTEGER_MAX
-
BIGINTEGER_MIN
-
validTypes
-
nullable
protected final boolean nullable -
strictType
protected final boolean strictType
-
-
Constructor Details
-
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 benullnullable- whetherModelType.UNDEFINEDis 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 benullnullable- whetherModelType.UNDEFINEDis allowedallowExpressions- whetherModelType.EXPRESSIONis 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 benullnullable- whetherModelType.UNDEFINEDis allowedallowExpressions- whetherModelType.EXPRESSIONis allowedstrictType-trueif the type of a node must precisely matchtype;falseif 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.UNDEFINEDis allowedallowExpressions- whetherModelType.EXPRESSIONis allowedstrictType-trueif the type of a node must precisely matchtype;falseif the value conversions described in the class javadoc can be performed to check for compatible typesfirstValidType- a valid type. Cannot benullotherValidTypes- additional valid types. May benull
-
-
Method Details
-
validateParameter
public void validateParameter(String parameterName, org.jboss.dmr.ModelNode value) throws OperationFailedException Validate the parameter with the given name.- Specified by:
validateParameterin interfaceParameterValidator- Parameters:
parameterName- the name of the parameter. Cannot benullvalue- the parameter value. Cannot benull- Throws:
OperationFailedException- if the value is not valid
-