|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.carbide.cpp.internal.pi.manager; |
|
19 |
|
20 import org.eclipse.core.runtime.CoreException; |
|
21 import org.eclipse.core.runtime.IConfigurationElement; |
|
22 import org.eclipse.core.runtime.IExtension; |
|
23 import org.eclipse.core.runtime.IExtensionPoint; |
|
24 import org.eclipse.core.runtime.IExtensionRegistry; |
|
25 import org.eclipse.core.runtime.Platform; |
|
26 import org.osgi.framework.Bundle; |
|
27 |
|
28 import com.nokia.carbide.cpp.internal.pi.interfaces.IReturnPlugin; |
|
29 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin; |
|
30 import com.nokia.carbide.cpp.pi.PiPlugin; |
|
31 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
|
32 |
|
33 |
|
34 |
|
35 public class PluginRegisterer |
|
36 { |
|
37 private static final String extensionName = "com.nokia.carbide.cpp.pi.piPluginData"; //$NON-NLS-1$ |
|
38 |
|
39 private static boolean alreadyRegistered = false; |
|
40 |
|
41 public PluginRegisterer() |
|
42 { |
|
43 } |
|
44 |
|
45 public static void registerAllPlugins() |
|
46 { |
|
47 if (alreadyRegistered) |
|
48 return; |
|
49 |
|
50 // start all PI plugins that have their dependencies resolved |
|
51 if (!PIPageEditor.arePluginsStarted()) { |
|
52 PIPageEditor.startPlugins(); |
|
53 |
|
54 Bundle[] bundles = PiPlugin.getDefault().getBundle().getBundleContext().getBundles(); |
|
55 for (int i = 0; i < bundles.length; i++) { |
|
56 Bundle bundle = bundles[i]; |
|
57 if (bundle.getSymbolicName().matches(".*com\\.nokia\\.carbide\\.cpp\\.pi\\..*")) { //$NON-NLS-1$ |
|
58 int state = bundle.getState(); |
|
59 if (state == Bundle.RESOLVED) |
|
60 try { |
|
61 bundle.start(Bundle.START_TRANSIENT); |
|
62 } catch (Exception ex) { |
|
63 } |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 IExtensionRegistry registry = Platform.getExtensionRegistry(); |
|
69 IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionName); |
|
70 |
|
71 if (extensionPoint == null) |
|
72 return; |
|
73 |
|
74 IExtension[] extensions = extensionPoint.getExtensions(); |
|
75 // For each extension ... |
|
76 for (int i = 0; i < extensions.length; i++) { |
|
77 IExtension extension = extensions[i]; |
|
78 IConfigurationElement[] elements = extension.getConfigurationElements(); |
|
79 // For each member of the extension ... |
|
80 if (elements != null && elements.length >= 1) { |
|
81 IConfigurationElement element = elements[0]; |
|
82 AbstractPiPlugin plugin; |
|
83 IReturnPlugin getPlugin; |
|
84 try { |
|
85 getPlugin = (IReturnPlugin) element.createExecutableExtension("pluginClass"); //$NON-NLS-1$ |
|
86 plugin = getPlugin.getPlugin(); |
|
87 PluginRegistry.getInstance().addRegistryEntry(plugin); |
|
88 } catch (CoreException e) { |
|
89 e.printStackTrace(); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 alreadyRegistered = true; |
|
95 } |
|
96 } |