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/29 23:13:26 UTC
svn commit: r202429 - in /struts/sandbox/trunk/overdrive/Nexus: Core/
Core/Helpers/ Core/Tables/ Core/Validators/ Extras/Spring/ Test/
Test/Resources/Command/ Web/
Author: husted
Date: Wed Jun 29 14:13:24 2005
New Revision: 202429
URL: http://svn.apache.org/viewcvs?rev=202429&view=rev
Log:
OVR-8
OVR-11
OVR-12
OVR-13
* ICatalog: Add PreOp and PostOp as properties, so that we don't have to use a magic identifier.
* IViewHelper: Add Profile property, so that it can be passed to internal Context.
* FieldTable, FieldContext: Extend contracts for Alerts and Labels, to utlize more useful defaults.
* FieldContext: Change ProcessorID to Processor instance, to avoid looking it up later.
* FieldContext: Remove DataFormat property. (To use another format, use another Processor.)
* FieldContext: Add Required, so that all messages can be obtained uniformally.
* ProcessorCommand: Remove Required property (now handled by IFieldContext).
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
struts/sandbox/trunk/overdrive/Nexus/Core/IRequestContext.cs
struts/sandbox/trunk/overdrive/Nexus/Core/RequestContext.cs
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/EntryListProcessor.cs
struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ProcessorCommand.cs
struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/FieldContext.cs
struts/sandbox/trunk/overdrive/Nexus/Test/BaseNexusTest.cs
struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs
struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs
struts/sandbox/trunk/overdrive/Nexus/Test/Resources/Command/AppConfig.xml
struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs Wed Jun 29 14:13:24 2005
@@ -15,6 +15,7 @@
*/
using System;
using System.Collections;
+using Nexus.Core.Profile;
using Nexus.Core.Tables;
namespace Nexus.Core.Helpers
@@ -91,6 +92,12 @@
/// </summary>
///
IDictionary Criteria { get; }
+
+
+ /// <summary>
+ /// User profile, which includes user ID and Locale.
+ /// </summary>
+ IProfile Profile { get; set; }
/// <summary>
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Wed Jun 29 14:13:24 2005
@@ -15,6 +15,7 @@
*/
using System;
using System.Collections;
+using Nexus.Core.Profile;
using Nexus.Core.Tables;
namespace Nexus.Core.Helpers
@@ -248,6 +249,16 @@
}
return _Context;
}
+ }
+
+ /// <summary>
+ /// Provide the user Profile for this Helper, if any.
+ /// </summary>
+ ///
+ public IProfile Profile
+ {
+ get { return Context.Profile; }
+ set { Context.Profile = value; }
}
#endregion
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs Wed Jun 29 14:13:24 2005
@@ -27,10 +27,17 @@
public interface IRequestCatalog : ICatalog
{
/// <summary>
+ /// Obtains an object for ID.
+ /// </summary>
+ /// <param name="name">Our object ID</param>
+ /// <returns>object for name</returns>
+ object GetObject (string name);
+
+ /// <summary>
/// Obtains a IViewHelper for helper ID.
/// </summary>
/// <param name="name">Our helper ID</param>
- /// <returns>IViewHelper or null</returns>
+ /// <returns>IViewHelper for name</returns>
IViewHelper GetHelper (string name);
/// <summary>
@@ -78,16 +85,41 @@
void ExecuteRequest (IRequestContext context);
/// <summary>
- /// Execute a IRequestContext as part of a View layer chain.
+ /// Execute a IRequestContext as part of a chain
+ /// created with the PreOp and PostOp commands (if any).
/// </summary>
/// <remarks><p>
- /// Among other things, the View layer chain may transfer
- /// data between the FieldState and the root Context.
- /// The View layer chain acts as a Front Controller.
+ /// Among other things, the PreOp/PostOp chain may transfer
+ /// data between the Criteria and the root Context.
+ /// </p><p>
+ /// The PreOp/PostOp chain acts as a Front Controller
+ /// in that it ensures certain tasks are perform
+ /// upon every request.
+ /// </p><p>
+ /// IViewHelper implementations are expected to
+ /// call ExecuteView to "invoke the Helper's command".
/// </p></remarks>
/// <param name="context">Context to execute</param>
///
void ExecuteView (IRequestContext context);
+
+ /// <summary>
+ /// Execute before a Command called via ExecuteView.
+ /// </summary>
+ /// <remarks><p>
+ /// Of course, a IRequestChain may be used here too.
+ /// </p></remarks>
+ ///
+ IRequestCommand PreOp {get;set;}
+
+ /// <summary>
+ /// Execute after a Command called via ExecuteView.
+ /// </summary>
+ /// <remarks><p>
+ /// Of course, a IRequestChain may be used here too.
+ /// </p></remarks>
+ ///
+ IRequestCommand PostOp {get;set;}
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/IRequestContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/IRequestContext.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/IRequestContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/IRequestContext.cs Wed Jun 29 14:13:24 2005
@@ -204,11 +204,18 @@
void AddAlert (string template, string message);
/// <summary>
- /// Add a formatted Alert error message
+ /// Add a formatted "Alert" error message
/// for the given field key via the FieldTable.
/// </summary>
/// <param name="key">Key from the FieldTable</param>
void AddAlertForField (string key);
+
+ /// <summary>
+ /// Add a formatted "Required" error message
+ /// for the given field key via the FieldTable.
+ /// </summary>
+ /// <param name="key">Key from the FieldTable</param>
+ void AddAlertRequired (string key);
/// <summary>
/// Indicate whether alerts exist.
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/RequestContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/RequestContext.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/RequestContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/RequestContext.cs Wed Jun 29 14:13:24 2005
@@ -191,7 +191,13 @@
public void AddAlertForField (string key)
{
- string message = FormatTemplate (FieldTable.Alert (key), key);
+ string message = FormatTemplate (FieldTable.Alert (key), FieldTable.Label(key));
+ AddAlert (message, key);
+ }
+
+ public void AddAlertRequired (string key)
+ {
+ string message = FormatTemplate (FieldTable.Required (key), FieldTable.Label(key));
AddAlert (message, key);
}
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=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldContext.cs Wed Jun 29 14:13:24 2005
@@ -1,5 +1,6 @@
using System;
using Agility.Core;
+using Nexus.Core.Validators;
namespace Nexus.Core.Tables
{
@@ -16,7 +17,15 @@
public string Alert
{
- get { return this [Tokens.Alert] as string; }
+ get
+ {
+ string alert = null;
+ IProcessor processor = Processor;
+ if (processor!=null) alert = processor.Alert;
+ if (alert==null) alert = this[Tokens.Alert] as string;
+ if (alert==null) alert = this[Tokens.Alert] as string;
+ return alert;
+ }
set { this [Tokens.Alert] = value; }
}
@@ -26,18 +35,6 @@
set { this [Tokens.ControlTypeName] = value; }
}
- public string DataFormat
- {
- get { return this [Tokens.DataFormat] as string; }
- set { this [Tokens.DataFormat] = value; }
- }
-
- public string ProcessorID
- {
- get { return this [Tokens.DataTypeID] as string; }
- set { this [Tokens.DataTypeID] = value; }
- }
-
public string Hint
{
get { return this [Tokens.Hint] as string; }
@@ -56,11 +53,27 @@
set { this [Tokens.ID] = value; }
}
-
public string Label
{
- get { return this [Tokens.Label] as string; }
+ get
+ {
+ string label = this [Tokens.Label] as string;
+ if (label==null) label = ID;
+ return label;
+ }
set { this [Tokens.Label] = value; }
+ }
+
+ public IProcessor Processor
+ {
+ get { return this [Tokens.Processor] as IProcessor; }
+ set { this [Tokens.Processor] = value; }
+ }
+
+ public string Required
+ {
+ get { return this [Tokens.Required] as string; }
+ set { this [Tokens.Required] = value; }
}
}
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=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/FieldTable.cs Wed Jun 29 14:13:24 2005
@@ -88,16 +88,6 @@
}
}
- public virtual IProcessor GetProcessor (string id)
- {
- if (id == null)
- throw new ArgumentNullException ("id==null", "Nexus.Core.Tables.FieldTable.GetProcessor");
- IProcessor processor = Processor [id] as IProcessor;
- if (processor == null)
- throw new ArgumentNullException (id, "Nexus.Core.Tables.FieldTable.GetProcessor");
- return processor;
- }
-
#endregion
#region Text
@@ -105,6 +95,16 @@
public virtual string Alert (string id)
{
return GetFieldContext (id).Alert;
+ }
+
+ public virtual string Label (string id)
+ {
+ return GetFieldContext (id).Label;
+ }
+
+ public virtual string Required (string id)
+ {
+ return GetFieldContext (id).Required;
}
#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=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldContext.cs Wed Jun 29 14:13:24 2005
@@ -1,34 +1,44 @@
using System.Runtime.Serialization;
+using Nexus.Core.Validators;
namespace Nexus.Core.Tables
{
/// <summary>
/// Provide properties common to controls,
- /// including Alert, Constraints, ControlType, and Processor.
+ /// including Alert, ControlType, and Processor.
/// </summary>
/// <remark><p>
- /// Validation commands can use the FieldContext properties
- /// to verify input.
/// The FieldContext entries are made available through a FieldTable.
/// The FieldContext members follow XForms terminology.
- /// </p>
- /// <p>
+ /// </p><p>
/// XForms [http://www.w3.org/MarkUp/Forms/].
/// XForms Controls [http://www.orbeon.com/ops/doc/processors-xforms].
/// XPath 2.0 for .NET [http://sourceforge.net/projects/saxondotnet/].
- /// </p>
- /// </remark>
+ /// </p><p>
+ /// To globalize an application,
+ /// utilize a IFieldContext implementation that supports localization.
+ /// A localized implementation can access a message resource to obtain text and messages,
+ /// rather than a simple property.
+ /// Localized implementations should also dissallow setting the text properties,
+ /// since those values would be provided through a message resource.
+ /// </p><p>
+ /// For a localized implementation, see Nexus.Core.Extras.Spring.FieldContext.
+ /// </p></remark>
///
public interface IFieldContext : ISerializable
{
/// <summary>
- /// Custom error message to display when input validation fails.
+ /// Provide a message to display when input validation fails.
/// </summary>
+ /// <remarks>
+ /// If the Processor also provides an Alert,
+ /// the Processor's Alert should be returned instead.
+ /// </remarks>
///
string Alert { get; set; }
/// <summary>
- /// Name for the default Control Type.
+ /// Identify name of the default Control Type.
/// </summary>
/// <remarks><p>
/// Standard control types are: input, secret, textarea, select1, select, submit, upload.
@@ -40,41 +50,43 @@
string ControlTypeName { get; set; }
/// <summary>
- /// Provide custom formatting instructions for the value,
- /// overriding any defaults for the Processor..
+ /// Provide text to display for a context-sensitive help screen.
/// </summary>
///
- string DataFormat { get; set; }
+ string Help { get; set; }
/// <summary>
- /// Identify the processor for this field.
+ /// Record an onscreen or hover hint.
/// </summary>
///
- string ProcessorID { get; set; }
+ string Hint { get; set; }
/// <summary>
- /// Record the text for a context-sensitive help screen.
+ /// Identify this field with a unique name.
/// </summary>
///
- string Help { get; set; }
+ string ID { get; set; }
/// <summary>
- /// Record an onscreen or hover hint.
+ /// Provide a label for the control.
/// </summary>
+ /// <remarks><p>
+ /// If the Label is null, the ID should be returned instead.
+ /// </p></remarks>
///
- string Hint { get; set; }
+ string Label { get; set; }
/// <summary>
- /// Identify the unique name of this field.
+ /// Provide the processor for this field context.
/// </summary>
///
- string ID { get; set; }
+ IProcessor Processor { get; set; }
/// <summary>
- /// Record a label for the control.
+ /// Provide a message to display when required input is missing.
/// </summary>
///
- string Label { get; set; }
+ string Required { 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=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tables/IFieldTable.cs Wed Jun 29 14:13:24 2005
@@ -39,14 +39,6 @@
IFieldContext GetFieldContext (string id);
/// <summary>
- /// Provide the Alert message for a given field id.
- /// </summary>
- /// <param name="id">FieldContext ID</param>
- /// <returns>Alert mesasge for FieldContext ID</returns>
- ///
- string Alert (string id);
-
- /// <summary>
/// Add a Processor to the set.
/// </summary>
IProcessor AddProcessor { set; }
@@ -57,13 +49,28 @@
IList AddProcessors { set; }
/// <summary>
- /// Obtain the Processor for the given ID;
- /// there must be a matching Processor for each
- /// ProcessorID specified by a FieldContext.
+ /// Provide the Alert message for a given field id.
/// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- IProcessor GetProcessor (string id);
+ /// <param name="id">FieldContext ID</param>
+ /// <returns>Alert message for FieldContext ID</returns>
+ ///
+ string Alert (string id);
+
+ /// <summary>
+ /// Provide the Label message for a given field id.
+ /// </summary>
+ /// <param name="id">FieldContext ID</param>
+ /// <returns>Alert message for FieldContext ID</returns>
+ ///
+ string Label (string id);
+
+ /// <summary>
+ /// Provide the Required message for a given field id.
+ /// </summary>
+ /// <param name="id">FieldContext ID</param>
+ /// <returns>Required message for FieldContext ID</returns>
+ ///
+ string Required (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=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Tokens.cs Wed Jun 29 14:13:24 2005
@@ -168,12 +168,18 @@
public const string ID = "_ID";
/// <summary>
- /// Token for Label Label.
+ /// Token for Label property.
/// </summary>
///
public const string Label = "_Label";
/// <summary>
+ /// Token for Required property.
+ /// </summary>
+ ///
+ public const string Required = "_Required";
+
+ /// <summary>
/// Token for Source property.
/// </summary>
///
@@ -188,18 +194,6 @@
#endregion
#region Command elements
-
- /// <summary>
- /// Token for the pre-op command element.
- /// </summary>
- ///
- public const string ID_PRE_OP = "pre-op";
-
- /// <summary>
- /// Token for the post-op command element.
- /// </summary>
- ///
- public const string ID_POST_OP = "post-op";
/// <summary>
/// Token for FieldTable command element.
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/EntryListProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/EntryListProcessor.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/EntryListProcessor.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/EntryListProcessor.cs Wed Jun 29 14:13:24 2005
@@ -45,7 +45,11 @@
outgoing.Target = target;
return true;
}
-
+
+ /// <summary>
+ /// Override to return an instance of the desired IEntryList type.
+ /// </summary>
+ /// <returns>An IEntryList instance</returns>
public abstract IEntryList NewEntryList();
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ProcessorCommand.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ProcessorCommand.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ProcessorCommand.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Validators/ProcessorCommand.cs Wed Jun 29 14:13:24 2005
@@ -59,12 +59,11 @@
return true;
}
- string processorID = fieldContext.ProcessorID;
- if (processorID == null)
+ IProcessor processor = fieldContext.Processor;
+ if (processor == null)
okay = ConvertInput (context);
else
{
- IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
okay = processor.ConvertInput (context);
}
return okay;
@@ -102,12 +101,11 @@
return true;
}
- string processorID = fieldContext.ProcessorID;
- if (processorID == null)
+ IProcessor processor = fieldContext.Processor;
+ if (processor == null)
okay = FormatOutput (context);
else
{
- IProcessor processor = table.GetProcessor (fieldContext.ProcessorID);
okay = processor.FormatOutput (context);
}
return okay;
@@ -155,8 +153,7 @@
bool okay = (context.Contains (id) && (null != context [id]) && (!String.Empty.Equals (context [id].ToString ())));
if (!okay)
{
- string message = context.FormatTemplate (Required, id);
- context.AddAlert (message, id);
+ context.AddAlertRequired (id);
}
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs Wed Jun 29 14:13:24 2005
@@ -30,6 +30,7 @@
///
public class Catalog : IRequestCatalog, IApplicationContextAware
{
+
#region Messages
private const string msg_ADD_COMMAND = "This catalog instance is created through dependency injection.";
@@ -52,15 +53,11 @@
set { _Factory = value; }
}
- /// <summary>
- /// Allow safe access to Factory.GetObject.
- /// </summary>
- /// <param name="name">ID for object</param>
- /// <returns>Object instance</returns>
- /// <exception cref="Exception">
- /// Throws Exception if name is null or object is not in catalog.
- /// </exception>
- private object GetObject (string name)
+ #endregion
+
+ #region IRequestCatalog
+
+ public object GetObject (string name)
{
if (null == name)
{
@@ -76,10 +73,6 @@
return o;
}
- #endregion
-
- #region ICatalog
-
/// <summary>
/// Not implemented as Catalog is expected to be created by an IOC framework.
/// </summary>
@@ -149,12 +142,7 @@
}
- /// <summary>
- /// Field for GetFieldTable method.
- /// </summary>
- ///
private IFieldTable _FieldTable = null;
-
/// <summary>
/// Access method for the Catalog's FieldTable.
/// </summary>
@@ -267,9 +255,9 @@
if (context.IsNominal)
{
IChain chain = new Chain ();
- chain.AddCommand (GetCommand (Tokens.ID_PRE_OP));
+ if (_PreOp!=null) chain.AddCommand (_PreOp);
chain.AddCommand (command);
- chain.AddCommand (GetCommand (Tokens.ID_POST_OP));
+ if (_PostOp!=null) chain.AddCommand (_PostOp);
try
{
chain.Execute (context);
@@ -279,6 +267,20 @@
context.Fault = e;
}
}
+ }
+
+ private IRequestCommand _PreOp;
+ public IRequestCommand PreOp
+ {
+ get { return _PreOp; }
+ set { _PreOp = value; }
+ }
+
+ private IRequestCommand _PostOp;
+ public IRequestCommand PostOp
+ {
+ get { return _PostOp; }
+ set { _PostOp = value; }
}
#endregion
Modified: struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/FieldContext.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/FieldContext.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/FieldContext.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/FieldContext.cs Wed Jun 29 14:13:24 2005
@@ -2,6 +2,7 @@
using Agility.Core;
using Nexus.Core;
using Nexus.Core.Tables;
+using Nexus.Core.Validators;
using Spring.Context;
namespace Nexus.Extras.Spring
@@ -14,16 +15,29 @@
/// The simplest way to do that is by using a base FieldContext in the Spring configuration file.
/// The MessageSource property can be set once in the base and inherited by the others.
/// </p><p>
- /// In this implementation, the text properties -- Alert, Hint, Help, and Label -- are read-only
+ /// In this implementation,
+ /// the text properties -- Alert, Hint, Help, Label, and Required -- are read-only
/// and cannot be accessed with a MessageSource property.
/// When the property is read,
- /// the method loods for a message resource that shares the same ID as the FieldContext,
- /// but with a "_property" suffix (_alert, _hint, _help, _label).
+ /// the method looks for a message resource that shares the same ID as the FieldContext,
+ /// but with a "_property" suffix (_alert, _hint, _help, _label, _required).
/// So, if the FieldContext ID is LastName, then reading its Alert will look for a message
/// resource named "LastName_alert".
- /// If the resource is not found,
- /// then the FieldContext ID (e.g. "LastName") is quietly returned instead.
+ /// </p><p>
+ /// In the case of an Alert, a message may also be provided by the Processor.
+ /// If so, then the Processor message supercedes the default message.
+ /// In this way, you can set a default for all the controls,
+ /// and then override the default for specific processors.
+ /// </p><p>
+ /// To provide a default Alert or Required to use when no other is provided,
+ /// provide a Message Resource entry in the form: "_alert" or "_required".
+ /// </p><p>
+ /// If a Label mesasge is not found, the FieldContext ID is returned instead.
+ /// Otherwise, if no message is found,
+ /// then the FieldContext ID and property tag (e.g. "LastName_required")
+ /// is returned.
/// </p></remarks>
+ ///
[Serializable]
public class FieldContext : Context, IFieldContext
{
@@ -38,21 +52,16 @@
set { this [Tokens.ControlTypeName] = value; }
}
- public string DataFormat
- {
- get { return this [Tokens.DataFormat] as string; }
- set { this [Tokens.DataFormat] = value; }
- }
-
public string ID
{
get { return this [Tokens.ID] as string; }
set { this [Tokens.ID] = value; }
}
- public string ProcessorID
+
+ public IProcessor Processor
{
- get { return this [Tokens.DataTypeID] as string; }
- set { this [Tokens.DataTypeID] = value; }
+ get { return this [Tokens.Processor] as IProcessor; }
+ set { this [Tokens.Processor] = value; }
}
#region text properties
@@ -87,9 +96,8 @@
/// Resolve the message or return null.
/// </summary>
/// <param name="name">The name of the resource to get.</param>
- /// <param name="defaultValue">The value to return on error.</param>
- /// <returns>A resolved message or the defaultValue if the message could not be located for any reason.</returns>
- private string GetMessageOrDefault(string name, string defaultValue)
+ /// <returns>A resolved message or null if the message could not be located for any reason.</returns>
+ private string GetMessageOrNull(string name)
{
string _name = null;
try
@@ -99,14 +107,39 @@
catch (Exception e)
{
e = e; // silly assignment
- _name = defaultValue;
+ _name = null;
}
return _name;
}
+ /// <summary>
+ /// Return the message for the Processor,
+ /// or the message for the FieldContext,
+ /// or the message for the suffix,
+ /// or the FieldContext ID and suffix verbatim,
+ /// if all else fails.
+ /// </summary>
+ /// <param name="root">FieldContext ID</param>
+ /// <param name="suffix">Message type</param>
+ /// <returns>A message or the root+suffix</returns>
private string GetText(string root, string suffix)
{
- return GetMessageOrDefault(root + suffix, root);
+ string text = null;
+ IProcessor processor = Processor;
+ string id = null;
+ if (processor!=null) id = processor.ID;
+ if (id!=null) text = GetMessageOrNull(id + suffix);
+ if (text==null)
+ {
+ text = GetMessageOrNull(root + suffix);
+ }
+ if (text==null)
+ {
+ text = GetMessageOrNull(suffix);
+ }
+ if (text==null) text = root + suffix;
+
+ return text;
}
public string Alert
@@ -129,7 +162,18 @@
public string Label
{
- get { return GetText(this.ID,"_label"); }
+ get
+ {
+ string label = GetMessageOrNull(this.ID + "_label");
+ if (label==null) label = ID;
+ return label;
+ }
+ set { throw new NotSupportedException(); }
+ }
+
+ public string Required
+ {
+ get { return GetText(this.ID,"_required"); }
set { throw new NotSupportedException(); }
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/BaseNexusTest.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/BaseNexusTest.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/BaseNexusTest.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/BaseNexusTest.cs Wed Jun 29 14:13:24 2005
@@ -13,22 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+using System;
using System.Collections;
using System.Text;
+using Agility.Core;
using Agility.Extras.Spring;
-using Nexus.Extras.Spring;
+using Nexus.Core.Helpers;
using NUnit.Framework;
using Spring.Context;
namespace Nexus.Core
{
/// <summary>
- /// Provide base SetUp method and convenience methods.
+ /// Provide base SetUp method and convenience methods
+ /// for tests that use a IRequestCatalog.
/// </summary>
///
[TestFixture]
- public class BaseNexusTest
+ public class CatalogBaseTest
{
+ /// <summary>
+ /// Catalog instance that tests can use.
+ /// </summary>
protected IRequestCatalog catalog;
/// <summary>
@@ -38,9 +44,8 @@
[SetUp]
public virtual void SetUp ()
{
- // TODO: Implement Objects.Factory [OVR-8]
IApplicationContext factory = Objects.Factory ();
- catalog = new Catalog (factory); // sic
+ catalog = factory.GetObject ("Catalog") as IRequestCatalog;
}
/// <summary>
@@ -53,6 +58,44 @@
Assert.IsTrue (catalog != null, "Expected non-null catalog.");
}
+ #region IRequestContext tests
+
+ /// <summary>
+ /// Determine if the context contains each key in keys.
+ /// </summary>
+ /// <param name="context">Context to process</param>
+ /// <param name="keys">Keys to verify</param>
+ /// <returns>True if contact contains each key in keys</returns>
+ protected bool ContainsKeys (IContext context, string[] keys)
+ {
+ bool found = true;
+ foreach (string key in keys)
+ {
+ found = found && context.Contains (key);
+ }
+ return found;
+ }
+
+ /// <summary>
+ /// Determine if the Criteria for context contains each key in keys.
+ /// </summary>
+ /// <param name="context">Context to process</param>
+ /// <param name="keys">Keys to verify</param>
+ /// <returns>True if Criteria for contact contains each key in keys</returns>
+ public bool ContainsCriteriaKeys (IRequestContext context, string[] keys)
+ {
+ if (!context.HasCriteria ()) return false;
+
+ IDictionary criteria = context.Criteria;
+ bool found = true;
+ foreach (string v in keys)
+ {
+ found = found && criteria.Contains (v);
+ }
+ return found;
+ }
+
+
/// <summary>
/// Convenience method to confirm that no Exception was caught.
/// </summary>
@@ -98,5 +141,162 @@
Assert.Fail (outer.ToString ());
}
}
+
+ /// <summary>
+ /// Convenience method to confirm
+ /// that there are no alerts or fault.
+ /// </summary>
+ /// <param name="helper">Helper under test</param>
+ ///
+ public void AssertNominal (IViewHelper helper)
+ {
+ bool hasFault = helper.HasFault;
+ if (hasFault)
+ Assert.Fail (helper.Fault.Message);
+
+ bool hasAlerts = helper.HasAlerts;
+ if (hasAlerts)
+ {
+ Assert.Fail(helper.ErrorsText);
+ }
+ }
+
+ /// <summary>
+ /// Confirm that the value is stored in the context under the key.
+ /// </summary>
+ /// <param name="context">The context to check</param>
+ /// <param name="key">The key</param>
+ /// <param name="value">The value</param>
+ protected void AssertKey (IDictionary context, string key, string value)
+ {
+ Assert.IsNotNull (value, "Value is null");
+ Assert.IsNotNull (key, "Key is null");
+ Assert.IsTrue (value.Equals (context [key]), "Key:Value mismatch: " + key + ":" + value);
+ }
+
+ /// <summary>
+ /// Confirm that the given context contains the given keys.
+ /// </summary>
+ /// <param name="context">The context to check</param>
+ /// <param name="keys">The keys to check</param>
+ protected void AssertKeys (IRequestContext context, string[] keys)
+ {
+ Assert.IsTrue (ContainsKeys (context,keys), "Missing keys.");
+ }
+
+ /// <summary>
+ /// Confirm that the context contains the keys,
+ /// that each key represents an non-null IList,
+ /// and that each IList is not empty.
+ /// </summary>
+ /// <param name="context">The context to check</param>
+ /// <param name="keys">The list keys</param>
+ protected void AssertListKeys (IRequestContext context, string[] keys)
+ {
+ AssertKeys (context, keys);
+ foreach (string key in keys)
+ {
+ IList list = context [key] as IList;
+ Assert.IsNotNull (list, "List is null: " + key);
+ Assert.IsTrue (list.Count > 0, "List is empty");
+ }
+ }
+
+ /// <summary>
+ /// Call AssertList(string,int) with no minimum.
+ /// </summary>
+ /// <param name="id"></param>
+ protected IRequestContext AssertList (string id)
+ {
+ return AssertList (id, 0);
+ }
+
+ /// <summary>
+ /// Execute the Command for the given id,
+ /// and confirm that the return state is Nominal,
+ /// has an Outcome,
+ /// that the Outcome is an non-null IList,
+ /// and that the IList containes at list minCount items.
+ /// </summary>
+ /// <param name="id">The List Command to check</param>
+ protected IRequestContext AssertList (string id, int minCount)
+ {
+ IRequestContext context = catalog.GetRequest (id);
+ catalog.ExecuteRequest (context);
+ AssertNominal (context);
+ Assert.IsTrue (context.HasOutcome, "Expected outcome");
+ IList list = context.Outcome as IList;
+ Assert.IsNotNull (list, "Expected outcome as IList");
+ Assert.IsTrue (list.Count >= minCount, "Expected list entries");
+ return context;
+ }
+
+ #endregion
+
+ #region data access tests
+
+ /// <summary>
+ /// Virtual method for populating a context
+ /// for use with other routine tests.
+ /// </summary>
+ /// <param name="context"></param>
+ protected virtual void Populate (IDictionary context)
+ {
+ // override to populate context
+ throw new NotImplementedException ("CatalogBaseTest.Populate must be overridden.");
+ }
+
+ /// <summary>
+ /// Insert and then delete a new record,
+ /// calling the Populate method to fill the context with the appropriate values.
+ /// </summary>
+ /// <param name="insertId">The "save" command name</param>
+ /// <param name="keyId">The name of the primary key field</param>
+ /// <param name="keyValue">The primary key value initially set by Populate</param>
+ /// <param name="deleteId">The "delete" command name</param>
+ protected IRequestContext AssertInsertDelete (string insertId, string keyId, string keyValue, string deleteId)
+ {
+ IRequestContext context = catalog.GetRequest (insertId);
+ Populate (context);
+ context [keyId] = String.Empty;
+
+ catalog.ExecuteRequest (context);
+ AssertNominal (context);
+ Assert.IsFalse (keyValue.Equals (context [keyId]), "Expected new primary key");
+
+ ICommand delete = catalog.GetCommand (deleteId);
+ delete.Execute (context);
+ AssertNominal (context);
+ return context;
+ }
+
+ protected IRequestContext AssertEdit (string editId, string keyId, string keyValue, string[] keys)
+ {
+ IRequestContext context = catalog.GetRequest (editId);
+ context [keyId] = keyValue;
+ catalog.ExecuteRequest (context);
+ AssertNominal (context);
+ Assert.IsTrue (ContainsKeys (context,keys), "Missing fields");
+ return context;
+ }
+
+ /// <summary>
+ /// Update the given record (usually to the same values).
+ /// </summary>
+ /// <param name="updateId">The "save" command</param>
+ /// <param name="keyId">The name of the primary key</param>
+ /// <param name="keyValue">The value of the primary key</param>
+ protected IRequestContext AssertUpdate (string updateId, string keyId, string keyValue)
+ {
+ IRequestContext context = catalog.GetRequest (updateId);
+ Populate (context);
+ catalog.ExecuteRequest (context);
+ AssertNominal (context);
+ Assert.IsTrue (keyValue.Equals (context [keyId]));
+ return context;
+ }
+
+ #endregion
+
}
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/ControllerTest.cs Wed Jun 29 14:13:24 2005
@@ -23,7 +23,7 @@
/// </summary>
///
[TestFixture]
- public class CatalogTest : BaseNexusTest
+ public class CatalogTest : CatalogBaseTest
{
/// <summary>
/// A simple "list all" command should return nominal with an outcome.
Modified: struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Test/ObjectByKeyTest.cs Wed Jun 29 14:13:24 2005
@@ -9,7 +9,7 @@
/// Prove that a single object can be returned by Execute, without error.
/// </summary>
[TestFixture]
- public class ObjectByKeyTest : BaseNexusTest
+ public class ObjectByKeyTest : CatalogBaseTest
{
public const string OBJECT_BY_KEY = "ObjectByKey";
public const string OBJECT_BY_KEY_WITH_VALIDATE = "ObjectByKeyWithValidate";
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=202429&r1=202428&r2=202429&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 29 14:13:24 2005
@@ -7,16 +7,13 @@
<object id="ConvertInput" type="Nexus.Core.Validators.ConvertInput">
<property name="ID"><value>ConvertInput</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="Required"><value>{0} is required.</value></property>
</object>
- <!-- pre-op -->
- <object id="pre-op" type="Nexus.Core.RequestChain">
+ <object id="PreOp" type="Nexus.Core.RequestChain">
<property name="ID"><value>pre-op</value></property>
<property name="AddCommands">
<list>
@@ -25,8 +22,7 @@
</property>
</object>
- <!-- post-op -->
- <object id="post-op" type="Nexus.Core.RequestChain">
+ <object id="PostOp" type="Nexus.Core.RequestChain">
<property name="ID"><value>post-op</value></property>
<property name="AddCommands">
<list>
@@ -34,22 +30,18 @@
</list>
</property>
</object>
-
- <!-- Catalog
- <object id="Catalog" type="Nexus.Extras.Spring.Catalog"/>
- -->
+
+<!-- Catalog -->
+
+ <object id="Catalog" type="Nexus.Extras.Spring.Catalog">
+ <property name="PreOp"><ref object="PreOp"/></property>
+ <property name="PostOp"><ref object="PostOp"/></property>
+ </object>
<!-- FieldTable -->
<object id="FieldTable" type="Nexus.Core.Tables.FieldTable">
<property name="Strict"><value>true</value></property>
- <property name="AddFieldContexts">
- <list>
- <ref object="pk_something"/>
- <ref object="SomeDate"/>
- <ref object="SomethingResult"/>
- </list>
- </property>
<property name="AddProcessors">
<list>
<ref object="CollectionProcessor"/>
@@ -57,24 +49,13 @@
<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>
+ <property name="AddFieldContexts">
+ <list>
+ <ref object="pk_something"/>
+ <ref object="SomeDate"/>
+ <ref object="SomethingResult"/>
+ </list>
+ </property>
</object>
<!-- Field Processors -->
@@ -85,11 +66,37 @@
<object id="DateTimeProcessor" type="Nexus.Core.Validators.DateTimeProcessor">
<property name="ID"><value>DateTimeProcessor</value></property>
+ <property name="Alert"><value>{0} must be a valid date</value></property>
<property name="DataFormat"><value>d</value></property>
</object>
<object id="StringProcessor" type="Nexus.Core.Validators.StringProcessor">
<property name="ID"><value>StringProcessor</value></property>
</object>
-
+
+<!-- Fields -->
+
+ <object id="BaseFieldContext" type="Nexus.Core.Tables.FieldContext">
+ <property name="Alert"><value>{0} is invalid.</value></property>
+ <property name="Required"><value>{0} is required.</value></property>
+ </object>
+
+ <object id="pk_something" parent="BaseFieldContext">
+ <property name="ID"><value>pk_something</value></property>
+ <property name="Label"><value>Something Key</value></property>
+ <property name="Processor"><ref object="StringProcessor"/></property>
+ </object>
+
+ <object id="SomethingResult" parent="BaseFieldContext">
+ <property name="ID"><value>SomethingResult</value></property>
+ <property name="Label"><value>Something Result</value></property>
+ <property name="Processor"><ref object="StringProcessor"/></property>
+ </object>
+
+ <object id="SomeDate" parent="BaseFieldContext">
+ <property name="ID"><value>SomeDate</value></property>
+ <property name="Label"><value>Some Date</value></property>
+ <property name="Processor"><ref object="DateTimeProcessor"/></property>
+ </object>
+
</objects>
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs Wed Jun 29 14:13:24 2005
@@ -6,10 +6,9 @@
using Nexus.Core.Helpers;
using Nexus.Core.Tables;
using Nexus.Web;
-using Nexus.Web.Helpers;
using Spring.Context;
-namespace Nexus
+namespace Nexus.Web
{
/// <summary>
/// Summary description for GridViewHelper.
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs?rev=202429&r1=202428&r2=202429&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs Wed Jun 29 14:13:24 2005
@@ -21,7 +21,7 @@
using Nexus.Core;
using Nexus.Core.Helpers;
-namespace Nexus.Web.Helpers
+namespace Nexus.Web
{
/// <summary>
/// Implement IWebViewHelper [OVR-14].
@@ -410,8 +410,9 @@
BoundColumn column = new BoundColumn ();
column.HeaderText = headerText;
column.DataField = dataField;
- column.SortExpression = sortExpression; // See DataGridColumn.SortExpression Property
- column.DataFormatString = dataFormat; // See Formatting Types in .NET Dev Guide
+ // ISSUE: Not being used in example applications.
+ column.DataFormatString = dataFormat; // See Formatting Types in .NET Dev Guide
+ column.SortExpression = sortExpression; // See DataGridColumn.SortExpression Property
grid.Columns.AddAt (pos, column);
return pos + 1;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org