1 23 package org.objectweb.clif.scenario.util.isac.plugin; 24 import java.util.Enumeration ; 25 import java.util.Hashtable ; 26 import java.util.Vector ; 27 28 import org.apache.log4j.Category; 29 import org.objectweb.clif.scenario.util.isac.FileName; 30 import org.objectweb.clif.scenario.util.isac.util.tree.NodeDescription; 31 import org.objectweb.clif.util.ClifClassLoader; 32 38 public class PluginManager { 39 static Category cat = Category.getInstance(PluginManager.class.getName()); 40 43 protected static PluginManager instance = null; 44 47 private Hashtable plugins; 48 52 protected PluginManager() { 53 cat.debug("-> constructor") ; 54 this.plugins = new Hashtable (); 55 } 56 57 64 public void initialisePluginsTable(String dirName) { 65 cat.debug("-> initialisePluginsTable") ; 66 String [] files = SearchPluginFile.searchPlugins(new String (dirName 68 + "/"), FileName.PLUGIN_PROPERTIES_FILE); 69 if (files == null) { 70 cat.warn("No plugins found...") ; 71 return ; 72 } 73 for (int i = 0; i < files.length; i++) { 75 PluginDescription temp = PluginDescription 76 .loadPluginDescription(files[i], ClifClassLoader.getClassLoader()); 77 if (temp != null) { 79 this.plugins.put(temp.getName(), temp); 80 } 81 } 82 } 83 84 89 public static PluginManager getPluginManager() { 90 cat.debug("-> getPluginManager") ; 91 if (instance == null) 92 instance = new PluginManager(); 93 return instance; 94 } 95 96 104 public Vector createNodesDescriptions(String type) { 105 cat.debug("-> createNodesDescriptions") ; 106 Vector result = new Vector (); 107 Enumeration e = this.plugins.elements(); 108 while (e.hasMoreElements()) { 109 PluginDescription temp = (PluginDescription) e.nextElement(); 110 result.addAll(temp.createNodesDescriptions(type)); 111 } 112 return result; 113 } 114 115 126 public NodeDescription createNodeDescription(String plugin, String type, 127 String name) { 128 cat.debug("-> createNodeDescription") ; 129 if (this.plugins.containsKey(plugin)) { 130 PluginDescription temp = (PluginDescription)this.plugins.get(plugin); 131 return temp.createNodeDescription(type, name) ; 132 } 133 return null; 134 } 135 136 147 public Vector createNodesDescriptionsByPlugins(Vector pluginsName, 148 String type) { 149 cat.debug("-> createNodesDescriptionsByPlugins") ; 150 Vector result = new Vector (); 151 Enumeration e = this.plugins.elements(); 152 while (e.hasMoreElements()) { 153 PluginDescription temp = (PluginDescription) e.nextElement(); 154 if (pluginsName.contains(temp.getName())) 155 result.addAll(temp.createNodesDescriptions(type)); 156 } 157 return result; 158 } 159 160 170 public Vector getPluginActionHelp(String plugin, String type, String action) { 171 cat.debug("-> getPluginActionHelp") ; 172 if (this.plugins.containsKey(plugin)) { 173 PluginDescription temp = (PluginDescription) this.plugins 174 .get(plugin); 175 Vector helpLines = temp.getActionHelp(type, action); 176 return helpLines; 177 } 178 return null; 179 } 180 181 188 public String getPluginActionGUIKey(String plugin, String type, String action) { 189 cat.debug("-> getPluginActionGUIKey") ; 190 if (this.plugins.containsKey(plugin)) { 191 PluginDescription temp = (PluginDescription) this.plugins.get(plugin); 192 return temp.getActionGUIKey(type, action); 193 } 194 return null ; 195 } 196 } | Popular Tags |