KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > plugin > PluginManager


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.plugin;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Vector JavaDoc;
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 /**
33  * This object will manage the different plugins
34  *
35  * @author JC Meillaud
36  * @author A Peyrard
37  */

38 public class PluginManager {
39     static Category cat = Category.getInstance(PluginManager.class.getName());
40     /**
41      * The unique instance of the object
42      */

43     protected static PluginManager instance = null;
44     /**
45      * The hashatable which will store the plugins descriptions
46      */

47     private Hashtable JavaDoc plugins;
48     /**
49      * Inaccessible constructor
50      *
51      */

52     protected PluginManager() {
53         cat.debug("-> constructor") ;
54         this.plugins = new Hashtable JavaDoc();
55     }
56
57     /**
58      * This method build the table which store the plugins descriptions
59      *
60      * @param dirName
61      * The directory to be scanned in order to search plugins
62      * descriptions files
63      */

64     public void initialisePluginsTable(String JavaDoc dirName) {
65         cat.debug("-> initialisePluginsTable") ;
66         // search the directories where the plugin are defined
67
String JavaDoc[] files = SearchPluginFile.searchPlugins(new String JavaDoc(dirName
68                 + "/"), FileName.PLUGIN_PROPERTIES_FILE);
69         if (files == null) {
70             cat.warn("No plugins found...") ;
71             return ;
72         }
73         // for each location analyse the plugins informations
74
for (int i = 0; i < files.length; i++) {
75             PluginDescription temp = PluginDescription
76                     .loadPluginDescription(files[i], ClifClassLoader.getClassLoader());
77             // add the plugin description which has be analysed
78
if (temp != null) {
79                 this.plugins.put(temp.getName(), temp);
80             }
81         }
82     }
83
84     /**
85      * Get the instance of the plugin manager, this instance is unique
86      *
87      * @return The plugin manager
88      */

89     public static PluginManager getPluginManager() {
90         cat.debug("-> getPluginManager") ;
91         if (instance == null)
92             instance = new PluginManager();
93         return instance;
94     }
95
96     /**
97      * Create a new vector with an entry for each actions, parameters values
98      * will be set to null
99      *
100      * @param type
101      * The type of the action searched
102      * @return The nodes descriptions
103      */

104     public Vector JavaDoc createNodesDescriptions(String JavaDoc type) {
105         cat.debug("-> createNodesDescriptions") ;
106         Vector JavaDoc result = new Vector JavaDoc();
107         Enumeration JavaDoc 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     /**
116      * Create a new node description for a selected action of a selected plugin
117      *
118      * @param plugin
119      * The name of the plugin
120      * @param type
121      * The type of the action
122      * @param name
123      * The name of the action
124      * @return The node description for this action
125      */

126     public NodeDescription createNodeDescription(String JavaDoc plugin, String JavaDoc type,
127             String JavaDoc 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     /**
137      * Create a new vector with an entry for each actions, parameters values
138      * will be set to null But only action of the plugin define in the vector
139      * which is given
140      *
141      * @param pluginsName
142      * The names of the plugins
143      * @param type
144      * The type of the action searched
145      * @return The nodes descriptions
146      */

147     public Vector JavaDoc createNodesDescriptionsByPlugins(Vector JavaDoc pluginsName,
148             String JavaDoc type) {
149         cat.debug("-> createNodesDescriptionsByPlugins") ;
150         Vector JavaDoc result = new Vector JavaDoc();
151         Enumeration JavaDoc 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     /**
161      * This method return the help lines of the action of a selected plugin
162      * @param plugin
163      * The plugin name
164      * @param type
165      * The type of the action
166      * @param action
167      * The name of the action
168      * @return The help lines of the action
169      */

170     public Vector JavaDoc getPluginActionHelp(String JavaDoc plugin, String JavaDoc type, String JavaDoc action) {
171         cat.debug("-> getPluginActionHelp") ;
172         if (this.plugins.containsKey(plugin)) {
173             PluginDescription temp = (PluginDescription) this.plugins
174                     .get(plugin);
175             Vector JavaDoc helpLines = temp.getActionHelp(type, action);
176             return helpLines;
177         }
178         return null;
179     }
180
181     /**
182      * This method return the gui key of an specified action of a specified plugin
183      * @param plugin The plugin name
184      * @param type The action type
185      * @param action The action name
186      * @return The gui key
187      */

188     public String JavaDoc getPluginActionGUIKey(String JavaDoc plugin, String JavaDoc type, String JavaDoc 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