Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv9288/src/Spring/Spring.Core/Validation
Modified Files:
AnyValidatorGroup.cs BaseValidationAction.cs BaseValidator.cs
CollectionValidator.cs ExclusiveValidatorGroup.cs
IValidationAction.cs IValidator.cs ValidationErrors.cs
ValidatorGroup.cs ValidatorReference.cs
Added Files:
IValidationErrors.cs ValidationException.cs
Log Message:
Extracted IValidationErrors interface and made ValidationErrors non-sealed.
Added ValidationException class.
Modified email, credit card, isbn and url validators to return true (valid) if object to validate is null or empty.
Index: ValidatorReference.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/ValidatorReference.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ValidatorReference.cs 9 Apr 2006 07:19:01 -0000 1.4
--- ValidatorReference.cs 5 Feb 2008 20:40:26 -0000 1.5
***************
*** 93,97 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, ValidationErrors errors)
{
return Validate(validationContext, null, errors);
--- 93,97 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, IValidationErrors errors)
{
return Validate(validationContext, null, errors);
***************
*** 105,109 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
if (Context != null)
--- 105,109 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
if (Context != null)
Index: ValidationErrors.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/ValidationErrors.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ValidationErrors.cs 31 Jul 2007 03:47:23 -0000 1.8
--- ValidationErrors.cs 5 Feb 2008 20:40:26 -0000 1.9
***************
*** 27,32 ****
using System.Xml.Serialization;
using Spring.Context;
- using Spring.Core;
- using Spring.Objects;
using Spring.Util;
--- 27,30 ----
***************
*** 49,53 ****
/// <version>$Id$</version>
[Serializable]
! public sealed class ValidationErrors : IXmlSerializable
{
#region Constructors
--- 47,51 ----
/// <version>$Id$</version>
[Serializable]
! public class ValidationErrors : IValidationErrors, IXmlSerializable
{
#region Constructors
***************
*** 177,198 ****
/// instance's collection of errors.
/// </summary>
! /// <param name="key">
! /// The key that should be used for message grouping; can't be
/// <see lang="null"/>.
/// </param>
/// <param name="message">The error message to add.</param>
/// <exception cref="System.ArgumentNullException">
! /// If the supplied <paramref name="key"/> or <paramref name="message"/> is <see langword="null"/>.
/// </exception>
! public void AddError(string key, ErrorMessage message)
{
! AssertUtils.ArgumentNotNull(key, "key");
AssertUtils.ArgumentNotNull(message, "errorMessage");
! IList errors = (IList) errorMap[key];
if (errors == null)
{
errors = new ArrayList();
! errorMap[key] = errors;
}
errors.Add(message);
--- 175,196 ----
/// instance's collection of errors.
/// </summary>
! /// <param name="provider">
! /// The provider that should be used for message grouping; can't be
/// <see lang="null"/>.
/// </param>
/// <param name="message">The error message to add.</param>
/// <exception cref="System.ArgumentNullException">
! /// If the supplied <paramref name="provider"/> or <paramref name="message"/> is <see langword="null"/>.
/// </exception>
! public void AddError(string provider, ErrorMessage message)
{
! AssertUtils.ArgumentNotNull(provider, "provider");
AssertUtils.ArgumentNotNull(message, "errorMessage");
! IList errors = (IList) errorMap[provider];
if (errors == null)
{
errors = new ArrayList();
! errorMap[provider] = errors;
}
errors.Add(message);
***************
*** 232,271 ****
/// <summary>
! /// Gets the list of errors for the supplied lookup <paramref name="key"/>.
/// </summary>
/// <remarks>
/// <p>
! /// If there are no errors for the supplied lookup <paramref name="key"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
! /// <param name="key">Error key that was used to group messages.</param>
/// <returns>
! /// A list of all <see cref="ErrorMessage"/>s for the supplied lookup <paramref name="key"/>.
/// </returns>
! public IList GetErrors(string key)
{
! IList errors = (IList) errorMap[key];
return errors == null ? ObjectUtils.EmptyObjects : errors;
}
/// <summary>
! /// Gets the list of resolved error messages for the supplied lookup <paramref name="key"/>.
/// </summary>
/// <remarks>
/// <p>
! /// If there are no errors for the supplied lookup <paramref name="key"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
! /// <param name="key">Error key that was used to group messages.</param>
/// <param name="messageSource"><see cref="IMessageSource"/> to resolve messages against.</param>
/// <returns>
! /// A list of resolved error messages for the supplied lookup <paramref name="key"/>.
/// </returns>
! public IList GetResolvedErrors(string key, IMessageSource messageSource)
{
IList messages = new ArrayList();
! IList errors = (IList) errorMap[key];
if (errors != null)
--- 230,269 ----
/// <summary>
! /// Gets the list of errors for the supplied lookup <paramref name="provider"/>.
/// </summary>
/// <remarks>
/// <p>
! /// If there are no errors for the supplied lookup <paramref name="provider"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
! /// <param name="provider">Error key that was used to group messages.</param>
/// <returns>
! /// A list of all <see cref="ErrorMessage"/>s for the supplied lookup <paramref name="provider"/>.
/// </returns>
! public IList GetErrors(string provider)
{
! IList errors = (IList) errorMap[provider];
return errors == null ? ObjectUtils.EmptyObjects : errors;
}
/// <summary>
! /// Gets the list of resolved error messages for the supplied lookup <paramref name="provider"/>.
/// </summary>
/// <remarks>
/// <p>
! /// If there are no errors for the supplied lookup <paramref name="provider"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
! /// <param name="provider">Error key that was used to group messages.</param>
/// <param name="messageSource"><see cref="IMessageSource"/> to resolve messages against.</param>
/// <returns>
! /// A list of resolved error messages for the supplied lookup <paramref name="provider"/>.
/// </returns>
! public IList GetResolvedErrors(string provider, IMessageSource messageSource)
{
IList messages = new ArrayList();
! IList errors = (IList) errorMap[provider];
if (errors != null)
***************
*** 284,288 ****
#region Data members
! private IDictionary errorMap = new Hashtable();
#endregion
--- 282,286 ----
#region Data members
! private readonly IDictionary errorMap = new Hashtable();
#endregion
Index: BaseValidationAction.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/BaseValidationAction.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** BaseValidationAction.cs 9 Apr 2006 07:19:01 -0000 1.5
--- BaseValidationAction.cs 5 Feb 2008 20:40:26 -0000 1.6
***************
*** 79,83 ****
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! public virtual void Execute(bool isValid, object validationContext, IDictionary contextParams, ValidationErrors errors)
{
if (EvaluateWhen(validationContext, contextParams))
--- 79,83 ----
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! public virtual void Execute(bool isValid, object validationContext, IDictionary contextParams, IValidationErrors errors)
{
if (EvaluateWhen(validationContext, contextParams))
***************
*** 104,108 ****
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected virtual void OnValid(object validationContext, IDictionary contextParams, ValidationErrors errors)
{}
--- 104,108 ----
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected virtual void OnValid(object validationContext, IDictionary contextParams, IValidationErrors errors)
{}
***************
*** 113,117 ****
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected virtual void OnInvalid(object validationContext, IDictionary contextParams, ValidationErrors errors)
{}
--- 113,117 ----
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected virtual void OnInvalid(object validationContext, IDictionary contextParams, IValidationErrors errors)
{}
Index: ValidatorGroup.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/ValidatorGroup.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ValidatorGroup.cs 9 Apr 2006 07:19:01 -0000 1.9
--- ValidatorGroup.cs 5 Feb 2008 20:40:26 -0000 1.10
***************
*** 94,98 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
bool valid = true;
--- 94,98 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
bool valid = true;
Index: BaseValidator.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/BaseValidator.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** BaseValidator.cs 9 Apr 2006 07:19:01 -0000 1.11
--- BaseValidator.cs 5 Feb 2008 20:40:26 -0000 1.12
***************
*** 123,127 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, ValidationErrors errors)
{
return Validate(validationContext, null, errors);
--- 123,127 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public bool Validate(object validationContext, IValidationErrors errors)
{
return Validate(validationContext, null, errors);
***************
*** 135,139 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public virtual bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
bool valid = true;
--- 135,139 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public virtual bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
bool valid = true;
***************
*** 195,199 ****
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected void ProcessActions(bool isValid, object validationContext, IDictionary contextParams, ValidationErrors errors)
{
if (actions != null && actions.Count > 0)
--- 195,199 ----
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! protected void ProcessActions(bool isValid, object validationContext, IDictionary contextParams, IValidationErrors errors)
{
if (actions != null && actions.Count > 0)
--- NEW FILE: ValidationException.cs ---
(This appears to be a binary file; contents omitted.)
Index: IValidator.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/IValidator.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** IValidator.cs 9 Apr 2006 07:19:01 -0000 1.7
--- IValidator.cs 5 Feb 2008 20:40:26 -0000 1.8
***************
*** 43,47 ****
/// custom validation ligic being implemented in an override of the
/// <see lang="abstract"/>
! /// <see cref="BaseValidator.Validate(object, ValidationErrors)"/>
/// template method.
/// </p>
--- 43,47 ----
/// custom validation ligic being implemented in an override of the
/// <see lang="abstract"/>
! /// <see cref="BaseValidator.Validate(object, IValidationErrors)"/>
/// template method.
/// </p>
***************
*** 63,67 ****
/// <see lang="true"/> if validation was successful.
/// </returns>
! bool Validate(object validationContext, ValidationErrors errors);
/// <summary>
--- 63,67 ----
/// <see lang="true"/> if validation was successful.
/// </returns>
! bool Validate(object validationContext, IValidationErrors errors);
/// <summary>
***************
*** 77,81 ****
/// <see lang="true"/> if validation was successful.
/// </returns>
! bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors);
}
--- 77,81 ----
/// <see lang="true"/> if validation was successful.
/// </returns>
! bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors);
}
--- NEW FILE: IValidationErrors.cs ---
using System.Collections;
using Spring.Context;
namespace Spring.Validation
{
/// <summary>
/// An interface that validation errors containers have to implement.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: IValidationErrors.cs,v 1.1 2008/02/05 20:40:26 aseovic Exp $</version>
public interface IValidationErrors
{
/// <summary>
/// Does this instance contain any validation errors?
/// </summary>
/// <remarks>
/// <p>
/// If this returns <see lang="true"/>, this means that it (obviously)
/// contains no validation errors.
/// </p>
/// </remarks>
/// <value><see lang="true"/> if this instance is empty.</value>
bool IsEmpty { get; }
/// <summary>
/// Gets the list of all error providers.
/// </summary>
IList Providers { get; }
/// <summary>
/// Adds the supplied <paramref name="message"/> to this
/// instance's collection of errors.
/// </summary>
/// <param name="provider">
/// The provider that should be used for message grouping; can't be
/// <see lang="null"/>.
/// </param>
/// <param name="message">The error message to add.</param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="provider"/> or <paramref name="message"/> is <see langword="null"/>.
/// </exception>
void AddError(string provider, ErrorMessage message);
/// <summary>
/// Merges another instance of <see cref="ValidationErrors"/> into this one.
/// </summary>
/// <remarks>
/// <p>
/// If the supplied <paramref name="errorsToMerge"/> is <see lang="null"/>,
/// then no errors will be added to this instance, and this method will
/// (silently) return.
/// </p>
/// </remarks>
/// <param name="errorsToMerge">
/// The validation errors to merge; can be <see lang="null"/>.
/// </param>
void MergeErrors(ValidationErrors errorsToMerge);
/// <summary>
/// Gets the list of errors for the supplied error <paramref name="provider"/>.
/// </summary>
/// <remarks>
/// <p>
/// If there are no errors for the supplied <paramref name="provider"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
/// <param name="provider">Error key that was used to group messages.</param>
/// <returns>
/// A list of all <see cref="ErrorMessage"/>s for the supplied lookup <paramref name="provider"/>.
/// </returns>
IList GetErrors(string provider);
/// <summary>
/// Gets the list of resolved error messages for the supplied lookup <paramref name="provider"/>.
/// </summary>
/// <remarks>
/// <p>
/// If there are no errors for the supplied lookup <paramref name="provider"/>,
/// an <b>empty</b> <see cref="System.Collections.IList"/> will be returned.
/// </p>
/// </remarks>
/// <param name="provider">Error key that was used to group messages.</param>
/// <param name="messageSource"><see cref="IMessageSource"/> to resolve messages against.</param>
/// <returns>
/// A list of resolved error messages for the supplied lookup <paramref name="provider"/>.
/// </returns>
IList GetResolvedErrors(string provider, IMessageSource messageSource);
}
}
Index: CollectionValidator.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/CollectionValidator.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CollectionValidator.cs 10 Oct 2007 18:10:17 -0000 1.4
--- CollectionValidator.cs 5 Feb 2008 20:40:26 -0000 1.5
***************
*** 140,144 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
if (Context != null)
--- 140,144 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
if (Context != null)
***************
*** 164,168 ****
// OR to pass validation errors collection that was passed to this method
//(and collect all error messages returned by the item validators)
! ValidationErrors err = (includeElementErrors)? errors : new ValidationErrors();
foreach (object objectToValidate in collectionToValidate)
--- 164,168 ----
// OR to pass validation errors collection that was passed to this method
//(and collect all error messages returned by the item validators)
! IValidationErrors err = (includeElementErrors)? errors : new ValidationErrors();
foreach (object objectToValidate in collectionToValidate)
Index: ExclusiveValidatorGroup.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/ExclusiveValidatorGroup.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ExclusiveValidatorGroup.cs 28 Feb 2007 20:30:25 -0000 1.7
--- ExclusiveValidatorGroup.cs 5 Feb 2008 20:40:26 -0000 1.8
***************
*** 73,79 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
! ValidationErrors tmpErrors = new ValidationErrors();
bool valid = true;
--- 73,79 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
! IValidationErrors tmpErrors = new ValidationErrors();
bool valid = true;
Index: IValidationAction.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/IValidationAction.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** IValidationAction.cs 9 Apr 2006 07:19:01 -0000 1.3
--- IValidationAction.cs 5 Feb 2008 20:40:26 -0000 1.4
***************
*** 53,57 ****
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! void Execute(bool isValid, object validationContext, IDictionary contextParams, ValidationErrors errors);
}
}
\ No newline at end of file
--- 53,57 ----
/// <param name="contextParams">Additional context parameters.</param>
/// <param name="errors">Validation errors container.</param>
! void Execute(bool isValid, object validationContext, IDictionary contextParams, IValidationErrors errors);
}
}
\ No newline at end of file
Index: AnyValidatorGroup.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Validation/AnyValidatorGroup.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** AnyValidatorGroup.cs 9 Apr 2006 07:19:01 -0000 1.8
--- AnyValidatorGroup.cs 5 Feb 2008 20:40:26 -0000 1.9
***************
*** 74,78 ****
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, ValidationErrors errors)
{
ValidationErrors tmpErrors = new ValidationErrors();
--- 74,78 ----
/// <param name="errors"><see cref="ValidationErrors"/> instance to add error messages to.</param>
/// <returns><c>True</c> if validation was successful, <c>False</c> otherwise.</returns>
! public override bool Validate(object validationContext, IDictionary contextParams, IValidationErrors errors)
{
ValidationErrors tmpErrors = new ValidationErrors();
|