KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > compatibility > PluginActivator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.compatibility;
12
13 import org.eclipse.core.internal.plugins.PluginDescriptor;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.core.runtime.Plugin;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18
19 public class PluginActivator implements BundleActivator {
20     private Plugin plugin;
21
22     public PluginActivator() {
23         super();
24     }
25
26     public void start(BundleContext context) throws Exception JavaDoc {
27         PluginDescriptor pd = (PluginDescriptor) Platform.getPluginRegistry().getPluginDescriptor(context.getBundle().getSymbolicName());
28         plugin = pd.getPlugin();
29         try {
30             plugin.start(context);
31             plugin.startup();
32         } catch(Exception JavaDoc e) {
33             try {
34                 plugin.shutdown();
35                 plugin.stop(context);
36                 pd.markAsDeactivated();
37             } catch(Exception JavaDoc e1) {
38                 // We are mostly interested in the original exception
39
e1.printStackTrace();
40             }
41             throw e;
42         }
43     }
44
45     public void stop(BundleContext context) throws Exception JavaDoc {
46         plugin.shutdown();
47         plugin.stop(context);
48         ((PluginDescriptor) plugin.getDescriptor()).doPluginDeactivation();
49     }
50 }
51
Popular Tags