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 23:43:41 UTC
svn commit: r192999 - in
/struts/sandbox/trunk/overdrive/Nexus/Core/Validators:
CollectionProcessor.cs DateTimeProcessor.cs IProcessor.cs Processor.cs
StringProcessor.cs
Author: husted
Date: Wed Jun 22 14:43:40 2005
New Revision: 192999
URL: http://svn.apache.org/viewcvs?rev=192999&view=rev
Log:
OVR-13
OVR-12
* Add new files to go with r192994.
Added:
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/CollectionProcessor.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/DateTimeProcessor.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IProcessor.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Processor.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/StringProcessor.cs
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/CollectionProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/CollectionProcessor.cs?rev=192999&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/CollectionProcessor.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/CollectionProcessor.cs Wed Jun 22 14:43:40 2005
@@ -0,0 +1,74 @@
+using System.Collections;
+
+namespace Nexus.Core.Validators
+{
+ public class CollectionProcessor : Processor
+ {
+ public override bool IsEmpty (object v)
+ {
+ ICollection c = v as ICollection;
+ return ((c != null) && (c.Count > 0));
+ }
+
+ public override bool ConvertInput (IProcessorContext incoming)
+ {
+ incoming.Target = incoming.Source;
+ return true;
+ }
+
+ public override bool FormatOutput (IProcessorContext outgoing)
+ {
+ outgoing.Target = outgoing.Source;
+ return true;
+ }
+
+ }
+
+ #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
+
+ 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);
+ }
+ }
+ */
+
+ #endregion
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/DateTimeProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/DateTimeProcessor.cs?rev=192999&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/DateTimeProcessor.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/DateTimeProcessor.cs Wed Jun 22 14:43:40 2005
@@ -0,0 +1,117 @@
+using System;
+
+namespace Nexus.Core.Validators
+{
+ /// <summary>
+ /// Convert and format DateTime fields.
+ /// </summary>
+ public class DateTimeProcessor : Processor
+ {
+ #region IProcessor
+
+ public override bool IsEmpty (object source)
+ {
+ SByte dbNull = 0;
+ return ((null == source) || (DBNull.Value.Equals (source)) || (dbNull.Equals (source) || String.Empty.Equals (source)));
+ }
+
+ public override bool ConvertInput (IProcessorContext incoming)
+ {
+ bool okay = false;
+ string source = incoming.Source as string;
+
+ if (IsStringEmpty (source))
+ {
+ DateTime t = DateTime_Convert (source);
+ bool isDateTimeEmpty = DateTime_Empty.Equals (t);
+ okay = !isDateTimeEmpty;
+ incoming.Target = t;
+ }
+ else
+ {
+ incoming.Target = null; // FIXME: We could use DateTime_Empty here,
+ okay = true; // but there was an issue with iBATIS (is there still?)
+ }
+
+ return okay;
+ }
+
+ public override bool FormatOutput (IProcessorContext outgoing)
+ {
+ bool okay = false;
+ object source = outgoing.Source;
+
+ if (IsEmpty (source))
+ {
+ outgoing.Target = String.Empty;
+ okay = true;
+ }
+ else
+ {
+ string target = DateTime_Format (source);
+ outgoing.Target = target;
+ okay = IsStringEmpty (target);
+ }
+ return okay;
+ }
+
+ #endregion
+
+ private bool IsStringEmpty (string v)
+ {
+ return ((v != null) && (!String.Empty.Equals (v)));
+ }
+
+ private DateTime DateTime_Empty = DateTime.MinValue;
+
+ private DateTime DateTime_Convert (string source)
+ {
+ DateTime t = DateTime_Empty;
+ try
+ {
+ t = Convert.ToDateTime (source);
+ }
+ catch (InvalidCastException e)
+ {
+ e = e; // silly assignment
+ }
+ catch (FormatException e)
+ {
+ e = e; // silly assignment
+ }
+ return t;
+
+ }
+
+ private string DateTime_Format (object source)
+ {
+ DateTime t = DateTime_Empty;
+ try
+ {
+ t = (DateTime) source;
+ }
+ catch (InvalidCastException e)
+ {
+ e = e;
+ }
+ if (DateTime_Empty.Equals (t)) return String.Empty;
+ else return t.ToString (DataFormat);
+ }
+
+
+ /*
+ public bool IsMyType (Type dataType)
+ {
+ bool v = (typeof (DateTime)).IsAssignableFrom (dataType);
+ return v;
+ }
+
+ public bool IsMyField(IFieldContext field)
+ {
+ bool v = (field.ProcessorID.Equals(ID));
+ return v;
+ }
+ */
+
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IProcessor.cs?rev=192999&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IProcessor.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/IProcessor.cs Wed Jun 22 14:43:40 2005
@@ -0,0 +1,16 @@
+namespace Nexus.Core.Validators
+{
+ /// <summary>
+ /// Convert or Format a standard or custom DataType.
+ /// </summary>
+ public interface IProcessor
+ {
+ string Alert { get; set; }
+ string DataFormat { get; set; }
+ string ID { get; set; }
+
+ bool IsEmpty (object source);
+ bool ConvertInput (IProcessorContext incoming);
+ bool FormatOutput (IProcessorContext outgoing);
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Processor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Processor.cs?rev=192999&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Processor.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/Processor.cs Wed Jun 22 14:43:40 2005
@@ -0,0 +1,35 @@
+namespace Nexus.Core.Validators
+{
+ /// <summary>
+ /// Implement common properties.
+ /// </summary>
+ public abstract class Processor : IProcessor
+ {
+ private string _Alert;
+ public string Alert
+ {
+ get { return _Alert; }
+ set { _Alert = value; }
+ }
+
+ private string _DataFormat;
+ public string DataFormat
+ {
+ get { return _DataFormat; }
+ set { _DataFormat = value; }
+ }
+
+ private string _ID;
+ public string ID
+ {
+ get { return _ID; }
+ set { _ID = value; }
+ }
+
+ public abstract bool IsEmpty (object source);
+
+ public abstract bool ConvertInput (IProcessorContext incoming);
+
+ public abstract bool FormatOutput (IProcessorContext outgoing);
+ }
+}
\ No newline at end of file
Added: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/StringProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/StringProcessor.cs?rev=192999&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/StringProcessor.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/StringProcessor.cs Wed Jun 22 14:43:40 2005
@@ -0,0 +1,58 @@
+using System;
+
+namespace Nexus.Core.Validators
+{
+ public class StringProcessor : Processor
+ {
+ #region IProcessor
+
+ public override bool IsEmpty (object v)
+ {
+ return ((v != null) && (!String_Empty.Equals (v)));
+ }
+
+ public override bool ConvertInput (IProcessorContext incoming)
+ {
+ string source = incoming.Source as string;
+ incoming.Target = String_Convert (source);
+ return true;
+ }
+
+ public override bool FormatOutput (IProcessorContext outgoing)
+ {
+ object source = outgoing.Source;
+ outgoing.Target = String_Format (source);
+ return true;
+ }
+
+ #endregion
+
+ private string String_Empty = String.Empty;
+
+ private string String_Convert (string source)
+ {
+ bool isNull = (source == null);
+ return isNull ? String_Empty : source;
+ // If null, return empty string rather than null
+ }
+
+ private string String_Format (object source)
+ {
+ string t = String_Empty;
+ if (source == null) return t;
+ string format = (DataFormat == null) ? t : DataFormat;
+ if (format.Equals (t)) return source.ToString ();
+ return String.Format (format, source);
+ }
+
+ /*
+ private bool IsMyType (Type dataType)
+ {
+ bool v = (typeof (string).IsAssignableFrom (dataType));
+ return v;
+ }
+ */
+
+
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org