Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: plugins/Messenger/PluginManager.java


1   /*
2   This file is part of DeXter - Java Internet Communication Solution
3   Copyright (c) 2002 Tobias Riemer
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.1 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
13  GNU 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 program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19  
20  /*
21   * PluginManager.java
22   *
23   * Created on October 22, 2002, 4:02 PM
24   */
25  
26  package plugins.Messenger;
27  
28  import dexter.property.*;
29  import java.util.*;
30  
31  /**
32   *
33   * @author  Christoph Walcher
34   */
35  public class PluginManager {
36      private static List activePlugins = new Vector();
37      private static boolean initialized = false;
38      
39      /** Creates a new instance of PluginManager */
40      protected PluginManager() {
41      }
42      
43      /**
44       * @todo Create a Factory to clone/or copy construct Plugins
45       * @todo Do not use the Default Created Plugin Classes for each PluginChain
46       */
47      public static synchronized void initPlugins(List pluginNames) {
48          
49          if (!initialized && pluginNames != null) {
50              Iterator pluginIter = pluginNames.iterator();
51  
52              while (pluginIter.hasNext()) {
53                  String pluginName = (String)pluginIter.next();
54  
55                  try {
56                      Class c = Class.forName("plugins." + pluginName + "." + pluginName);
57                      Object plugin = c.newInstance();
58                      activePlugins.add((MessengerPlugin)plugin);
59  
60                      System.out.println("Plugin added to PluginManager: " + pluginName);
61                  } catch (Exception ex) {
62                      System.out.println("Plugin could not be started: " + pluginName);
63                      ex.printStackTrace();
64                  }
65              }
66              initialized = true;
67          }
68      }
69      
70      public static PluginChain createPluginChain(Conversation conversation) {
71          if (conversation == null) {
72              throw new IllegalArgumentException("Conversation must not be null");
73          }
74          
75          DefaultPluginChain pluginChain = new DefaultPluginChain();
76          pluginChain.setConversation(conversation);
77          
78            java.util.Iterator pluginIter = activePlugins.iterator();
79          
80            while (pluginIter.hasNext()) {
81              MessengerPlugin plugin = (MessengerPlugin)((MessengerPlugin)pluginIter.next()).clone();
82              
83              // Set the PluginChain refernce for every plugin
84              plugin.init(pluginChain);
85              
86              // add the initialized Plugin to the chain
87              pluginChain.addPlugin(plugin);
88            }
89            
90          return pluginChain;
91      }
92  }