#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Ingenious.Mvc.Util;
namespace Ingenious.Mvc.Factories{
/// <summary>
/// A default factory for creating tasks.
/// </summary>
/// <remarks>
/// <para>
/// This class is a default implementation of <see cref="ITaskFactory"/> which the Ingenious MVC framework uses if no other factory is
/// specified. The <see cref="Instance"/> property yields the one and only instance of this class.
/// </para>
/// </remarks>
[Serializable]
public sealed class DefaultTaskFactory : DefaultFactoryBase, ITaskFactory
{
private static DefaultTaskFactory _instance;
private static readonly object _instanceLock = new object();
private static readonly Type[] _argTypes = new Type[] { typeof(Task), typeof(Id<Task>), typeof(TaskManager), typeof(object) };
private static readonly string[] _argNames = new string[] { "Owner", "Id", "TaskManager", "Data" };
private static readonly Log _log = Log.CreateForType(typeof(DefaultTaskFactory));
/// <summary>
/// Gets the one and only instance of this class.
/// </summary>
public static ITaskFactory Instance
{
get
{
lock (_instanceLock)
{
if (_instance == null)
{
_instance = new DefaultTaskFactory();
}
}
return _instance;
}
}
/// <summary>
/// Gets the name of this factory.
/// </summary>
public override string Name
{
get
{
return "Default Task";
}
}
/// <summary>
/// Creates a <see cref="Task"/> instance.
/// </summary>
/// <param name="owner">
/// The owning task, if any.
/// </param>
/// <param name="id">
/// The ID of the task to create.
/// </param>
/// <param name="taskManager">
/// The <see cref="TaskManager"/> that is managing the task.
/// </param>
/// <param name="data">
/// Any data for the task.
/// </param>
/// <returns>
/// The created and initialized <see cref="Task"/> instance.
/// </returns>
public Task Create(Task owner, Id<Task> id, TaskManager taskManager, object data)
{
ArgumentHelper.AssertNotEmpty(id, "id");
ArgumentHelper.AssertNotNull(taskManager, "taskManager");
_log.Verbose("Creating task with ID '{0}' for owner task with ID '{1}'.", id, (owner == null) ? string.Empty : owner.Id.ToString());
//create and return the task
return CreateInstance(typeof(Task), null, _argTypes, new object[] { owner, id, taskManager, data }, _argNames, Type.EmptyTypes) as Task;
}
private DefaultTaskFactory()
{
}
}
}
|