01: package gui;
02:
03: import java.io.InputStream;
04: import java.net.URL;
05: import java.util.Properties;
06:
07: import logging.LoggingPlugin;
08: import logging.PluginLogManager;
09:
10: import org.eclipse.core.runtime.IStatus;
11: import org.eclipse.core.runtime.Status;
12: import org.eclipse.ui.plugin.AbstractUIPlugin;
13: import org.osgi.framework.BundleContext;
14:
15: /** <p>The main plugin class for the generator plugin.</p>
16: *
17: * @author The mighty PDE wizard
18: */
19: public class RefactoringPlugin extends AbstractUIPlugin {
20:
21: private static final String LOG_PROPERTIES_FILE = "log4j.properties";
22:
23: //The shared instance.
24: private static RefactoringPlugin plugin;
25: private PluginLogManager logManager;
26:
27: public RefactoringPlugin() {
28: super ();
29: plugin = this ;
30: }
31:
32: public static PluginLogManager getLogManager() {
33: return getDefault().logManager;
34: }
35:
36: /**
37: * This method is called upon plug-in activation
38: */
39: public void start(BundleContext context) throws Exception {
40: super .start(context);
41: configure();
42: }
43:
44: /**
45: * This method is called when the plug-in is stopped
46: */
47: public void stop(BundleContext context) throws Exception {
48: super .stop(context);
49: if (this .logManager != null) {
50: this .logManager.shutdown();
51: this .logManager = null;
52: }
53: }
54:
55: public static RefactoringPlugin getDefault() {
56: return plugin;
57: }
58:
59: public static String getPluginId() {
60: return getDefault().getBundle().getSymbolicName();
61: }
62:
63: private void configure() {
64: try {
65: URL url = getBundle().getEntry("/" + LOG_PROPERTIES_FILE);
66: InputStream propertiesInputStream = url.openStream();
67: if (propertiesInputStream != null) {
68: Properties props = new Properties();
69: props.load(propertiesInputStream);
70: propertiesInputStream.close();
71: this .logManager = new PluginLogManager(this , props);
72:
73: this .logManager.hookPlugin(LoggingPlugin.getDefault()
74: .getBundle().getSymbolicName(), LoggingPlugin
75: .getDefault().getLog());
76: }
77: } catch (Exception e) {
78: String message = "Error while initializing log properties."
79: + e.getMessage();
80: IStatus status = new Status(IStatus.ERROR, getDefault()
81: .getBundle().getSymbolicName(), IStatus.ERROR,
82: message, e);
83: getLog().log(status);
84: throw new RuntimeException(
85: "Error while initializing log properties.", e);
86: }
87: }
88: }
|