aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/DataPluginFactory.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/DataPluginFactory.cs155
1 files changed, 0 insertions, 155 deletions
diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs
deleted file mode 100644
index 841f71e..0000000
--- a/OpenSim/Data/DataPluginFactory.cs
+++ /dev/null
@@ -1,155 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenSim.Framework;
31
32namespace OpenSim.Data
33{
34 /// <summary>
35 /// A static class containing methods for obtaining handles to database
36 /// storage objects.
37 /// </summary>
38 public static class DataPluginFactory
39 {
40 /// <summary>
41 /// Based on <typeparam name="T" />, returns the appropriate
42 /// PluginInitialiserBase instance in <paramref name="init" /> and
43 /// extension point path in <paramref name="path" />.
44 /// </summary>
45 /// <param name="connect">
46 /// The DB connection string used when creating a new
47 /// PluginInitialiserBase, returned in <paramref name="init" />.
48 /// </param>
49 /// <param name="init">
50 /// A reference to a PluginInitialiserBase object in which the proper
51 /// initialiser will be returned.
52 /// </param>
53 /// <param name="path">
54 /// A string in which the proper extension point path will be returned.
55 /// </param>
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
64 {
65 Type type = typeof(T);
66
67 if (type == typeof(IInventoryDataPlugin))
68 {
69 init = new InventoryDataInitialiser(connect);
70 path = "/OpenSim/InventoryData";
71 }
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 }
97 }
98
99 /// <summary>
100 /// Returns a list of new <typeparamref name="T" /> data plugins.
101 /// Plugins will be requested in the order they were added.
102 /// </summary>
103 /// <param name="provider">
104 /// The filename of the inventory server plugin DLL.
105 /// </param>
106 /// <param name="connect">
107 /// The connection string for the storage backend.
108 /// </param>
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
116 {
117 PluginInitialiserBase pluginInitialiser;
118 string extensionPointPath;
119
120 PluginLoaderParamFactory<T>(connect, out pluginInitialiser, out extensionPointPath);
121
122 using (PluginLoader<T> loader = new PluginLoader<T>(pluginInitialiser))
123 {
124 // loader will try to load all providers (MySQL, MSSQL, etc)
125 // unless it is constrainted to the correct "Provider" entry in the addin.xml
126 loader.Add(extensionPointPath, new PluginProviderFilter(provider));
127 loader.Load();
128
129 return loader.Plugins;
130 }
131 }
132
133 /// <summary>
134 /// Returns a new <typeparamref name="T" /> data plugin instance if
135 /// only one was loaded, otherwise returns null (<c>default(T)</c>).
136 /// </summary>
137 /// <param name="provider">
138 /// The filename of the inventory server plugin DLL.
139 /// </param>
140 /// <param name="connect">
141 /// The connection string for the storage backend.
142 /// </param>
143 /// <typeparam name="T">
144 /// The type of data plugin requested.
145 /// </typeparam>
146 /// <returns>
147 /// A list of all loaded plugins matching <typeparamref name="T" />.
148 /// </returns>
149 public static T LoadDataPlugin<T>(string provider, string connect) where T : IPlugin
150 {
151 List<T> plugins = LoadDataPlugins<T>(provider, connect);
152 return (plugins.Count == 1) ? plugins[0] : default(T);
153 }
154 }
155}