001: package net.refractions.udig.catalog.internal.gml;
002:
003: import java.util.MissingResourceException;
004: import java.util.ResourceBundle;
005:
006: import org.eclipse.core.runtime.IStatus;
007: import org.eclipse.core.runtime.Platform;
008: import org.eclipse.core.runtime.Plugin;
009: import org.eclipse.core.runtime.Status;
010: import org.osgi.framework.BundleContext;
011:
012: /**
013: * The main plugin class to be used in the desktop.
014: */
015: public class GmlPlugin extends Plugin {
016: //The shared instance.
017: private static GmlPlugin plugin;
018: //Resource bundle.
019: private ResourceBundle resourceBundle;
020:
021: public final static String ID = "net.refractions.udig.catalog.gml"; //$NON-NLS-1$
022:
023: /**
024: * The constructor.
025: */
026: public GmlPlugin() {
027: super ();
028: plugin = this ;
029: }
030:
031: /**
032: * This method is called upon plug-in activation
033: */
034: public void start(BundleContext context) throws Exception {
035: super .start(context);
036: }
037:
038: /**
039: * This method is called when the plug-in is stopped
040: */
041: public void stop(BundleContext context) throws Exception {
042: plugin = null;
043: resourceBundle = null;
044: super .stop(context);
045: }
046:
047: /**
048: * Returns the shared instance.
049: */
050: public static GmlPlugin getDefault() {
051: return plugin;
052: }
053:
054: /**
055: * Returns the string from the plugin's resource bundle,
056: * or 'key' if not found.
057: */
058: public static String getResourceString(String key) {
059: ResourceBundle bundle = GmlPlugin.getDefault()
060: .getResourceBundle();
061: try {
062: return (bundle != null) ? bundle.getString(key) : key;
063: } catch (MissingResourceException e) {
064: return key;
065: }
066: }
067:
068: /**
069: * Returns the plugin's resource bundle,
070: */
071: public ResourceBundle getResourceBundle() {
072: try {
073: if (resourceBundle == null)
074: resourceBundle = ResourceBundle
075: .getBundle("net.refractions.udig.catalog.gml.GmlPluginResources"); //$NON-NLS-1$
076: } catch (MissingResourceException x) {
077: resourceBundle = null;
078: }
079: return resourceBundle;
080: }
081:
082: /**
083: * Logs the Throwable in the plugin's log.
084: * <p>
085: * This will be a user visable ERROR iff:
086: * <ul>
087: * <li>t is an Exception we are assuming it is human readable or if a message is provided
088: * </ul>
089: * </p>
090: * @param message
091: * @param t
092: */
093: public static void log(String message, Throwable t) {
094: int status = t instanceof Exception || message != null ? IStatus.ERROR
095: : IStatus.WARNING;
096: getDefault().getLog().log(
097: new Status(status, ID, IStatus.OK, message, t));
098: }
099:
100: /**
101: * Messages that only engage if getDefault().isDebugging()
102: * <p>
103: * It is much prefered to do this:<pre><code>
104: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
105: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
106: * System.out.println( "your message here" );
107: * }
108: * </code></pre>
109: * </p>
110: * @param message
111: * @param e
112: */
113: public static void trace(String message, Throwable e) {
114: if (getDefault().isDebugging()) {
115: if (message != null)
116: System.out.println(message);
117: if (e != null)
118: e.printStackTrace();
119: }
120: }
121:
122: /**
123: * Performs the Platform.getDebugOption true check on the provided trace
124: * <p>
125: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
126: * <ul>
127: * <li>Trace.RENDER - trace rendering progress
128: * </ul>
129: * </p>
130: * @param trace currently only RENDER is defined
131: * @return true if -debug is on for this plugin
132: */
133: public static boolean isDebugging(final String trace) {
134: return getDefault().isDebugging()
135: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
136: }
137: }
|