diff options
author | Mike Mazur | 2009-02-09 00:33:44 +0000 |
---|---|---|
committer | Mike Mazur | 2009-02-09 00:33:44 +0000 |
commit | 369eef5fcd8e6566d5f953db6a6b093cf674269c (patch) | |
tree | 1f9f1373ec68f48d359d9037c3907d5d1ffd2ecf /OpenSim/Data | |
parent | * Once again, fixing linked prim collisions by putting AbsolutePosition = Abs... (diff) | |
download | opensim-SC-369eef5fcd8e6566d5f953db6a6b093cf674269c.zip opensim-SC-369eef5fcd8e6566d5f953db6a6b093cf674269c.tar.gz opensim-SC-369eef5fcd8e6566d5f953db6a6b093cf674269c.tar.bz2 opensim-SC-369eef5fcd8e6566d5f953db6a6b093cf674269c.tar.xz |
The DataPluginFactory is now a set of generic methods instead of
multiple duplicates of the same code.
Diffstat (limited to 'OpenSim/Data')
-rw-r--r-- | OpenSim/Data/DataPluginFactory.cs | 151 |
1 files changed, 82 insertions, 69 deletions
diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs index 5293e94..2f60ae4 100644 --- a/OpenSim/Data/DataPluginFactory.cs +++ b/OpenSim/Data/DataPluginFactory.cs | |||
@@ -25,117 +25,130 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
29 | using OpenSim.Framework; | 30 | using OpenSim.Framework; |
30 | 31 | ||
31 | namespace OpenSim.Data | 32 | namespace OpenSim.Data |
32 | { | 33 | { |
33 | /// <summary> | 34 | /// <summary> |
34 | /// A static class containing a series of methods for obtaining handles to | 35 | /// A static class containing methods for obtaining handles to database |
35 | /// database storage objects. | 36 | /// storage objects. |
36 | /// </summary> | 37 | /// </summary> |
37 | // Yeah, it's not really a factory, but maybe it'll morph into one? | ||
38 | public static class DataPluginFactory | 38 | public static class DataPluginFactory |
39 | { | 39 | { |
40 | /// <summary> | 40 | /// <summary> |
41 | /// Returns a list of new inventory data plugins. Plugins will be | 41 | /// Based on <typeparam name="T" />, returns the appropriate |
42 | /// requested in the order they were added. | 42 | /// PluginInitialiserBase instance in <paramref name="init" /> and |
43 | /// extension point path in <paramref name="path" />. | ||
43 | /// </summary> | 44 | /// </summary> |
44 | /// <param name="provider"> | ||
45 | /// The filename of the inventory server plugin DLL. | ||
46 | /// </param> | ||
47 | /// <param name="connect"> | 45 | /// <param name="connect"> |
48 | /// The connection string for the storage backend. | 46 | /// The DB connection string used when creating a new |
47 | /// PluginInitialiserBase, returned in <paramref name="init" />. | ||
49 | /// </param> | 48 | /// </param> |
50 | public static List<IInventoryDataPlugin> LoadInventoryDataPlugins(string provider, string connect) | 49 | /// <param name="init"> |
51 | { | 50 | /// A reference to a PluginInitialiserBase object in which the proper |
52 | PluginLoader<IInventoryDataPlugin> loader = new PluginLoader<IInventoryDataPlugin> (new InventoryDataInitialiser(connect)); | 51 | /// initialiser will be returned. |
53 | |||
54 | // loader will try to load all providers (MySQL, MSSQL, etc) | ||
55 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | ||
56 | loader.Add ("/OpenSim/InventoryData", new PluginProviderFilter(provider)); | ||
57 | loader.Load(); | ||
58 | |||
59 | return loader.Plugins; | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Returns a list of new user data plugins. Plugins will be requested | ||
64 | /// in the order they were added. | ||
65 | /// </summary> | ||
66 | /// <param name="provider"> | ||
67 | /// The filename of the user data plugin DLL. | ||
68 | /// </param> | 52 | /// </param> |
69 | /// <param name="connect"> | 53 | /// <param name="path"> |
70 | /// The connection string for the storage backend. | 54 | /// A string in which the proper extension point path will be returned. |
71 | /// </param> | 55 | /// </param> |
72 | public static List<IUserDataPlugin> LoadUserDataPlugins(string provider, string connect) | 56 | /// <typeparam name="T"> |
57 | /// The type of data plugin requested. | ||
58 | /// </typeparam> | ||
59 | /// <exception cref="NotImplementedException"> | ||
60 | /// Thrown if <typeparamref name="T" /> is not one of the expected data | ||
61 | /// interfaces. | ||
62 | /// </exception> | ||
63 | private static void PluginLoaderParamFactory<T>(string connect, out PluginInitialiserBase init, out string path) where T : IPlugin | ||
73 | { | 64 | { |
74 | PluginLoader<IUserDataPlugin> loader = new PluginLoader<IUserDataPlugin>(new UserDataInitialiser(connect)); | 65 | Type type = typeof(T); |
75 | 66 | ||
76 | // loader will try to load all providers (MySQL, MSSQL, etc) | 67 | if (type == typeof(IInventoryDataPlugin)) |
77 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | 68 | { |
78 | loader.Add("/OpenSim/UserData", new PluginProviderFilter(provider)); | 69 | init = new InventoryDataInitialiser(connect); |
79 | loader.Load(); | 70 | path = "/OpenSim/InventoryData"; |
80 | 71 | } | |
81 | return loader.Plugins; | 72 | else if (type == typeof(IUserDataPlugin)) |
73 | { | ||
74 | init = new UserDataInitialiser(connect); | ||
75 | path = "/OpenSim/UserData"; | ||
76 | } | ||
77 | else if (type == typeof(IGridDataPlugin)) | ||
78 | { | ||
79 | init = new GridDataInitialiser(connect); | ||
80 | path = "/OpenSim/GridData"; | ||
81 | } | ||
82 | else if (type == typeof(ILogDataPlugin)) | ||
83 | { | ||
84 | init = new LogDataInitialiser(connect); | ||
85 | path = "/OpenSim/LogData"; | ||
86 | } | ||
87 | else if (type == typeof(IAssetDataPlugin)) | ||
88 | { | ||
89 | init = new AssetDataInitialiser(connect); | ||
90 | path = "/OpenSim/AssetData"; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | // We don't support this data plugin. | ||
95 | throw new NotImplementedException(String.Format("The type '{0}' is not a valid data plugin.", type)); | ||
96 | } | ||
82 | } | 97 | } |
83 | 98 | ||
84 | /// <summary> | 99 | /// <summary> |
85 | /// Returns a list of new grid data plugins. Plugins will be requested | 100 | /// Returns a list of new <typeparamref name="T" /> data plugins. |
86 | /// in the order they were added. | 101 | /// Plugins will be requested in the order they were added. |
87 | /// </summary> | 102 | /// </summary> |
88 | /// <param name="provider"> | 103 | /// <param name="provider"> |
89 | /// The filename of the user data plugin DLL. | 104 | /// The filename of the inventory server plugin DLL. |
90 | /// </param> | 105 | /// </param> |
91 | /// <param name="connect"> | 106 | /// <param name="connect"> |
92 | /// The connection string for the storage backend. | 107 | /// The connection string for the storage backend. |
93 | /// </param> | 108 | /// </param> |
94 | public static List<IGridDataPlugin> LoadGridDataPlugins(string provider, string connect) | 109 | /// <typeparam name="T"> |
110 | /// The type of data plugin requested. | ||
111 | /// </typeparam> | ||
112 | /// <returns> | ||
113 | /// A list of all loaded plugins matching <typeparamref name="T" />. | ||
114 | /// </returns> | ||
115 | public static List<T> LoadDataPlugins<T>(string provider, string connect) where T : IPlugin | ||
95 | { | 116 | { |
96 | PluginLoader<IGridDataPlugin> loader = new PluginLoader<IGridDataPlugin>(new GridDataInitialiser(connect)); | 117 | PluginInitialiserBase pluginInitialiser; |
118 | string extensionPointPath; | ||
119 | |||
120 | PluginLoaderParamFactory<T>(connect, out pluginInitialiser, out extensionPointPath); | ||
121 | |||
122 | PluginLoader<T> loader = new PluginLoader<T>(pluginInitialiser); | ||
97 | 123 | ||
98 | // loader will try to load all providers (MySQL, MSSQL, etc) | 124 | // loader will try to load all providers (MySQL, MSSQL, etc) |
99 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | 125 | // unless it is constrainted to the correct "Provider" entry in the addin.xml |
100 | loader.Add("/OpenSim/GridData", new PluginProviderFilter(provider)); | 126 | loader.Add(extensionPointPath, new PluginProviderFilter(provider)); |
101 | loader.Load(); | 127 | loader.Load(); |
102 | 128 | ||
103 | return loader.Plugins; | 129 | return loader.Plugins; |
104 | } | 130 | } |
105 | 131 | ||
106 | /// <summary> | 132 | /// <summary> |
107 | /// Returns a list of new log data plugins. Plugins will be requested | 133 | /// Returns a new <typeparamref name="T" /> data plugin instance if |
108 | /// in the order they were added. | 134 | /// only one was loaded, otherwise returns null (<c>default(T)</c>). |
109 | /// </summary> | 135 | /// </summary> |
110 | /// <param name="provider"> | 136 | /// <param name="provider"> |
111 | /// The filename of the user data plugin DLL. | 137 | /// The filename of the inventory server plugin DLL. |
112 | /// </param> | 138 | /// </param> |
113 | /// <param name="connect"> | 139 | /// <param name="connect"> |
114 | /// The connection string for the storage backend. | 140 | /// The connection string for the storage backend. |
115 | /// </param> | 141 | /// </param> |
116 | public static List<ILogDataPlugin> LoadLogDataPlugins(string provider, string connect) | 142 | /// <typeparam name="T"> |
143 | /// The type of data plugin requested. | ||
144 | /// </typeparam> | ||
145 | /// <returns> | ||
146 | /// A list of all loaded plugins matching <typeparamref name="T" />. | ||
147 | /// </returns> | ||
148 | public static T LoadDataPlugin<T>(string provider, string connect) where T : IPlugin | ||
117 | { | 149 | { |
118 | PluginLoader<ILogDataPlugin> loader = new PluginLoader<ILogDataPlugin>(new LogDataInitialiser(connect)); | 150 | List<T> plugins = LoadDataPlugins<T>(provider, connect); |
119 | 151 | return (plugins.Count == 1) ? plugins[0] : default(T); | |
120 | // loader will try to load all providers (MySQL, MSSQL, etc) | ||
121 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | ||
122 | loader.Add("/OpenSim/LogData", new PluginProviderFilter(provider)); | ||
123 | loader.Load(); | ||
124 | |||
125 | return loader.Plugins; | ||
126 | } | ||
127 | |||
128 | public static IAssetDataPlugin LoadAssetDataPlugin(string provider, string connect) | ||
129 | { | ||
130 | PluginLoader<IAssetDataPlugin> loader = new PluginLoader<IAssetDataPlugin> (new AssetDataInitialiser (connect)); | ||
131 | |||
132 | // loader will try to load all providers (MySQL, MSSQL, etc) | ||
133 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | ||
134 | loader.Add ("/OpenSim/AssetData", new PluginProviderFilter (provider)); | ||
135 | loader.Load(); | ||
136 | |||
137 | return loader.Plugin; | ||
138 | } | 152 | } |
139 | |||
140 | } | 153 | } |
141 | } | 154 | } |