CardinalConstraintpublic class CardinalConstraint extends ConstraintUtils implements ConstraintCardinalConstraint is a {@link Constraint} to validate the structure.
It implements Constraint interface and extends
{@link ConstraintUtils} class.
match method of this object returns empty
Collection if the value being validated conforms to the
structure specified by this Constraint ; else it returns a
Collection with a {@link ConstraintFailure} object in it.
ConstraintUtils class provides utility methods for formating
failure messages and a print method to print this object. |
Fields Summary |
---|
private int | cardinalThe structure represented by this Constraint . |
Constructors Summary |
---|
public CardinalConstraint()Creates a new instance of CardinalConstraint
cardinal = Constants.MANDATORY_ELEMENT;
| public CardinalConstraint(int cardinal)Creates a new instance of CardinalConstraint .
this.cardinal = cardinal;
| public CardinalConstraint(String cardinal)Creates a new instance of CardinalConstraint .
try {
this.cardinal = Integer.parseInt(cardinal);
} catch(NumberFormatException e) {
String format =
BundleReader.getValue("Error_failed_to_create"); //NOI18N
Object[] arguments =
new Object[]{"CardinalConstraint"}; //NOI18N
System.out.println(MessageFormat.format(format, arguments));
}
|
Methods Summary |
---|
public java.util.Collection | match(java.lang.String value, java.lang.String name)Validates the given value against this Constraint .
return match((Object)value, name);
| public java.util.Collection | match(java.lang.Object value, java.lang.String name)Validates the given value against this Constraint .
Collection failed_constrained_list =
new ArrayList();
if(Constants.MANDATORY_ARRAY == cardinal) {
Object[] values = null;
try {
values = (Object[])value;
} catch(ClassCastException exception){
System.out.println(BundleReader.getValue(
"Error_expects_argument_one_to_be_an_array_of_Objects"));//NOI18N
}
if((null == values) || (values.length < 1)){
String failureMessage = formatFailureMessage(toString(), name);
failed_constrained_list.add(new ConstraintFailure(toString(),
null, name, failureMessage, BundleReader.getValue(
"MSG_CardinalConstraint_Failure"))); //NOI18N
}
} else {
if(Constants.MANDATORY_ELEMENT == cardinal){
if (null == value){
String failureMessage =
formatFailureMessage(toString(), name);
failed_constrained_list.add(
new ConstraintFailure(toString(), null, name,
failureMessage, BundleReader.getValue(
"MSG_CardinalConstraint_Failure"))); //NOI18N
}
}
}
return failed_constrained_list;
| public void | print()Prints this Constraint .
super.print();
String format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
Object[] arguments =
new Object[]{"Cardinal", String.valueOf(cardinal)}; //NOI18N
System.out.println(MessageFormat.format(format, arguments));
| public void | setCardinal(int cardinal)Sets the given cardinal as the structure
represented by this object.
this.cardinal = cardinal;
| public void | setCardinal(java.lang.String cardinal)Sets the given cardinal as the structure
represented by this object.
try {
this.cardinal = Integer.parseInt(cardinal);
} catch(NumberFormatException e) {
String format =
BundleReader.getValue("Error_failed_to_set"); //NOI18N
Object[] arguments =
new Object[]{this.toString(), "Cardinal"}; //NOI18N
System.out.println(MessageFormat.format(format, arguments));
}
|
|