FileDocCategorySizeDatePackage
ArrayConstraint.javaAPI DocExample2527Sun Dec 14 22:47:36 GMT 2003oreilly.hcj.datamodeling.constraints

ArrayConstraint

public class ArrayConstraint extends ObjectConstraint
Models a constraint on objects that are arrays.

Objects of this class are immutable.

author
Robert Simmons jr.
version
$Revision: 1.1 $

Fields Summary
protected long
maxSize
Holds value of property maxSize.
Constructors Summary
public ArrayConstraint(String name, boolean optional, Class dataType, long maxSize)
Creates a new instance of ArrayConstraint.

param
name Contains the name of the constraint.
param
optional Indicates if the property is optional.
param
dataType The type of number this class is validating.
param
maxSize The maximum size for the byte array.
throws
IllegalArgumentException If the dataType isn't an array.
see
mirror.datamodel.constraints.Constraint

		super(name, optional, dataType);

		if (!dataType.isArray()) {
			throw new IllegalArgumentException("The dataType must be an Array");  //$NON-NLS-1$
		}

		this.maxSize = maxSize;
	
Methods Summary
public longgetMaxSize()
Getter for property maxSize.

return
Value of property maxSize.

		return this.maxSize;
	
public voidvalidate(java.lang.Object obj)
Validate the given object against the constraint. Checks to make sure the array is within the size limitation and then passes checking to the superclass.

param
obj The object to validate.
throws
ConstraintException If the constraint is violated.

		super.validate(obj);

		if (obj != null) {
			if (!obj.getClass()
			        .isArray()) {
				throw new ConstraintException(ConstraintExceptionType.INVALID_DATA_TYPE);
			}

			if (Array.getLength(obj) > maxSize) {
				throw new ConstraintException(ConstraintExceptionType.ARRAY_TOO_LARGE);
			}
		}