Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 103:3593d5d756ef
Fixes #124: Remove factory factory
* Remove factory factory. Future work on plugins should let the plugin's "activation" methods register the factory
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 15 Aug 2009 09:40:05 +0000 |
parents | c85ea8988455 |
children | 2f3cafb69799 |
files | IBBoard.WarFoundry.API.csproj api/Factories/WarFoundryFactoryFactory.cs |
diffstat | 2 files changed, 0 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj Sat Aug 15 09:25:28 2009 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Aug 15 09:40:05 2009 +0000 @@ -70,7 +70,6 @@ <Compile Include="api\Factories\INativeWarFoundryFactory.cs" /> <Compile Include="api\Factories\INonNativeWarFoundryFactory.cs" /> <Compile Include="api\Factories\IWarFoundryFactory.cs" /> - <Compile Include="api\Factories\WarFoundryFactoryFactory.cs" /> <Compile Include="api\Factories\Xml\WarFoundryXmlElementName.cs" /> <Compile Include="api\Factories\Xml\WarFoundryXmlFactory.cs" /> <Compile Include="api\Factories\Xml\WarFoundryXmlSaver.cs" />
--- a/api/Factories/WarFoundryFactoryFactory.cs Sat Aug 15 09:25:28 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -// This file (WarFoundryFactoryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Collections.Generic; -using System.Reflection; -using IBBoard; -using IBBoard.Logging; - -namespace IBBoard.WarFoundry.API.Factories -{ - public class WarFoundryFactoryFactory - { - private Dictionary<Type, IWarFoundryFactory> factories = new Dictionary<Type, IWarFoundryFactory>(); - private Type defaultType; - private static WarFoundryFactoryFactory factoryFactory; - - private WarFoundryFactoryFactory() - { - } - - public static WarFoundryFactoryFactory GetFactoryFactory() - { - if (factoryFactory == null) - { - factoryFactory = new WarFoundryFactoryFactory(); - } - - return factoryFactory; - } - - public IWarFoundryFactory GetFactory() - { - return GetFactory(DefaultType); - } - - public IWarFoundryFactory GetFactory(Type cls) - { - cls = CheckType(cls); - - IWarFoundryFactory factory = null; - factories.TryGetValue(cls, out factory); - - if (factory == null) - { - factory = null; - MethodInfo method = cls.GetMethod("GetFactory"); - - if (method!=null) - { - LogNotifier.Debug(GetType(), "Found GetFactory method on " + cls.Name); - object temp = method.Invoke(null, new object[]{}); - - if (temp is IWarFoundryFactory) - { - factory = (IWarFoundryFactory)temp; - factories.Add(cls, factory); - } - } - - if (factory == null) - { - throw new ArgumentException("Could not create factory for class "+cls.FullName); - } - } - - return factory; - } - - public Type DefaultType - { - get { return defaultType; } - set { - value = CheckType(value); - defaultType = value; - } - } - - private Type CheckType(Type cls) - { - if (cls == null) - { - if (DefaultType!=null) - { - return DefaultType; - } - else - { - throw new InvalidOperationException("Class cannot be null when no default class is set"); - } - } - else if (!typeof(IWarFoundryFactory).IsAssignableFrom(cls)) - { - throw new ArgumentException("Class "+cls.FullName+" was not a subtype of "+typeof(IWarFoundryFactory).FullName); - } - - return cls; - } - } -}