Source Code Cross Referenced for PluginManager.java in  » Groupware » lucane » org » lucane » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » lucane » org.lucane.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Lucane - a collaborative platform
003:         * Copyright (C) 2002  Vincent Fiack <vfiack@mail15.com>
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package org.lucane.client;
020:
021:        import org.lucane.common.*;
022:        import org.lucane.common.net.ObjectConnection;
023:
024:        import java.net.URL;
025:        import java.util.*;
026:
027:        /**
028:         * This is an important part of the Client.
029:         * It can dynamically load plugins.
030:         */
031:        public class PluginManager {
032:            private static PluginManager instance = null;
033:
034:            //stores available plugins in a (name, plugin) map
035:            private HashMap availablePlugins;
036:
037:            //stores running plugins
038:            private ArrayList runningPlugins;
039:
040:            /**
041:             * PluginManager is a singleton
042:             * 
043:             * @return the unique PluginManager instance
044:             */
045:            public static PluginManager getInstance() {
046:                if (instance == null)
047:                    instance = new PluginManager();
048:
049:                return instance;
050:            }
051:
052:            /**
053:             * Creates a PluginManager and initialize its plugins list
054:             */
055:            private PluginManager() {
056:                this .availablePlugins = new HashMap();
057:                this .runningPlugins = new ArrayList();
058:            }
059:
060:            //-- plugin initialization & run
061:
062:            /**
063:             * Get a new plugin instance
064:             * 
065:             * @param name the plugin name
066:             * @param friends the connectinfos
067:             * @param starter true if the plugin is starter
068:             * @return a new plugin instance
069:             */
070:            public Plugin newPluginInstance(String name, ConnectInfo[] friends,
071:                    boolean starter) {
072:                Plugin base = (Plugin) this .availablePlugins.get(name);
073:                Plugin p = base.newInstance(friends);
074:                p.setStarter(starter);
075:                p.setName(base.getName());
076:                p.setLocale(Client.getInstance().getConfig().getLanguage());
077:
078:                return p;
079:            }
080:
081:            /**
082:             * Loads a Plugin.
083:             * Initialize it with the correct streams and run it in a new Thread
084:             * 
085:             * @param oc the ObjectConnection
086:             * @param message the message
087:             */
088:            public Plugin load(ObjectConnection oc, Message message) {
089:                String name = message.getApplication();
090:                Logging.getLogger().fine("Trying to load plugin " + name);
091:
092:                Plugin p = newPluginInstance(name, new ConnectInfo[0], false);
093:                p.setStarter(false);
094:                p.load(oc, message.getSender(), (String) message.getData());
095:                (new Thread(p, p.getName())).start();
096:                Logging.getLogger().info("Plugin " + name + " loaded.");
097:                return p;
098:            }
099:
100:            /**
101:             * Runs the requested Plugin in a new Thread
102:             * 
103:             * @param name the Plugin to run
104:             * @param friends the connexions associated with the plugin
105:             */
106:            public Plugin run(String name, ConnectInfo[] friends) {
107:                Logging.getLogger().fine("Trying to run plugin " + name);
108:                Plugin p = newPluginInstance(name, friends, true);
109:                p.setStarter(true);
110:                (new Thread(p, p.getName())).start();
111:                Logging.getLogger().fine("Plugin " + name + " started.");
112:
113:                return p;
114:            }
115:
116:            //-- available plugins
117:
118:            /**
119:             * Check if a Plugin is available
120:             * 
121:             * @param name the Plugin to check
122:             * @return true if the client has this Plugin
123:             */
124:            public boolean isAvailable(String name) {
125:                return this .isAvailable(name, "", false);
126:            }
127:
128:            /**
129:             * Check if a Plugin is available
130:             * 
131:             * @param name the Plugin to check
132:             * @param version the version to check
133:             * @return true if the Client has this version of the Plugin
134:             */
135:            public boolean isAvailable(String name, String version) {
136:                return isAvailable(name, version, false);
137:            }
138:
139:            /**
140:             * Check if a Plugin is available
141:             * 
142:             * @param name the Plugin to check
143:             * @param version the version to check
144:             * @param load trus if the PluginManager has to load the Plugin
145:             * @return true if the Client has this version of the Plugin
146:             */
147:            protected boolean isAvailable(String name, String version,
148:                    boolean load) {
149:                Plugin plugin;
150:                if (load == true) {
151:                    try {
152:                        LucaneClassLoader loader = LucaneClassLoader
153:                                .getInstance();
154:                        String baseURL = System.getProperty("user.dir") + "/"
155:                                + Client.APPLICATIONS_DIRECTORY;
156:                        String jarUrl = baseURL + name + ".jar";
157:                        URL url = new URL("jar:file:///" + jarUrl + "!/");
158:                        loader.addUrl(url);
159:                        Logging.getLogger().fine("plugin URL: " + url);
160:
161:                        //we have to set our ClassLoader to reload the plugin.
162:                        String className = JarUtils.getPluginClass(jarUrl);
163:                        Logging.getLogger().finer("classname: " + className);
164:
165:                        plugin = (Plugin) Class
166:                                .forName(className, true, loader).newInstance();
167:                        plugin.setName(name);
168:                        plugin.setLocale(Client.getInstance().getConfig()
169:                                .getLanguage());
170:                        this .availablePlugins.put(plugin.getName(), plugin);
171:                        Logging.getLogger().info(
172:                                "Loaded plugin " + plugin.getName() + " v. "
173:                                        + plugin.getVersion());
174:                    } catch (Exception e) {
175:                        return false;
176:                    }
177:                }
178:
179:                plugin = (Plugin) this .availablePlugins.get(name);
180:                return plugin != null
181:                        && (plugin.getVersion().equals(version) || version
182:                                .length() == 0);
183:            }
184:
185:            /**
186:             * Get all available plugins
187:             * 
188:             * @return an iterator
189:             */
190:            public Iterator getAvailablePlugins() {
191:                return this .availablePlugins.values().iterator();
192:            }
193:
194:            /**
195:             * Get a plugin by its name
196:             * 
197:             * @param name the plugin name
198:             * @return the corresponding Plugin
199:             */
200:            public Plugin getPlugin(String name) {
201:                return (Plugin) this .availablePlugins.get(name);
202:            }
203:
204:            //-- running plugins
205:
206:            /**
207:             * Tells the client that a plugin has been launched.
208:             */
209:            protected void addRunningPlugin(Plugin p) {
210:                Logging.getLogger().fine("registering : " + p.getName());
211:                this .runningPlugins.add(p);
212:            }
213:
214:            /**
215:             * Tells a client that a plugin has been closed.
216:             */
217:            protected void removeRunningPlugin(Plugin p) {
218:                Logging.getLogger().fine("unregistering : " + p.getName());
219:                this .runningPlugins.remove(p);
220:
221:                //if no more plugins are running, or if we quit the startup plugin,
222:                //exits the client cleanly
223:                if (runningPlugins.isEmpty()
224:                        || p.getName().equals(
225:                                Client.getInstance().getStartupPlugin()))
226:                    Client.getInstance().cleanExit();
227:            }
228:
229:            /**
230:             * Get plugins that are currently running
231:             * 
232:             * @return an iterator containing active plugins
233:             */
234:            public Iterator getRunningPlugins() {
235:                return runningPlugins.iterator();
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.