chris@3: /* chris@3: * SONEWS News Server chris@3: * see AUTHORS for the list of contributors chris@3: * chris@3: * This program is free software: you can redistribute it and/or modify chris@3: * it under the terms of the GNU General Public License as published by chris@3: * the Free Software Foundation, either version 3 of the License, or chris@3: * (at your option) any later version. chris@3: * chris@3: * This program is distributed in the hope that it will be useful, chris@3: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@3: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@3: * GNU General Public License for more details. chris@3: * chris@3: * You should have received a copy of the GNU General Public License chris@3: * along with this program. If not, see . chris@3: */ chris@3: chris@3: package org.sonews.storage; chris@3: chris@3: /** chris@3: * chris@3: * @author Christian Lins chris@3: * @since sonews/1.0 chris@3: */ chris@3: public final class StorageManager chris@3: { chris@3: cli@37: private static StorageProvider provider; chris@3: cli@37: public static Storage current() cli@37: throws StorageBackendException cli@37: { cli@37: synchronized (StorageManager.class) { cli@37: if (provider == null) { cli@37: return null; cli@37: } else { cli@37: return provider.storage(Thread.currentThread()); cli@37: } cli@37: } cli@37: } chris@3: cli@37: public static StorageProvider loadProvider(String pluginClassName) cli@37: { cli@37: try { cli@37: Class clazz = Class.forName(pluginClassName); cli@37: Object inst = clazz.newInstance(); cli@37: return (StorageProvider) inst; cli@37: } catch (Exception ex) { cli@37: System.err.println(ex); cli@37: return null; cli@37: } cli@37: } chris@3: cli@37: /** cli@37: * Sets the current storage provider. cli@37: * @param provider cli@37: */ cli@37: public static void enableProvider(StorageProvider provider) cli@37: { cli@37: synchronized (StorageManager.class) { cli@37: if (StorageManager.provider != null) { cli@37: disableProvider(); cli@37: } cli@37: StorageManager.provider = provider; cli@37: } cli@37: } chris@3: cli@37: /** cli@37: * Disables the current provider. cli@37: */ cli@37: public static void disableProvider() cli@37: { cli@37: synchronized (StorageManager.class) { cli@37: provider = null; cli@37: } cli@37: } chris@3: }