Source Code Cross Referenced for PluginRegistry.java in  » Content-Management-System » contineo » org » contineo » util » 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 » Content Management System » contineo » org.contineo.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.util;
002:
003:        import java.io.File;
004:        import java.io.FilenameFilter;
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:        import java.util.Arrays;
008:        import java.util.Collection;
009:        import java.util.Iterator;
010:        import java.util.LinkedList;
011:        import java.util.List;
012:        import java.util.Map;
013:
014:        import org.apache.commons.lang.StringUtils;
015:        import org.java.plugin.JpfException;
016:        import org.java.plugin.ObjectFactory;
017:        import org.java.plugin.PluginManager;
018:        import org.java.plugin.registry.Extension;
019:        import org.java.plugin.registry.ExtensionPoint;
020:        import org.java.plugin.registry.Identity;
021:        import org.java.plugin.registry.PluginDescriptor;
022:        import org.java.plugin.util.ExtendedProperties;
023:
024:        /**
025:         * Central point where plugins are loaded and handled. The class is abstract and
026:         * must be personalized as needed. The used implementation can be specified with
027:         * the 'contineo.app.pluginregistry' system property.
028:         * 
029:         * @author Marco Meschieri
030:         * @version $Id$
031:         * @since 3.0
032:         */
033:        public abstract class PluginRegistry {
034:
035:            // System property containing the plugin registry implementation to be used
036:            public static final String CONTINEO_APP_PLUGINREGISTRY = "contineo.app.pluginregistry";
037:
038:            protected PluginManager manager = null;
039:
040:            private static PluginRegistry instance;
041:
042:            public static PluginRegistry getInstance() {
043:                if (instance == null) {
044:                    String pluginregistry = System
045:                            .getProperty(CONTINEO_APP_PLUGINREGISTRY);
046:                    if (StringUtils.isEmpty(pluginregistry)) {
047:                        pluginregistry = "org.contineo.DefaultPluginRegistry";
048:                    }
049:                    try {
050:                        System.out
051:                                .println("Instantiate concrete PluginRegistry: "
052:                                        + pluginregistry);
053:                        instance = (PluginRegistry) Class.forName(
054:                                pluginregistry).newInstance();
055:                    } catch (Exception e) {
056:                        e.printStackTrace();
057:                    }
058:                }
059:                return instance;
060:            }
061:
062:            /**
063:             * Initializes all found plugins
064:             */
065:            public void init() {
066:                ExtendedProperties properties = new ExtendedProperties();
067:                properties.put("org.java.plugin.PathResolver",
068:                        "org.java.plugin.standard.ShadingPathResolver");
069:                properties
070:                        .put(
071:                                "org.java.plugin.standard.ShadingPathResolver.shadowFolder",
072:                                System.getProperty("contineo.app.pluginsdir")
073:                                        + "/../.plugins");
074:                properties
075:                        .put(
076:                                "org.java.plugin.standard.ShadingPathResolver.unpackMode",
077:                                "always");
078:
079:                ObjectFactory pluginObjectFactory = ObjectFactory
080:                        .newInstance(properties);
081:                manager = pluginObjectFactory.createManager();
082:
083:                List<PluginManager.PluginLocation> pluginLocations = locatePlugins(System
084:                        .getProperty("contineo.app.pluginsdir"));
085:
086:                if (pluginLocations.size() > 0) {
087:                    Map<String, Identity> plugins = null;
088:                    try {
089:                        PluginManager.PluginLocation[] pLocations = (PluginManager.PluginLocation[]) pluginLocations
090:                                .toArray(new PluginManager.PluginLocation[0]);
091:                        plugins = manager.publishPlugins(pLocations);
092:                    } catch (JpfException e) {
093:                        throw new RuntimeException("Error publishing plugins",
094:                                e);
095:                    }
096:
097:                    System.out.println("Succesfully registered "
098:                            + plugins.size() + " plugins");
099:                    initPlugins(plugins);
100:                }
101:            }
102:
103:            /**
104:             * Initializes found plugins
105:             * 
106:             * @param plugins Map of found plugins
107:             */
108:            protected abstract void initPlugins(Map<String, Identity> plugins);
109:
110:            protected List<PluginManager.PluginLocation> locatePlugins(
111:                    String pluginsDirectoryPath) {
112:
113:                List<PluginManager.PluginLocation> pluginLocations = new LinkedList<PluginManager.PluginLocation>();
114:
115:                // look for all zip files in plugin directory
116:                File pluginDirectory = new File(pluginsDirectoryPath);
117:
118:                System.out.println("Searching for plugins in "
119:                        + pluginDirectory.getAbsolutePath());
120:
121:                FilenameFilter filter = new FilenameFilter() {
122:                    public boolean accept(File dir, String name) {
123:                        return (name.endsWith(".zip"));
124:                    }
125:                };
126:
127:                if (pluginDirectory.isDirectory()) {
128:
129:                    // find the plugins
130:                    List<String> pluginsList = Arrays.asList(pluginDirectory
131:                            .list(filter));
132:
133:                    if (pluginsList.size() > 0) {
134:
135:                        Iterator<String> i = pluginsList.iterator();
136:
137:                        while (i.hasNext()) {
138:
139:                            String pluginFilename = (String) i.next();
140:
141:                            File pluginZIPFile = new File(pluginDirectory
142:                                    .getPath()
143:                                    + "/" + pluginFilename);
144:
145:                            if (!pluginZIPFile.exists())
146:                                throw new RuntimeException("file not Found:"
147:                                        + pluginZIPFile.getAbsolutePath());
148:
149:                            try {
150:
151:                                final URL manifestURL = new URL("jar:file:"
152:                                        + pluginZIPFile.getAbsolutePath()
153:                                        + "!/plugin.xml");
154:
155:                                final URL contextURL = pluginZIPFile.toURL();
156:
157:                                System.out.println("Found plugin file: "
158:                                        + pluginZIPFile.getName());
159:
160:                                pluginLocations
161:                                        .add(new PluginManager.PluginLocation() {
162:                                            public URL getManifestLocation() {
163:                                                return manifestURL;
164:                                            }
165:
166:                                            public URL getContextLocation() {
167:                                                return contextURL;
168:                                            }
169:                                        });
170:                            } catch (MalformedURLException e) {
171:                                e.printStackTrace();
172:                            }
173:                        }
174:                    } else {
175:                        System.out.println("No Plugins Found");
176:                    }
177:
178:                } else {
179:                    throw new RuntimeException(
180:                            "Unable to access Plugins directory: "
181:                                    + pluginDirectory.getAbsolutePath());
182:                }
183:                return pluginLocations;
184:            }
185:
186:            public PluginManager getManager() {
187:                return manager;
188:            }
189:
190:            /**
191:             * Returns the extensions connected to the specified extension point
192:             * 
193:             * @param pluginId The plugin identifier
194:             * @param extensionPoint The extension point id
195:             * @return List of connected extensions
196:             */
197:            public Collection<Extension> getExtensions(String pluginId,
198:                    String extensionPoint) {
199:                PluginRegistry registry = PluginRegistry.getInstance();
200:                PluginDescriptor descriptor = registry.getManager()
201:                        .getRegistry().getPluginDescriptor(pluginId);
202:                ExtensionPoint dbinitExtPoint = registry.getManager()
203:                        .getRegistry().getExtensionPoint(descriptor.getId(),
204:                                extensionPoint);
205:                Collection<Extension> exts = dbinitExtPoint
206:                        .getConnectedExtensions();
207:                return exts;
208:            }
209:
210:            /**
211:             * Retrieves the list of registered plugins
212:             * 
213:             * @return The list of registered plugins descriptors
214:             */
215:            public Collection<PluginDescriptor> getPlugins() {
216:                PluginRegistry registry = PluginRegistry.getInstance();
217:                return registry.getManager().getRegistry()
218:                        .getPluginDescriptors();
219:            }
220:
221:            /**
222:             * Retrieve the plugin descriptor
223:             * 
224:             * @return The plugin descriptor
225:             */
226:            public PluginDescriptor getPlugin(String pluginId) {
227:                PluginRegistry registry = PluginRegistry.getInstance();
228:                return registry.getManager().getRegistry().getPluginDescriptor(
229:                        pluginId);
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.