KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > MapperPlugin


1 package org.hibernate.eclipse.mapper;
2
3 import java.util.MissingResourceException JavaDoc;
4 import java.util.ResourceBundle JavaDoc;
5
6 import org.eclipse.ui.plugin.AbstractUIPlugin;
7 import org.hibernate.eclipse.EclipseLogger;
8 import org.osgi.framework.BundleContext;
9
10 /**
11  * The main plugin class to be used in the desktop.
12  */

13 public class MapperPlugin extends AbstractUIPlugin {
14     
15     final public static String JavaDoc ID = MapperPlugin.class.getName();
16     
17     //The shared instance.
18
private static MapperPlugin plugin;
19     //Resource bundle.
20
private ResourceBundle JavaDoc resourceBundle;
21     
22     private final EclipseLogger logger = new EclipseLogger(ID);
23     
24     /**
25      * The constructor.
26      */

27     public MapperPlugin() {
28         super();
29         plugin = this;
30     }
31
32     /**
33      * This method is called upon plug-in activation
34      */

35     public void start(BundleContext context) throws Exception JavaDoc {
36         super.start(context);
37     }
38
39     /**
40      * This method is called when the plug-in is stopped
41      */

42     public void stop(BundleContext context) throws Exception JavaDoc {
43         super.stop(context);
44         plugin = null;
45         resourceBundle = null;
46     }
47
48     /**
49      * Returns the shared instance.
50      */

51     public static MapperPlugin getDefault() {
52         return plugin;
53     }
54     
55     public EclipseLogger getLogger() {
56         return logger;
57     }
58
59     /**
60      * Returns the string from the plugin's resource bundle,
61      * or 'key' if not found.
62      */

63     public static String JavaDoc getResourceString(String JavaDoc key) {
64         ResourceBundle JavaDoc bundle = MapperPlugin.getDefault().getResourceBundle();
65         try {
66             return (bundle != null) ? bundle.getString(key) : key;
67         } catch (MissingResourceException JavaDoc e) {
68             return key;
69         }
70     }
71
72     /**
73      * Returns the plugin's resource bundle,
74      */

75     public ResourceBundle JavaDoc getResourceBundle() {
76         try {
77             if (resourceBundle == null)
78                 resourceBundle = ResourceBundle.getBundle("org.hibernate.eclipse.mapper.MapperPluginResources");
79         } catch (MissingResourceException JavaDoc x) {
80             resourceBundle = null;
81         }
82         return resourceBundle;
83     }
84
85     public void logException(Throwable JavaDoc exception) {
86         getLogger().logException(exception);
87     }
88 }
89
Popular Tags