/*******************************************************************************
* Copyright (c) 2007 Spring IDE Developers
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Spring IDE Developers - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.aop.ui.matcher;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* OSGi Bundle Activator for the Pointcut Matcher Plugin.
* @author Christian Dupuis
* @since 2.0.2
*/
public class PointcutMatcherPlugin extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.springframework.ide.eclipse.aop.ui.matcher";
private static final String RESOURCE_NAME = PLUGIN_ID + ".messages";
private static PointcutMatcherPlugin plugin;
private ResourceBundle resourceBundle;
public PointcutMatcherPlugin() {
plugin = this;
try {
resourceBundle = ResourceBundle.getBundle(RESOURCE_NAME);
}
catch (MissingResourceException e) {
log(e);
resourceBundle = null;
}
}
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
public static IStatus createErrorStatus(String message, Throwable exception) {
if (message == null) {
message = "";
}
return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception);
}
public static PointcutMatcherPlugin getDefault() {
return plugin;
}
public static String getResourceString(String key) {
String bundleString;
ResourceBundle bundle = getDefault().getResourceBundle();
if (bundle != null) {
try {
bundleString = bundle.getString(key);
}
catch (MissingResourceException e) {
log(e);
bundleString = "!" + key + "!";
}
}
else {
bundleString = "!" + key + "!";
}
return bundleString;
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
public static void log(String message, Throwable exception) {
IStatus status = createErrorStatus(message, exception);
getDefault().getLog().log(status);
}
public static void log(Throwable exception) {
getDefault().getLog().log(
createErrorStatus(getResourceString("Plugin.internal_error"),
exception));
}
}