Project

General

Profile

Download (2.48 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.framework.ServiceRegistration;
9
import org.osgi.service.packageadmin.PackageAdmin;
10

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

    
21
	// The plug-in ID
22
	/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
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
	/** Constant <code>bundleContext</code> */
33
	protected static BundleContext bundleContext;
34

    
35

    
36
	private ServiceRegistration policyRegistration;
37

    
38
//	private CloudPolicy policy;
39
	
40
	/**
41
	 * The constructor
42
	 */
43
	public TaxonomicEditorPlugin() {
44
	}
45

    
46
	/*
47
	 * (non-Javadoc)
48
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
49
	 */
50
	/** {@inheritDoc} */
51
	public void start(BundleContext context) throws Exception {
52
		super.start(context);
53
		
54
		plugin = this;
55
		bundleContext = context;
56
		
57
		packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
58
		packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
59
		
60
		logger.debug("Taxonomic Editor started.");
61
	}
62

    
63
	private Bundle getBundle(String symbolicName) {
64
		if (packageAdmin == null)
65
			return null;
66
		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
67
		if (bundles == null)
68
			return null;
69
		// Return the first bundle that is not installed or uninstalled
70
		for (int i = 0; i < bundles.length; i++) {
71
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
72
				return bundles[i];
73
			}
74
		}
75
		return null;
76
	}
77
	
78
	/*
79
	 * (non-Javadoc)
80
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
81
	 */
82
	/** {@inheritDoc} */
83
	public void stop(BundleContext context) throws Exception {
84
		plugin = null;
85
		super.stop(context);
86
		ApplicationUtil.info("Taxonomic Editor stopped.");
87
	}
88

    
89
	/**
90
	 * Returns the shared instance
91
	 *
92
	 * @return the shared instance
93
	 */
94
	public static TaxonomicEditorPlugin getDefault() {
95
		return plugin;
96
	}
97
	
98
	
99
	
100
}
(13-13/13)