Skip to content
Snippets Groups Projects
Commit 0c7a350a authored by Florian Hölzl's avatar Florian Hölzl
Browse files

bugfix #97: improved LoggingUtils interface

parent be4dac0b
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,6 @@ package org.fortiss.tooling.kernel.ui.internal;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
......@@ -54,18 +53,17 @@ public class EditPartFactoryService extends
public EditPart createEditPart(EditPart context, Object modelElement) {
if (!(modelElement instanceof EObject)) {
LoggingUtils.log(ToolingKernelUIActivator.getDefault(),
LoggingUtils.error(ToolingKernelUIActivator.getDefault(),
EditPartFactoryService.class.getSimpleName()
+ " may only be used for EObjects!", IStatus.ERROR);
+ " may only be used for EObjects!");
return null;
}
Class<? extends EObject> clazz = ((EObject) modelElement).getClass();
List<IEditPartFactory<EObject>> factories = getRegisteredHandlers(clazz);
if (factories == null || factories.isEmpty()) {
LoggingUtils.log(ToolingKernelUIActivator.getDefault(),
"No editpart factory registered for " + clazz.getName(),
IStatus.ERROR);
LoggingUtils.error(ToolingKernelUIActivator.getDefault(),
"No editpart factory registered for " + clazz.getName());
return null;
}
......
......@@ -19,7 +19,6 @@ package org.fortiss.tooling.kernel.ui.internal;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
......@@ -59,9 +58,9 @@ public class ModelElementHandlerService extends
Class<? extends EObject> clazz = modelElement.getClass();
List<IModelElementHandler<EObject>> handlerList = getRegisteredHandlers(clazz);
if (handlerList == null || handlerList.isEmpty()) {
LoggingUtils.log(ToolingKernelActivator.getDefault(), "ERROR: "
LoggingUtils.error(ToolingKernelActivator.getDefault(), "ERROR: "
+ modelElement.getClass().getName()
+ " does not have a registered handler!", IStatus.ERROR);
+ " does not have a registered handler!");
return null;
}
return handlerList.get(0);
......
......@@ -19,7 +19,6 @@ package org.fortiss.tooling.kernel.internal.storage.eclipse;
import java.util.Collection;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.transaction.RecordingCommand;
......@@ -39,7 +38,7 @@ import org.fortiss.tooling.kernel.util.LoggingUtils;
* @author hummel
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 033E90E46FF2E736A09F2FEBD2365AF1
* @ConQAT.Rating YELLOW Hash: 6AF9B849FA94FE28EEAE8F998B9511F0
*/
public class EMFTransactionalCommand implements Command {
......@@ -114,12 +113,12 @@ public class EMFTransactionalCommand implements Command {
try {
tx.commit();
} catch (RollbackException e) {
LoggingUtils.log(ToolingKernelActivator.getDefault(),
"Transaction was rolled back!", IStatus.ERROR, e);
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Transaction was rolled back!", e);
}
} else {
LoggingUtils.log(ToolingKernelActivator.getDefault(),
"Was not able to start transaction!", IStatus.ERROR);
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Was not able to start transaction!");
}
}
}
......
......@@ -24,7 +24,6 @@ import java.util.Map;
import org.conqat.lib.commons.reflect.ReflectionUtils;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IStatus;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.internal.ConnectionCompositorService;
import org.fortiss.tooling.kernel.internal.ElementCompositorService;
......@@ -69,7 +68,7 @@ import org.osgi.framework.Bundle;
* @author hoelzlf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash: 786F8E4DCC1D8024AB6DB6FBE101DB56
* @ConQAT.Rating YELLOW Hash: A84331A14E4EF55D9FD9FB282DA918B2
*/
public abstract class ObjectAware2ServiceBase<T extends IObjectAware2<? extends Object, ? extends Object>> {
......@@ -231,12 +230,12 @@ public abstract class ObjectAware2ServiceBase<T extends IObjectAware2<? extends
}
if (requiresUniqueHandler() && !list.isEmpty()) {
LoggingUtils.log(
LoggingUtils.warning(
ToolingKernelActivator.getDefault(),
"Encountered more than one handler registered with "
+ getExtensionPointName() + "("
+ handler.getClass() + "," + list.get(0).getClass()
+ ")", IStatus.WARNING);
+ ")");
}
list.add(handler);
}
......
......@@ -26,7 +26,6 @@ import java.util.Set;
import org.conqat.lib.commons.reflect.ReflectionUtils;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IStatus;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.internal.ConnectionCompositorService;
import org.fortiss.tooling.kernel.util.ExtensionPointUtils;
......@@ -64,7 +63,7 @@ import org.osgi.framework.Bundle;
* @author hoelzlf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 1A071A45F987F422A550D0D78B863F90
* @ConQAT.Rating YELLOW Hash: 93375807324DBDF3639FA5D77D1E61BE
*/
public abstract class ObjectAwareServiceBase<T extends IObjectAware<? extends Object>> {
......@@ -123,12 +122,12 @@ public abstract class ObjectAwareServiceBase<T extends IObjectAware<? extends Ob
handlerMap.put(modelElementClass, list);
}
if (requiresUniqueHandler() && !list.isEmpty()) {
LoggingUtils.log(
LoggingUtils.warning(
ToolingKernelActivator.getDefault(),
"Encountered more than one handler registered with "
+ getExtensionPointName() + "("
+ handler.getClass() + "," + list.get(0).getClass()
+ ")", IStatus.WARNING);
+ ")");
}
list.add(handler);
allHandlersSet.add(handler);
......
......@@ -24,7 +24,6 @@ import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.osgi.framework.Bundle;
......@@ -39,7 +38,7 @@ import org.osgi.framework.Bundle;
* @author hummel
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 9EFBA1C989BEFB70A825EC0F299A0B46
* @ConQAT.Rating YELLOW Hash: F8469E65054BB71EB418921037100326
*/
public class ExtensionPointUtils {
......@@ -69,9 +68,8 @@ public class ExtensionPointUtils {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(extensionPointName);
if (extensionPoint == null) {
LoggingUtils.log(ToolingKernelActivator.getDefault(),
"Could not find extension point " + extensionPointName,
IStatus.ERROR);
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Could not find extension point " + extensionPointName);
return Collections.EMPTY_LIST;
}
......
......@@ -30,49 +30,19 @@ import org.eclipse.core.runtime.Status;
*
* @author hummel
* @author schwitze
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 5489A04000105CF881046928C19E6E14
* @ConQAT.Rating YELLOW Hash: 1166B933696B4D525D5D97DE2724E3DD
*/
public class LoggingUtils {
/**
* Logs a message that occurred in the context of the given plug-in with the
* given severity.
*
* @see IStatus
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param severity
* The severity of the log message. See {@link IStatus} for valid
* constants.
*
*/
public static void log(Plugin plugin, String message, int severity) {
log(plugin, message, severity, null);
}
/**
* Logs a message that occurred in the context of the given plug-in with the
* given severity and a given {@link Throwable} that originally caused this
* log message.
*
* @see IStatus
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param severity
* The severity of the log message. See {@link IStatus} for valid
* constants.
* @param cause
* The {@link Throwable} that originally caused this log message.
*/
public static void log(Plugin plugin, String message, int severity,
private static void log(Plugin plugin, String message, int severity,
Throwable cause) {
String pluginId = plugin.getBundle().getSymbolicName();
IStatus status = new Status(severity, pluginId, message, cause);
......@@ -82,15 +52,48 @@ public class LoggingUtils {
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#ERROR}.
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param cause
* The {@link Throwable} that originally caused this log message.
*/
public static void error(Plugin plugin, String message, Throwable cause) {
log(plugin, message, IStatus.ERROR, cause);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#ERROR}.
*/
public static void error(Plugin plugin, String message) {
error(plugin, message, null);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#WARNING}.
*/
public static void warning(Plugin plugin, String message, Throwable cause) {
log(plugin, message, IStatus.WARNING, cause);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#WARNING}.
*/
public static void warning(Plugin plugin, String message) {
warning(plugin, message, null);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#INFO}.
*/
public static void info(Plugin plugin, String message, Throwable cause) {
log(plugin, message, IStatus.INFO, cause);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#INFO}.
*/
public static void info(Plugin plugin, String message) {
info(plugin, message, null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment