57041a0e7b4bf08f07ee6d86934daad2bbae379a
[taxeditor.git] / taxeditor-application / src / main / java / eu / etaxonomy / taxeditor / TaxonomicEditorPlugin.java
1 package eu.etaxonomy.taxeditor;
2
3 import org.apache.log4j.Logger;
4 import org.eclipse.ui.plugin.AbstractUIPlugin;
5 import org.osgi.framework.Bundle;
6 import org.osgi.framework.BundleContext;
7 import org.osgi.framework.ServiceReference;
8 import org.osgi.framework.ServiceRegistration;
9 import org.osgi.service.packageadmin.PackageAdmin;
10
11 /**
12 * The activator class controls the plug-in life cycle
13 */
14 public class TaxonomicEditorPlugin extends AbstractUIPlugin {
15 private static final Logger logger = Logger
16 .getLogger(TaxonomicEditorPlugin.class);
17
18 // The plug-in ID
19 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
20
21 // The shared instance
22 private static TaxonomicEditorPlugin plugin;
23
24 private PackageAdmin packageAdmin;
25
26 private ServiceReference packageAdminRef;
27
28 protected static BundleContext bundleContext;
29
30
31 private ServiceRegistration policyRegistration;
32
33 // private CloudPolicy policy;
34
35 /**
36 * The constructor
37 */
38 public TaxonomicEditorPlugin() {
39 }
40
41 /*
42 * (non-Javadoc)
43 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
44 */
45 public void start(BundleContext context) throws Exception {
46 super.start(context);
47
48 plugin = this;
49 bundleContext = context;
50
51 packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
52 packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
53
54 logger.debug("Taxonomic Editor started.");
55 }
56
57 private Bundle getBundle(String symbolicName) {
58 if (packageAdmin == null)
59 return null;
60 Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
61 if (bundles == null)
62 return null;
63 // Return the first bundle that is not installed or uninstalled
64 for (int i = 0; i < bundles.length; i++) {
65 if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
66 return bundles[i];
67 }
68 }
69 return null;
70 }
71
72 /*
73 * (non-Javadoc)
74 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
75 */
76 public void stop(BundleContext context) throws Exception {
77 plugin = null;
78 super.stop(context);
79 ApplicationUtil.info("Taxonomic Editor stopped.");
80 }
81
82 /**
83 * Returns the shared instance
84 *
85 * @return the shared instance
86 */
87 public static TaxonomicEditorPlugin getDefault() {
88 return plugin;
89 }
90
91
92
93 }