Project

General

Profile

Download (2.15 KB) Statistics
| Branch: | Tag: | Revision:
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.service.packageadmin.PackageAdmin;
9

    
10
import eu.etaxonomy.taxeditor.model.MessagingUtils;
11

    
12
/**
13
 * The activator class controls the plug-in life cycle
14
 *
15
 * @author n.hoffmann
16
 * @version $Id: $
17
 */
18
public class TaxonomicEditorPlugin extends AbstractUIPlugin {
19
	private static final Logger logger = Logger
20
			.getLogger(TaxonomicEditorPlugin.class);
21

    
22
	// The plug-in ID
23
	public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
24

    
25
	// The shared instance
26
	private static TaxonomicEditorPlugin plugin;
27

    
28
	private PackageAdmin packageAdmin;
29

    
30
	private ServiceReference packageAdminRef;
31

    
32
	protected static BundleContext bundleContext;
33

    
34

    
35
	public TaxonomicEditorPlugin() {
36
	}
37

    
38
	@Override
39
    public void start(BundleContext context) throws Exception {
40
		super.start(context);
41

    
42
		plugin = this;
43
		bundleContext = context;
44

    
45
		packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
46
		packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
47

    
48
		logger.debug("Taxonomic Editor started.");
49
	}
50

    
51
	private Bundle getBundle(String symbolicName) {
52
		if (packageAdmin == null) {
53
            return null;
54
        }
55
		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
56
		if (bundles == null) {
57
            return null;
58
        }
59
		// Return the first bundle that is not installed or uninstalled
60
		for (int i = 0; i < bundles.length; i++) {
61
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
62
				return bundles[i];
63
			}
64
		}
65
		return null;
66
	}
67

    
68
	/** {@inheritDoc} */
69
	@Override
70
	public void stop(BundleContext context) throws Exception {
71
	    plugin = null;
72
	    super.stop(context);
73
	    MessagingUtils.info("Taxonomic Editor stopped.");
74
	}
75

    
76
	/**
77
	 * Returns the shared instance
78
	 *
79
	 * @return the shared instance
80
	 */
81
	public static TaxonomicEditorPlugin getDefault() {
82
	    return plugin;
83
	}
84

    
85
	public static BundleContext getContext() {
86
	    return bundleContext;
87
	}
88

    
89
}
(7-7/7)