001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.preferences; 020 021import icy.plugin.PluginLoader; 022import icy.plugin.abstract_.Plugin; 023import icy.util.ClassUtil; 024 025/** 026 * @author Stephane 027 */ 028public class PluginsPreferences 029{ 030 /** 031 * pref id 032 */ 033 private static final String PREF_ID = "plugins"; 034 035 /** 036 * preferences 037 */ 038 private static XMLPreferences preferences; 039 040 public static void load() 041 { 042 // load preference 043 preferences = IcyPreferences.root().node(PREF_ID); 044 } 045 046 /** 047 * @return the preferences 048 */ 049 public static XMLPreferences getPreferences() 050 { 051 return preferences; 052 } 053 054 /** 055 * Return root node for specified Plugin class. 056 */ 057 public static XMLPreferences root(Class<? extends Plugin> pluginClass) 058 { 059 if (pluginClass != null) 060 { 061 final String className = pluginClass.getName(); 062 063 if (className.startsWith(PluginLoader.PLUGIN_PACKAGE)) 064 return preferences.node(ClassUtil.getPathFromQualifiedName(className 065 .substring(PluginLoader.PLUGIN_PACKAGE.length() + 1))); 066 } 067 068 return null; 069 } 070 071 /** 072 * Return root node for specified Plugin 073 */ 074 public static XMLPreferences root(Plugin plugin) 075 { 076 if (plugin != null) 077 { 078 final String className = plugin.getClass().getName(); 079 080 if (className.startsWith(PluginLoader.PLUGIN_PACKAGE)) 081 return preferences.node(ClassUtil.getPathFromQualifiedName(className 082 .substring(PluginLoader.PLUGIN_PACKAGE.length() + 1))); 083 } 084 085 return null; 086 } 087}