com.braintreegateway
Class ValidationErrors

java.lang.Object
  extended by com.braintreegateway.ValidationErrors

public class ValidationErrors
extends Object

Represents a collection of (nested) validation errors. Query for validation errors by object and field. For Example:

  TransactionRequest request = new TransactionRequest().
      amount(null).
   Result result = gateway.transaction().sale(request);
   Assert.assertFalse(result.isSuccess());
   ValidationErrors errors = result.getErrors();
   Assert.assertEquals(ValidationErrorCode.TRANSACTION_AMOUNT_IS_REQUIRED, errors.forObject("transaction").onField("amount").get(0).getCode());
 
For more detailed information on ValidationErrors, see http://www.braintreepayments.com/gateway/validation-errors


Field Summary
private  List<ValidationError> errors
           
private  Map<String,ValidationErrors> nestedErrors
           
 
Constructor Summary
ValidationErrors()
           
ValidationErrors(NodeWrapper node)
           
 
Method Summary
 void addError(ValidationError error)
           
 void addErrors(String objectName, ValidationErrors errors)
           
 int deepSize()
          Returns the number of errors on this object and all nested objects.
 ValidationErrors forIndex(int index)
           
 ValidationErrors forObject(String objectName)
          Returns a ValidationErrors representing nested errors for the given ojbectName.
 List<ValidationError> getAllDeepValidationErrors()
          Returns a List of all of the ValidationError on this object and all nested objects.
 List<ValidationError> getAllValidationErrors()
          Returns a List of all of the ValidationError objects at the current nesting level.
 List<ValidationError> onField(String fieldName)
          Returns a List of ValidationError objects for the given field.
private  void populateErrors(NodeWrapper node)
           
private  void populateTopLevelErrors(List<NodeWrapper> childErrors)
           
 int size()
          Returns the number of errors on this object at the current nesting level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errors

private List<ValidationError> errors

nestedErrors

private Map<String,ValidationErrors> nestedErrors
Constructor Detail

ValidationErrors

public ValidationErrors()

ValidationErrors

public ValidationErrors(NodeWrapper node)
Method Detail

addError

public void addError(ValidationError error)

addErrors

public void addErrors(String objectName,
                      ValidationErrors errors)

deepSize

public int deepSize()
Returns the number of errors on this object and all nested objects.

Returns:
the number of errors.
See Also:
size()

forIndex

public ValidationErrors forIndex(int index)

forObject

public ValidationErrors forObject(String objectName)
Returns a ValidationErrors representing nested errors for the given ojbectName.

Parameters:
objectName - the name of the object with nested validation errors, e.g. customer or creditCard.
Returns:
a ValidationErrors object.

getAllDeepValidationErrors

public List<ValidationError> getAllDeepValidationErrors()
Returns a List of all of the ValidationError on this object and all nested objects.

Returns:
a List of ValidationError objects.

getAllValidationErrors

public List<ValidationError> getAllValidationErrors()
Returns a List of all of the ValidationError objects at the current nesting level.

Returns:
a List of ValidationError objects.

onField

public List<ValidationError> onField(String fieldName)
Returns a List of ValidationError objects for the given field.

Parameters:
fieldName - the name of the field with errors, e.g. amount or expirationDate.
Returns:
a List of ValidationError objects

populateErrors

private void populateErrors(NodeWrapper node)

populateTopLevelErrors

private void populateTopLevelErrors(List<NodeWrapper> childErrors)

size

public int size()
Returns the number of errors on this object at the current nesting level.

Returns:
the number of errors.
See Also:
deepSize()


Copyright © 2013. All Rights Reserved.