You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/06/22 22:20:54 UTC
svn commit: r192994 - in /struts/sandbox/trunk/overdrive/Nexus: Core/
Core/Tables/ Core/Validators/ Test/ Test/Resources/Command/
Author: husted
Date: Wed Jun 22 13:20:53 2005
New Revision: 192994
URL: http://svn.apache.org/viewcvs?rev=192994&view=rev
Log:
OVR-13
OVR-12
* Refactor IFieldTable and Validators members to create a list of "Processors" that convert and format fields. Each field can specify a Processor in the FieldTable. The fields Processor is utilized when we need to covert or format the value. The notion of a Processor replaces declaring the DataType for a field. We can have standard Processors for the usual DataTypes, but a Processor can be used to do anything needed with a field, including inserting and stripping punctuation (telephone numbers).
* Right now, the Processors are in the Validator namespace, but that will change in a future commit. Processors have the effect of validating a data type, but we would still need Validators to test the range of values within a data type, and so forth.
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ConvertInput.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/FormatOutput.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidator.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidatorContext.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ValidatorContext.cs
struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs
struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj Wed Jun 22 13:20:53 2005
@@ -184,22 +184,47 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Validators\CollectionProcessor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Validators\ConvertInput.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
+ RelPath = "Validators\DateTimeProcessor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Validators\FormatOutput.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
+ RelPath = "Validators\IProcessor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Validators\IValidator.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Validators\IValidatorContext.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Validators\Processor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Validators\StringProcessor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs Wed Jun 22 13:20:53 2005
@@ -32,29 +32,10 @@
set { this [Tokens.DataFormat] = value; }
}
- public Type DataType
+ public string ProcessorID
{
- get
- {
- Type v = this [Tokens.DataType] as Type;
- if (v == null) v = typeof (String);
- return v;
- }
- set
- {
- this [Tokens.DataType] = value;
- this [Tokens.DataTypeName] = value.FullName;
- }
- }
-
- public string DataTypeName
- {
- get { return this [Tokens.DataTypeName] as string; }
- set
- {
- this [Tokens.DataType] = Type.GetType (value);
- this [Tokens.DataTypeName] = value;
- }
+ get { return this [Tokens.DataTypeID] as string; }
+ set { this [Tokens.DataTypeID] = value; }
}
public string Hint
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs Wed Jun 22 13:20:53 2005
@@ -23,6 +23,8 @@
{
#region IFieldTable
+ #region Field
+
private bool _Strict = false;
public virtual bool Strict
{
@@ -30,345 +32,107 @@
set { _Strict = value; }
}
- public virtual IFieldContext AddField
+ public virtual IFieldContext AddFieldContext
{
set
{
if (value == null)
- throw new ArgumentNullException ("value", "Agility.Nexus.FieldTable.AddField");
- this [value.ID] = value;
+ throw new ArgumentNullException ("value", "Nexus.Core.Tables.FieldTable.AddFieldContext");
+ Field [value.ID] = value;
}
}
- public virtual IList AddFields
+ public virtual IList AddFieldContexts
{
set
{
if (value == null)
- throw new ArgumentNullException ("value", "Agility.Nexus.FieldTable.AddFields");
+ throw new ArgumentNullException ("value", "Nexus.Core.Tables.FieldTable.AddFieldContexts");
IEnumerator elements = value.GetEnumerator ();
- while (elements.MoveNext ()) AddField = elements.Current as IFieldContext;
+ while (elements.MoveNext ()) AddFieldContext = elements.Current as IFieldContext;
}
}
- public virtual string Alert (string id)
+ public virtual IFieldContext GetFieldContext (string id)
{
- return GetField (id).Alert;
+ IFieldContext fieldContext = Field [id] as IFieldContext;
+ bool problem = ((fieldContext == null) && (Strict));
+ if (problem)
+ throw new ArgumentNullException ("Nexus.Core.Tables.FieldTable", "GetFieldContext");
+ return fieldContext;
}
- // FIXME: This is begging for a Chain
- public virtual bool Convert_Execute (IValidatorContext context)
- {
- bool okay = false;
- string id = context.FieldKey;
- string source = context.Source as string;
- IFieldContext fieldContext = GetField (id); // enforces Strict
-
- #region Not registered
-
- if ((fieldContext == null))
- {
- context.Target = source;
- return true;
- }
-
- #endregion
+ #endregion
- #region Registered
+ #region Processor
- bool processed = false;
-
- // Collection
- if (IsCollectionType (fieldContext.DataType))
- {
- processed = true;
- context.Target = source; // TODO: Recurse into collection
- okay = true;
- }
-
- // Date
- if (IsDateType (fieldContext.DataType))
- {
- processed = true;
- if (IsStringEmpty (source))
- {
- DateTime t = DateTime_Convert (fieldContext, source);
- bool isDateTimeEmpty = DateTime_Empty.Equals (t);
- okay = !isDateTimeEmpty;
- context.Target = t;
- }
- else
- {
- context.Target = null; // FIXME: We could use DateTime_Empty here,
- okay = true; // but there was an issue with iBATIS (is there still?)
- }
- }
-
- // String
- if (IsStringType (fieldContext.DataType))
+ public virtual IProcessor AddProcessor
+ {
+ set
{
- processed = true;
- context.Target = String_Convert (fieldContext, source);
- okay = true;
+ if (value == null)
+ throw new ArgumentNullException ("value", "Nexus.Core.Tables.FieldTable.AddProcessor");
+ Processor [value.ID] = value;
}
-
- // TODO: Other types.
-
- #endregion
-
- if (!processed)
- throw new ArgumentOutOfRangeException ("Nexus.Core.FieldTable.DataType", id);
-
- return okay;
}
- // FIXME: This is begging for a Chain
- public virtual bool Format_Execute (IValidatorContext context)
+ public virtual IList AddProcessors
{
- bool okay = false;
- string id = context.FieldKey;
- object source = context.Source;
- IFieldContext fieldContext = GetField (id); // Enforces Strict
-
- #region Not Registered
-
- if ((fieldContext == null))
- {
- if (source == null)
- context.Target = null;
- else
- {
- Type sourceType = source.GetType ();
- if (IsCollectionType (sourceType)) context.Target = source;
- else context.Target = source.ToString ();
- }
- return true;
- }
-
- #endregion
-
- #region Registered
-
- bool processed = false;
-
- // Collection
- if (IsCollectionType (fieldContext.DataType))
- {
- processed = true;
- context.Target = source; // TODO: Recurse into collection
- okay = true;
- }
-
- // Date
- if (IsDateType (fieldContext.DataType))
- {
- processed = true;
- if (IsDateEmpty (source))
- {
- context.Target = String.Empty;
- okay = true;
- }
- else
- {
- string target = DateTime_Format (fieldContext, source);
- context.Target = target;
- okay = IsStringEmpty (target);
- }
- }
-
- // String
- if (IsStringType (fieldContext.DataType))
+ set
{
- processed = true;
- context.Target = String_Format (fieldContext, source);
- okay = true;
+ if (value == null)
+ throw new ArgumentNullException ("value", "Nexus.Core.Tables.FieldTable.AddProcessors");
+ IEnumerator elements = value.GetEnumerator ();
+ while (elements.MoveNext ()) AddProcessor = elements.Current as IProcessor;
}
-
- // TODO: Other types.
-
- #endregion
-
- if (!processed)
- throw new ArgumentOutOfRangeException ("Agility.Nexus.FieldTable.DataType", id);
-
- return okay;
}
- public virtual IFieldContext GetField (string id)
+ public virtual IProcessor GetProcessor (string id)
{
- IFieldContext fieldContext = this [id] as IFieldContext;
- bool problem = ((fieldContext == null) && (Strict));
- if (problem)
- throw new ArgumentNullException ("Agility.Nexus.FieldTable", "GetField");
- return fieldContext;
+ IProcessor processor = Processor [id] as IProcessor;
+ if (processor == null)
+ throw new ArgumentNullException (id, "Nexus.Core.Tables.FieldTable.GetProcessor");
+ return processor;
}
#endregion
- // TODO: Create a IDataTrip interface with IsType, IsEmpty, Convert, and Format methods.
- // The runtime instances could then be injected into FieldTable
- // or added to a list, for extensibility
-
- #region Collection Convert/Format
-
- private bool IsCollectionType (Type dataType)
- {
- bool v = (typeof (ICollection)).IsAssignableFrom (dataType);
- return (v);
- }
-
- #region Notes
-
- /*
- /// <summary>
- /// Instantiate from an IDictionary,
- /// formatting each entry using the FieldTable from a INexusContext,
- /// and reporting any conversion or formatting errors in the INexusContext.
- /// </summary>
- /// <remarks><p>
- /// The result of a query will come back as a list of IDictionaries,
- /// using native, unformatted data types.
- /// This constructor can be used to loop through a list of IDictionaires,
- /// create a AppContext for each entry, and formatting any values
- /// along the way. (Dates being the best example.)
- /// The result is a AppContextList that can be used as a DataGrid
- /// DataSource (or whatever).
- /// </p></remarks>
- /// <param name="dictionary">Values for new object</param>
- /// <param name="context">Context with FieldTable and error handler</param>
- public AppContext (IDictionary dictionary, IRequestContext context)
- {
- #region Assert parameters
+ #region Text
- if (null == dictionary) throw new ArgumentNullException ("dictionary", "AppContext(IDictionary,INexusContext");
- if (null == context) throw new ArgumentNullException ("context", "AppContext(IDictionary,INexusContext");
- IFieldTable table = context.FieldTable;
- if (null == table) throw new ArgumentNullException ("FieldTable", "AppContext(IDictionary,INexusContext");
-
- #endregion
-
- IEnumerator keys = dictionary.Keys.GetEnumerator ();
- while (keys.MoveNext ())
- {
- string key = keys.Current as string;
- IValidatorContext input = new ValidatorContext (); // ISSUE: Spring? [WNE-63]
- input.FieldKey = key;
- input.Source = dictionary [key];
- bool okay = table.Format (input);
- if (!okay)
- // OR, do we just want to push convert/format(id) up?
- context.AddAlertForField (key);
- this.Add (key, input.Target);
- }
- }
- */
+ public virtual string Alert (string id)
+ {
+ return GetFieldContext (id).Alert;
+ }
#endregion
#endregion
- #region DateTime Convert/Format
-
- private DateTime DateTime_Empty = DateTime.MinValue;
-
- private bool IsDateEmpty (object source)
- {
- SByte dbNull = 0;
- return ((null == source) || (DBNull.Value.Equals (source)) || (dbNull.Equals (source) || String.Empty.Equals (source)));
- }
-
- private bool IsDateType (Type dataType)
- {
- bool v = (typeof (DateTime)).IsAssignableFrom (dataType);
- return (v);
- }
-
/// <summary>
- /// Substitute default value (MinValue) if conversion fails.
+ /// Create instance with zero paramters.
/// </summary>
- /// <param name="fieldContext">Our field definition.</param>
- /// <param name="input">The string to convert.</param>
- /// <returns>A DateTime value, using MinValue to represent failure.</returns>
- private DateTime DateTime_Convert (IFieldContext fieldContext, string input)
+ public FieldTable ()
{
- DateTime t = DateTime_Empty;
- try
- {
- t = Convert.ToDateTime (input);
- }
- catch (InvalidCastException e)
- {
- e = e; // silly assignment
- }
- catch (FormatException e)
- {
- e = e; // silly assignment
- }
- return t;
+ this [Tokens.Field] = new Hashtable ();
+ this [Tokens.Processor] = new Hashtable ();
}
/// <summary>
- /// Render DateTime value using the DataFormat string,
- /// or an empty string if value is MinValue or an invalid type.
+ /// Internal storage for the FieldContexts.
/// </summary>
- /// <param name="fieldContext">Our field definition.</param>
- /// <param name="value">The value to format.</param>
- /// <returns>Formatted representation or an empty string.</returns>
- private string DateTime_Format (IFieldContext fieldContext, object value)
+ private IDictionary Field
{
- DateTime t = DateTime_Empty;
- try
- {
- t = (DateTime) value;
- }
- catch (InvalidCastException e)
- {
- e = e;
- }
- if (DateTime_Empty.Equals (t)) return String.Empty;
- else return t.ToString (fieldContext.DataFormat);
+ get { return this [Tokens.Field] as IDictionary; }
}
- #endregion
-
- #region String Convert/Format
-
- private string String_Empty = String.Empty;
-
/// <summary>
- /// Determine whether string is null or empty.
+ /// Internal storage for the Processors.
/// </summary>
- /// <param name="v">String to test.</param>
- /// <returns>True if the string is valid input (not null and not empty).</returns>
- ///
- private bool IsStringEmpty (string v)
+ private IDictionary Processor
{
- return ((v != null) && (!String_Empty.Equals (v)));
+ get { return this [Tokens.Processor] as IDictionary; }
}
- private bool IsStringType (Type dataType)
- {
- bool v = (typeof (string).IsAssignableFrom (dataType));
- return v;
- }
-
- private string String_Convert (IFieldContext fieldContext, string input)
- {
- bool isNull = (input == null);
- return isNull ? String_Empty : input;
- // If null, return empty string rather than null
- }
-
- private string String_Format (IFieldContext fieldContext, object value)
- {
- string t = String_Empty;
- if (value == null) return t;
- string format = (fieldContext.DataFormat == null) ? t : fieldContext.DataFormat;
- if (format.Equals (t)) return value.ToString ();
- return String.Format (format, value);
- }
-
- #endregion
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs Wed Jun 22 13:20:53 2005
@@ -1,11 +1,10 @@
-using System;
using System.Runtime.Serialization;
namespace Nexus.Core.Tables
{
/// <summary>
/// Provide properties common to controls,
- /// including Alert, Constraints, ControlType, and DataType.
+ /// including Alert, Constraints, ControlType, and Processor.
/// </summary>
/// <remark><p>
/// Validation commands can use the FieldContext properties
@@ -23,7 +22,7 @@
public interface IFieldContext : ISerializable
{
/// <summary>
- /// Intitial error message to display when Constraints fail.
+ /// Custom error message to display when input validation fails.
/// </summary>
///
string Alert { get; set; }
@@ -41,48 +40,38 @@
string ControlTypeName { get; set; }
/// <summary>
- /// Formatting instructions for the value, according to DateType.
+ /// Provide custom formatting instructions for the value,
+ /// overriding any defaults for the Processor..
/// </summary>
///
string DataFormat { get; set; }
/// <summary>
- /// Type of native data.
+ /// Identify the processor for this field.
/// </summary>
- /// <remarks>
- /// Standard data types are: Boolean, Byte Char, DateTime, Decimal,
- /// Double, Int16, Int32, Int64, SByte, Single, String, TimeSpan,
- /// UInt16, UInt32, UInt64
- /// </remarks>
///
- Type DataType { get; set; }
+ string ProcessorID { get; set; }
/// <summary>
- /// Cannonical name of the DataType.
- /// </summary>
- ///
- string DataTypeName { get; set; }
-
- /// <summary>
- /// Help - Gets or sets text for a context-sensitive help screen.
+ /// Record the text for a context-sensitive help screen.
/// </summary>
///
string Help { get; set; }
/// <summary>
- /// Hint - Gets or sets an onscreen or hover hint.
+ /// Record an onscreen or hover hint.
/// </summary>
///
string Hint { get; set; }
/// <summary>
- /// Name of the control (also dictionary key).
+ /// Identify the unique name of this field.
/// </summary>
///
string ID { get; set; }
/// <summary>
- /// The label for the control.
+ /// Record a label for the control.
/// </summary>
///
string Label { get; set; }
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs Wed Jun 22 13:20:53 2005
@@ -6,29 +6,37 @@
namespace Nexus.Core.Tables
{
/// <summary>
- /// Inventory of fields used by the application.
+ /// Inventory of fields and processors used by the application.
/// </summary>
///
public interface IFieldTable : IContext, ISerializable
{
/// <summary>
+ /// Indicate whether this FieldTable must include all fields,
+ /// including strings fields [FALSE].
+ /// </summary>
+ ///
+ bool Strict { set; get; }
+
+ /// <summary>
/// Add a field to the set.
/// </summary>
///
- IFieldContext AddField { set; }
+ IFieldContext AddFieldContext { set; }
/// <summary>
/// Add a list of fields to the set.
/// </summary>
///
- IList AddFields { set; }
+ IList AddFieldContexts { set; }
/// <summary>
- /// Indicate whether this FieldTable must include all fields,
- /// including strings fields [FALSE].
+ /// Obtain the FieldContext for the given ID, observing Strict setting.
/// </summary>
+ /// <param name="id">FieldContext ID</param>
+ /// <returns>FieldContext for ID</returns>
///
- bool Strict { set; get; }
+ IFieldContext GetFieldContext (string id);
/// <summary>
/// Provide the Alert message for a given field id.
@@ -39,29 +47,23 @@
string Alert (string id);
/// <summary>
- /// Convert and copy values from the Criteria into the main Context,
- /// utilitizing the FieldContext settings.
+ /// Add a Processor to the set.
/// </summary>
- /// <param name="context">Context to process (including Criteria)</param>
- /// <returns>True if nominal</returns>
- ///
- bool Convert_Execute (IValidatorContext context);
+ IProcessor AddProcessor { set; }
/// <summary>
- /// Format and copy values from the main Context into the Criteria,
- /// utilizing the FieldContext settings.
+ /// Add a list of Processors to the set.
/// </summary>
- /// <param name="context">Context to process (including Criteria)</param>
- /// <returns>True if nominal</returns>
- ///
- bool Format_Execute (IValidatorContext context);
+ IList AddProcessors { set; }
/// <summary>
- /// Obtain the FieldContext for the given ID, observering Strict setting.
+ /// Obtain the Processor for the given ID;
+ /// there must be a matching Processor for each
+ /// ProcessorID specified by a FieldContext.
/// </summary>
- /// <param name="id">FieldContext ID</param>
- /// <returns>FieldContext for ID</returns>
- ///
- IFieldContext GetField (string id);
+ /// <param name="id"></param>
+ /// <returns></returns>
+ IProcessor GetProcessor (string id);
+
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs Wed Jun 22 13:20:53 2005
@@ -89,6 +89,11 @@
public const string Criteria = "_Criteria";
/// <summary>
+ /// Token for Processor property.
+ /// </summary>
+ public const string Processor = "_Processor";
+
+ /// <summary>
/// Token for DataFormat DataFormat.
/// </summary>
///
@@ -104,7 +109,7 @@
/// Token for DataTypeName DataTypeName.
/// </summary>
///
- public const string DataTypeName = "_DataTypeName";
+ public const string DataTypeID = "_DataTypeID";
/// <summary>
/// Token for Fault property.
@@ -123,6 +128,11 @@
/// </summary>
///
public const string FieldTable = "_FieldTable";
+
+ /// <summary>
+ /// Token for Field property.
+ /// </summary>
+ public const string Field = "_Field";
/// <summary>
/// Token for a generic message property.
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ConvertInput.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ConvertInput.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ConvertInput.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ConvertInput.cs Wed Jun 22 13:20:53 2005
@@ -1,26 +1,24 @@
using System.Collections;
-using Nexus.Core.Tables;
namespace Nexus.Core.Validators
{
/// <summary>
- /// Convert all related fields from Criteria to the main context,
+ /// Convert related fields from Criteria to the main context,
/// adding an Alert message to Errors if a conversion fails.
/// </summary>
- public class ConvertInput : Validator
+ public class ConvertInput : ProcessorCommand
{
- public override bool ProcessExecute (IValidatorContext incoming)
+ public override bool ExecuteProcess (IProcessorContext incoming)
{
string key = incoming.FieldKey;
IRequestContext context = incoming.Context;
IDictionary criteria = incoming.Criteria;
- IFieldTable table = incoming.FieldTable;
bool have = (criteria.Contains (key));
if (have)
{
incoming.Source = criteria [key];
- bool okay = table.Convert_Execute (incoming);
+ bool okay = ExecuteConvert (incoming);
if (okay)
// set to main context
context [key] = incoming.Target;
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/FormatOutput.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/FormatOutput.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/FormatOutput.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/FormatOutput.cs Wed Jun 22 13:20:53 2005
@@ -1,26 +1,24 @@
using System.Collections;
-using Nexus.Core.Tables;
namespace Nexus.Core.Validators
{
/// <summary>
- /// Format all related fields from the main context to Criteria,
+ /// Format related fields from the main context to Criteria,
/// adding an error message to Alerts if formatting fails.
/// </summary>
- public class FormatOutput : Validator
+ public class FormatOutput : ProcessorCommand
{
- public override bool ProcessExecute (IValidatorContext outgoing)
+ public override bool ExecuteProcess (IProcessorContext outgoing)
{
string key = outgoing.FieldKey;
IRequestContext context = outgoing.Context;
IDictionary criteria = outgoing.Criteria;
- IFieldTable table = outgoing.FieldTable;
bool have = (context.Contains (key));
if (have)
{
outgoing.Source = context [key];
- bool okay = table.Format_Execute (outgoing);
+ bool okay = ExecuteFormat (outgoing);
if (okay)
// set to field buffer
criteria [key] = outgoing.Target;
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidator.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidator.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidator.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidator.cs Wed Jun 22 13:20:53 2005
@@ -1,13 +1,35 @@
namespace Nexus.Core.Validators
{
/// <summary>
- /// Provide a message Template to use when validation fails [OVR-13].
+ /// Transform values from one data type or format to another. [OVR-13].
/// </summary>
- public interface IValidatorCommand : IRequestCommand
+ public interface IProcessorCommand : IRequestCommand
{
- string Template { get; set; }
- bool Continue { get; set; }
- bool ProcessExecute (IValidatorContext context);
+ /// <summary>
+ /// Provide a message template to use when a required field is missing.
+ /// </summary>
+ string Required { get; set; }
+
+ /// <summary>
+ /// Transform the value indicated by the context FieldKey, if present.
+ /// </summary>
+ /// <param name="context">The context we are processing</param>
+ /// <returns>True if nominal</returns>
+ bool ExecuteProcess (IProcessorContext context);
+
+ /// <summary>
+ /// Convert a field value, utlitizing the field table and processor.
+ /// </summary>
+ /// <param name="context">The context we are processing</param>
+ /// <returns>True if nominal</returns>
+ bool ExecuteConvert (IProcessorContext context);
+
+ /// <summary>
+ /// Format a field value, utlitizing the field table and processor.
+ /// </summary>
+ /// <param name="context">The context we are processing</param>
+ /// <returns>True if nominal</returns>
+ bool ExecuteFormat (IProcessorContext context);
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidatorContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidatorContext.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidatorContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IValidatorContext.cs Wed Jun 22 13:20:53 2005
@@ -5,10 +5,10 @@
namespace Nexus.Core.Validators
{
/// <summary>
- /// Encapsulate values needed by standard IValidatorCommands [OVR-13].
+ /// Encapsulate values needed by standard IProcessorCommands [OVR-13].
/// </summary>
///
- public interface IValidatorContext : IContext
+ public interface IProcessorContext : IContext
{
/// <summary>
/// Identify the field under validation.
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs Wed Jun 22 13:20:53 2005
@@ -11,56 +11,42 @@
/// <remarks>
/// Subclasses must provide a NexusExecute method.
/// </remarks>
- public abstract class Validator : RequestCommand, IValidatorCommand
+ public abstract class ProcessorCommand : RequestCommand, IProcessorCommand
{
- #region Properties
+ #region IRequestCommand
- private string _Template = null;
- public virtual string Template
+ public override bool RequestExecute (IRequestContext context)
{
- get { return _Template; }
- set { _Template = value; }
+ ProcessRelated (context);
+ ProcessRequired (context);
+ return context.HasAlerts;
}
- private bool _Continue = false;
- public virtual bool Continue
- {
- get { return _Continue; }
- set { _Continue = value; }
- }
+ #endregion
- public const bool MODE_INPUT = false;
- public const bool MODE_OUTPUT = true;
+ #region IProcessorCommand
- private bool _Mode = MODE_INPUT;
- public virtual bool Mode
+ private string _Template = null;
+ public virtual string Required
{
- get { return _Mode; }
- set { _Mode = value; }
+ get { return _Template; }
+ set { _Template = value; }
}
- #endregion
+ public abstract bool ExecuteProcess (IProcessorContext context);
- public ICollection CombinedIDs (IRequestContext context)
- {
- IDictionary combined = new Hashtable ();
- IList relatedIDs = context.CommandBin.RelatedIDs; // outer list
- if (relatedIDs != null) foreach (string i in relatedIDs) combined [i] = i;
- IList requiredIDs = context.CommandBin.RequiredIDs; // inner list
- if (requiredIDs != null) foreach (string i in requiredIDs) combined [i] = i;
- return combined.Keys;
- }
+ #endregion
#region ProcessRequired
- public void AssertProcessRequired (IRequestContext context)
+ private void AssertProcessRequired (IRequestContext context)
{
IDictionary criteria = context.Criteria;
if (null == criteria)
throw new ArgumentNullException ("Criteria", "BaseValidator.NexusExecute.AssertProcessRequired");
}
- public virtual void ProcessRequired (IRequestContext context, bool mode)
+ private void ProcessRequired (IRequestContext context)
{
IList requiredIDs = context.CommandBin.RequiredIDs; // inner list
if (requiredIDs == null) return;
@@ -83,7 +69,7 @@
bool okay = (context.Contains (id) && (null != context [id]) && (!String.Empty.Equals (context [id].ToString ())));
if (!okay)
{
- string message = context.FormatTemplate (Template, id);
+ string message = context.FormatTemplate (Required, id);
context.AddAlert (message, id);
}
}
@@ -93,7 +79,7 @@
#region ProcessRelated
- public void AssertProcessRelated (IRequestContext context)
+ private void AssertProcessRelated (IRequestContext context)
{
AssertProcessRequired (context);
@@ -102,31 +88,79 @@
throw new ArgumentNullException ("FieldTable", "BaseValidator.NexusExecute.AssertProcessRelated");
}
- public abstract bool ProcessExecute (IValidatorContext context);
-
- public virtual void ProcessRelated (IRequestContext context, bool mode)
+ private void ProcessRelated (IRequestContext context)
{
AssertProcessRelated (context);
ICollection related = CombinedIDs (context);
foreach (string key in related)
{
- IValidatorContext _context = new ValidatorContext (key, context);
- ProcessExecute (_context);
+ IProcessorContext _context = new ProcessorContext (key, context);
+ ExecuteProcess (_context);
}
}
+ private ICollection CombinedIDs (IRequestContext context)
+ {
+ IDictionary combined = new Hashtable ();
+ IList relatedIDs = context.CommandBin.RelatedIDs; // outer list
+ if (relatedIDs != null) foreach (string i in relatedIDs) combined [i] = i;
+ IList requiredIDs = context.CommandBin.RequiredIDs; // inner list
+ if (requiredIDs != null) foreach (string i in requiredIDs) combined [i] = i;
+ return combined.Keys;
+ }
+
#endregion
- // public abstract bool ProcessExecute(ValidatorContext context);
+ public virtual bool ExecuteConvert (IProcessorContext context)
+ {
+ bool okay = false;
+ string id = context.FieldKey;
+ IFieldTable table = context.FieldTable;
+ IFieldContext fieldContext = table.GetFieldContext (id); // enforces Strict
- public override bool RequestExecute (IRequestContext context)
+ if ((fieldContext == null))
+ {
+ context.Target = context.Source;
+ return true;
+ }
+
+ IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
+ okay = processor.ConvertInput (context);
+ return okay;
+ }
+
+ public virtual bool ExecuteFormat (IProcessorContext context)
{
- ProcessRelated (context, Mode);
- ProcessRequired (context, Mode);
- if (Continue) return CONTINUE;
- return context.HasAlerts;
+ bool okay = false;
+ string id = context.FieldKey;
+ object source = context.Source;
+ IFieldTable table = context.FieldTable;
+ IFieldContext fieldContext = table.GetFieldContext (id); // Enforces Strict
+
+ if ((fieldContext == null))
+ {
+ if (source == null)
+ context.Target = null;
+ else
+ {
+ // TODO: Remove exception code and replace with Collection processors
+ Type sourceType = source.GetType ();
+ if (IsCollectionType (sourceType)) context.Target = source;
+ else context.Target = source.ToString ();
+ }
+ return true;
+ }
+
+ IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
+ okay = processor.FormatOutput (context);
+ return okay;
}
+ private bool IsCollectionType (Type dataType)
+ {
+ bool v = (typeof (ICollection)).IsAssignableFrom (dataType);
+ return (v);
+ }
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ValidatorContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ValidatorContext.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ValidatorContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ValidatorContext.cs Wed Jun 22 13:20:53 2005
@@ -7,21 +7,21 @@
namespace Agility.Nexus.Validators
{
/// <summary>
- /// Implement IValidatorContext.
+ /// Implement IProcessorContext.
/// </summary>
- public class ValidatorContext : Context, IValidatorContext
+ public class ProcessorContext : Context, IProcessorContext
{
- public ValidatorContext ()
+ public ProcessorContext ()
{
}
- public ValidatorContext (string key, object source)
+ public ProcessorContext (string key, object source)
{
FieldKey = key;
Source = source;
}
- public ValidatorContext (string key, IRequestContext context)
+ public ProcessorContext (string key, IRequestContext context)
{
FieldKey = key;
this [Tokens.Context] = context;
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs Wed Jun 22 13:20:53 2005
@@ -71,7 +71,7 @@
[Test]
- public void ObjectByKey_Validate ()
+ public void ObjectByKey_Process ()
{
IDictionary fields = new Hashtable ();
fields [PK_SOMETHING] = PK_SOMETHING_VALUE;
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml?rev=192994&r1=192993&r2=192994&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml Wed Jun 22 13:20:53 2005
@@ -3,16 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
-<!-- catalog commands -->
+<!-- Request Processors -->
<object id="ConvertInput" type="Nexus.Core.Validators.ConvertInput">
<property name="ID"><value>ConvertInput</value></property>
- <property name="Template"><value>{0} is required.</value></property>
+ <property name="Required"><value>{0} is required.</value></property>
</object>
<object id="FormatOutput" type="Nexus.Core.Validators.FormatOutput">
<property name="ID"><value>FormatOutput</value></property>
- <property name="Template"><value>{0} is required.</value></property>
+ <property name="Required"><value>{0} is required.</value></property>
</object>
<!-- pre-op -->
@@ -43,30 +43,53 @@
<object id="FieldTable" type="Nexus.Core.Tables.FieldTable">
<property name="Strict"><value>true</value></property>
- <property name="AddFields">
+ <property name="AddFieldContexts">
<list>
<ref object="pk_something"/>
<ref object="SomeDate"/>
<ref object="SomethingResult"/>
</list>
</property>
+ <property name="AddProcessors">
+ <list>
+ <ref object="CollectionProcessor"/>
+ <ref object="DateTimeProcessor"/>
+ <ref object="StringProcessor"/>
+ </list>
+ </property>
</object>
<!-- Fields -->
<object id="pk_something" type="Nexus.Core.Tables.FieldContext">
<property name="ID"><value>pk_something</value></property>
+ <property name="ProcessorID"><value>StringProcessor</value></property>
</object>
<object id="SomethingResult" type="Nexus.Core.Tables.FieldContext">
<property name="ID"><value>SomethingResult</value></property>
+ <property name="ProcessorID"><value>StringProcessor</value></property>
</object>
<object id="SomeDate" type="Nexus.Core.Tables.FieldContext">
<property name="ID"><value>SomeDate</value></property>
+ <property name="ProcessorID"><value>DateTimeProcessor</value></property>
<property name="Alert"><value>{0} must be a valid date</value></property>
+ </object>
+
+<!-- Field Processors -->
+
+ <object id="CollectionProcessor" type="Nexus.Core.Validators.CollectionProcessor">
+ <property name="ID"><value>CollectionProcessor</value></property>
+ </object>
+
+ <object id="DateTimeProcessor" type="Nexus.Core.Validators.DateTimeProcessor">
+ <property name="ID"><value>DateTimeProcessor</value></property>
<property name="DataFormat"><value>d</value></property>
- <property name="DataTypeName"><value>System.DateTime</value></property>
+ </object>
+
+ <object id="StringProcessor" type="Nexus.Core.Validators.StringProcessor">
+ <property name="ID"><value>StringProcessor</value></property>
</object>
</objects>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org