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/24 13:59:33 UTC

svn commit: r201598 - /struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs

Author: husted
Date: Fri Jun 24 04:59:33 2005
New Revision: 201598

URL: http://svn.apache.org/viewcvs?rev=201598&view=rev
Log:
OVR-13
* Extend ValidatorCommand to provide default behavior for registered fields that do not supply a Processor.

Modified:
    struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs

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=201598&r1=201597&r2=201598&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Validator.cs Fri Jun 24 04:59:33 2005
@@ -33,6 +33,19 @@
 			set { _Template = value; }
 		}
 
+		/// <summary>
+		/// Convert input for fields that do not have a Processor.
+		/// </summary>
+		/// <remarks>
+		/// The default behavior is to pass through the objects, verbatim.
+		/// </remarks>
+		/// <param name="context">The IProcessorContext</param>
+		public virtual bool ConvertInput (IProcessorContext context)
+		{
+			context.Target = context.Source;
+			return true;
+		}
+
 		public virtual bool ExecuteConvert (IProcessorContext context)
 		{
 			bool okay = false;
@@ -42,15 +55,37 @@
 
 			if ((fieldContext == null))
 			{
-				context.Target = context.Source;
+				ConvertInput (context);
 				return true;
 			}
 
-			IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
-			okay = processor.ConvertInput (context);
+			string processorID = fieldContext.ProcessorID;
+			if (processorID == null)
+				okay = ConvertInput (context);
+			else
+			{
+				IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
+				okay = processor.ConvertInput (context);
+			}
 			return okay;
 		}
 
+		/// <summary>
+		/// Format output for fields that do not have a Processor.
+		/// </summary>
+		/// <remarks>
+		/// The default behavior is to pass through ICollection types 
+		/// and call ToString on everything else.
+		/// </remarks>
+		/// <param name="context">The IProcessorContext</param>
+		public virtual bool FormatOutput (IProcessorContext context)
+		{
+			Type sourceType = context.Source.GetType ();
+			if (IsCollectionType (sourceType)) context.Target = context.Source;
+			else context.Target = context.Source.ToString ();
+			return true;
+		}
+
 		public virtual bool ExecuteFormat (IProcessorContext context)
 		{
 			bool okay = false;
@@ -63,18 +98,18 @@
 			{
 				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 ();
-				}
+				else okay = FormatOutput (context);
 				return true;
 			}
 
-			IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
-			okay = processor.FormatOutput (context);
+			string processorID = fieldContext.ProcessorID;
+			if (processorID == null)
+				okay = FormatOutput (context);
+			else
+			{
+				IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
+				okay = processor.FormatOutput (context);
+			}
 			return okay;
 		}
 
@@ -94,7 +129,7 @@
 		{
 			IDictionary criteria = context.Criteria;
 			if (null == criteria)
-				throw new ArgumentNullException ("Criteria", "BaseValidator.NexusExecute.AssertProcessRequired");
+				throw new ArgumentNullException ("Criteria==null", "BaseValidator.NexusExecute.AssertProcessRequired");
 		}
 
 		private void ProcessRequired (IRequestContext context)
@@ -136,7 +171,7 @@
 
 			IFieldTable table = context.FieldTable;
 			if (null == table)
-				throw new ArgumentNullException ("FieldTable", "BaseValidator.NexusExecute.AssertProcessRelated");
+				throw new ArgumentNullException ("FieldTable==null", "BaseValidator.NexusExecute.AssertProcessRelated");
 		}
 
 		private void ProcessRelated (IRequestContext context)
@@ -162,6 +197,5 @@
 		}
 
 		#endregion
-
 	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org