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