# HG changeset patch # User IBBoard # Date 1250329205 0 # Node ID 3593d5d756ef4872006e333db85e7de13db765be # Parent c85ea89884559157c12970addd9d6377b94245b9 Fixes #124: Remove factory factory * Remove factory factory. Future work on plugins should let the plugin's "activation" methods register the factory diff -r c85ea8988455 -r 3593d5d756ef IBBoard.WarFoundry.API.csproj --- 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 @@ - diff -r c85ea8988455 -r 3593d5d756ef api/Factories/WarFoundryFactoryFactory.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 factories = new Dictionary(); - 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; - } - } -}