blob: 82f3444a23d62340fadb2c40134f67a72b3a5f56 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2009 Borland Software Corporation and others.
*
* 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:
* Borland Software Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.ResourceLocator;
/**
* The main plugin class to be used in the desktop.
*/
public class QvtPlugin extends EMFPlugin {
public static final String ID = "org.eclipse.m2m.qvt.oml"; //$NON-NLS-1$
/**
* The singleton instance of the plugin.
*/
public static final QvtPlugin INSTANCE = new QvtPlugin();
private static Implementation plugin;
/**
* The constructor.
*/
public QvtPlugin() {
super(new ResourceLocator[] {});
}
@Override
public ResourceLocator getPluginResourceLocator() {
return plugin;
}
static public class Implementation extends EclipsePlugin {
public Implementation() {
super();
plugin = this;
}
}
/**
* Returns the shared instance.
*/
public static QvtPlugin getDefault() {
return INSTANCE;
}
public static Implementation getPlugin() {
return plugin;
}
/**
* Generates an error log for the specified plug-in, with the specified
* status code, message.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
*
*/
public static void error(int code, String message) {
error(code, message, null);
}
/**
* Generates an error log for the specified plug-in, with the specified
* status code, message, and throwable.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
* @param throwable
* The throwable for the log.
*
*/
public static void error(int code, String message, Throwable throwable) {
log(Diagnostic.ERROR, code, message, throwable);
}
public static void error(String message, Throwable throwable) {
error(0, message, throwable);
}
public static void error(Throwable throwable) {
error("", throwable); //$NON-NLS-1$
}
public static void error(String message) {
error(0, message, null);
}
/**
* Generates an information log for the specified plug-in, with the
* specified status code, message.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
*
*/
public static void info(int code, String message) {
info(code, message, null);
}
/**
* Generates an information log for the specified plug-in, with the
* specified status code, message, and throwable.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
* @param throwable
* The throwable for the log.
*
*/
public static void info(int code, String message, Throwable throwable) {
log(Diagnostic.INFO, code, message, throwable);
}
/**
* Generates a warning log for the specified plug-in, with the specified
* status code, message.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
*
*/
public static void warning(int code, String message) {
warning(code, message, null);
}
/**
* Generates a warning log for the specified plug-in, with the specified
* status code, message, and throwable.
*
* @param code
* The status code for the log.
* @param message
* The message for the log.
* @param throwable
* The throwable for the log.
*
*/
public static void warning(int code, String message, Throwable throwable) {
log(Diagnostic.WARNING, code, message, throwable);
}
public static void logDiagnostic(Diagnostic diagnostic) {
if(getPlugin() != null) {
getPlugin().log(BasicDiagnostic.toIStatus(diagnostic));
} else {
getDefault().log(diagnostic);
}
}
public static void log(int severity, int code, String message, Throwable throwable) {
//
// Status ctor requires a non-null message
String msg = message == null
? "" //$NON-NLS-1$
: message;
try {
if (getPlugin() != null) {
// Eclipse environment
getPlugin().log(
new Status(severity, ID, code, msg, throwable));
} else {
// not in the Eclipse environment
//if (shouldTrace()) {
switch (code) {
case Diagnostic.WARNING :
System.err.print("WARNING "); //$NON-NLS-1$
break;
case Diagnostic.ERROR :
case Diagnostic.CANCEL :
System.err.print("ERROR "); //$NON-NLS-1$
break;
default :
// don't output INFO or OK messages
return;
}
System.err.print(code);
System.err.print(": "); //$NON-NLS-1$
System.err.println(message);
if (throwable != null) {
throwable.printStackTrace(System.err);
}
//}
}
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
public static BasicDiagnostic createDiagnostic(String message) {
return new BasicDiagnostic(Diagnostic.OK, ID, 0, message, null);
}
public static Diagnostic createErrorDiagnostic(String message, Throwable throwable) {
Object[] data = (throwable == null) ? null : new Object [] { throwable };
return new BasicDiagnostic(Diagnostic.ERROR, ID, 0, message, data);
}
public static Diagnostic createWarnDiagnostic(String message) {
return new BasicDiagnostic(Diagnostic.ERROR, ID, 0, message, null);
}
/**
* Indicates that the given diagnostic is neither error or canceled.
*
* @param diagnostic
* the diagnostic to test
* @return <code>true</code> in case of success, <code>false</code>
* otherwise
*/
public static boolean isSuccess(Diagnostic diagnostic) {
int severity = diagnostic.getSeverity();
return severity != Diagnostic.ERROR && severity != Diagnostic.CANCEL;
}
}