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

Replaced some kernel services with OSGi declarative services.

refs 2598
parent e227ca46
No related branches found
No related tags found
No related merge requests found
Showing
with 176 additions and 71 deletions
......@@ -32,4 +32,4 @@ Export-Package: org.fortiss.tooling.kernel;uses:="org.eclipse.core.runtime,org.o
org.fortiss.tooling.kernel.service.base,
org.fortiss.tooling.kernel.service.listener,
org.fortiss.tooling.kernel.utils;uses:="org.eclipse.emf.ecore,org.eclipse.core.resources"
Service-Component: OSGI-INF/EclipseResourceStorageService.xml, OSGI-INF/LoggingService.xml, OSGI-INF/TutorialService.xml
Service-Component: OSGI-INF/CommandStackService.xml, OSGI-INF/EclipseResourceStorageService.xml, OSGI-INF/LoggingService.xml, OSGI-INF/TransformationService.xml, OSGI-INF/PersistencyService.xml, OSGI-INF/PrototypeService.xml, OSGI-INF/TutorialService.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: pom.xml 16107 2016-03-07 11:50:15Z hoelzl $
@version $Rev: 16107 $
@ConQAT.Rating YELLOW Hash: 1AB4E45B3940C00A982A3C49474361A1
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.fortiss.tooling.kernel.service.CommandStackService">
<implementation class="org.fortiss.tooling.kernel.internal.CommandStackService"/>
<service>
<provide interface="org.fortiss.tooling.kernel.service.ICommandStackService"/>
</service>
</scr:component>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: pom.xml 16107 2016-03-07 11:50:15Z hoelzl $
@version $Rev: 16107 $
@ConQAT.Rating YELLOW Hash: 1AB4E45B3940C00A982A3C49474361A1
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.fortiss.tooling.kernel.service.PersistencyService">
<implementation class="org.fortiss.tooling.kernel.internal.PersistencyService"/>
<service>
<provide interface="org.fortiss.tooling.kernel.service.IPersistencyService"/>
</service>
</scr:component>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: pom.xml 16107 2016-03-07 11:50:15Z hoelzl $
@version $Rev: 16107 $
@ConQAT.Rating YELLOW Hash: 1AB4E45B3940C00A982A3C49474361A1
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.fortiss.tooling.kernel.service.PrototypeService">
<implementation class="org.fortiss.tooling.kernel.internal.PrototypeService"/>
<service>
<provide interface="org.fortiss.tooling.kernel.service.IPrototypeService"/>
</service>
</scr:component>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: pom.xml 16107 2016-03-07 11:50:15Z hoelzl $
@version $Rev: 16107 $
@ConQAT.Rating YELLOW Hash: D68D970F24A29629569E61B8181D188F
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.fortiss.tooling.kernel.service.TransformationService">
<implementation class="org.fortiss.tooling.kernel.internal.TransformationService"/>
<service>
<provide interface="org.fortiss.tooling.kernel.service.ITransformationService"/>
</service>
</scr:component>
......@@ -114,8 +114,6 @@ public final class ToolingKernel {
ToolingKernelInternal.registerConnectionCompositor(compositor, sourceClass, targetClass);
}
/** Prints the given kernel phase message to system console. */
/** Prints the introduction message of the given phase */
public static void printPhase(String phase) {
phase = rightPad(phase, 40);
......
......@@ -18,8 +18,8 @@ $Id$
package org.fortiss.tooling.kernel;
import org.eclipse.core.runtime.Plugin;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle.
......@@ -62,8 +62,11 @@ public class ToolingKernelActivator extends Plugin {
/** Returns the service for the given interface. */
public static <SERVICE> SERVICE getService(Class<SERVICE> clazz) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference<SERVICE> ref = context.getServiceReference(clazz);
return context.getService(ref);
return ServicesUtils.getService(plugin.getBundle(), clazz);
}
/** Releases the OSGi service. */
public static boolean ungetService(Class<?> clazz) {
return ServicesUtils.ungetService(plugin.getBundle(), clazz);
}
}
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.getService;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.ungetService;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import org.eclipse.core.runtime.IProgressMonitor;
......@@ -52,56 +54,71 @@ public class CommandStackService implements ICommandStackService {
if(target != null) {
target.removeCommandStackListener(listener);
} else {
for(ITopLevelElement top : IPersistencyService.getInstance().getTopLevelElements()) {
IPersistencyService ps = getService(IPersistencyService.class);
for(ITopLevelElement top : ps.getTopLevelElements()) {
top.removeCommandStackListener(listener);
}
ungetService(IPersistencyService.class);
}
}
/** {@inheritDoc} */
@Override
public void runAsCommand(EObject target, Runnable runner) {
ITopLevelElement context = IPersistencyService.getInstance().getTopLevelElementFor(target);
IPersistencyService ps = getService(IPersistencyService.class);
ITopLevelElement context = ps.getTopLevelElementFor(target);
context.runAsCommand(runner);
ungetService(IPersistencyService.class);
}
/** {@inheritDoc} */
@Override
public boolean canUndo(EObject target) {
ITopLevelElement context = IPersistencyService.getInstance().getTopLevelElementFor(target);
IPersistencyService ps = getService(IPersistencyService.class);
ITopLevelElement context = ps.getTopLevelElementFor(target);
ungetService(IPersistencyService.class);
return context != null && context.canUndo();
}
/** {@inheritDoc} */
@Override
public boolean canRedo(EObject target) {
ITopLevelElement context = IPersistencyService.getInstance().getTopLevelElementFor(target);
IPersistencyService ps = getService(IPersistencyService.class);
ITopLevelElement context = ps.getTopLevelElementFor(target);
ungetService(IPersistencyService.class);
return context != null && context.canRedo();
}
/** {@inheritDoc} */
@Override
public void undo(EObject target) {
IPersistencyService.getInstance().getTopLevelElementFor(target).undo();
IPersistencyService ps = getService(IPersistencyService.class);
ps.getTopLevelElementFor(target).undo();
ungetService(IPersistencyService.class);
}
/** {@inheritDoc} */
@Override
public void redo(EObject target) {
IPersistencyService.getInstance().getTopLevelElementFor(target).redo();
IPersistencyService ps = getService(IPersistencyService.class);
ps.getTopLevelElementFor(target).redo();
ungetService(IPersistencyService.class);
}
/** {@inheritDoc} */
@Override
public boolean isDirty(EObject target) {
ITopLevelElement context = IPersistencyService.getInstance().getTopLevelElementFor(target);
IPersistencyService ps = getService(IPersistencyService.class);
ITopLevelElement context = ps.getTopLevelElementFor(target);
ungetService(IPersistencyService.class);
return context != null && context.isDirty();
}
/** {@inheritDoc} */
@Override
public void doSave(EObject target, IProgressMonitor monitor) {
ITopLevelElement context = IPersistencyService.getInstance().getTopLevelElementFor(target);
IPersistencyService ps = getService(IPersistencyService.class);
ITopLevelElement context = ps.getTopLevelElementFor(target);
if(context != null && context.isDirty()) {
try {
context.doSave(monitor);
......@@ -109,5 +126,6 @@ public class CommandStackService implements ICommandStackService {
error(ToolingKernelActivator.getDefault(), "Error while saving.", e);
}
}
ungetService(IPersistencyService.class);
}
}
......@@ -94,6 +94,9 @@ public class PersistencyService implements IPersistencyService, IIntrospectiveKe
private final List<IPersistencyServiceListener> listeners =
new ArrayList<IPersistencyServiceListener>();
/** The tutorial service instance. */
private ITutorialService tutorialService;
/** Initializes the service. */
public void initializeService() {
setupStorageProviders();
......@@ -109,6 +112,7 @@ public class PersistencyService implements IPersistencyService, IIntrospectiveKe
/** Starts the service. */
public void startService() {
KernelIntrospectionSystemService.getInstance().registerService(this);
tutorialService = ToolingKernelActivator.getService(ITutorialService.class);
}
/** Registers the given storage provider with the service. */
......@@ -135,9 +139,8 @@ public class PersistencyService implements IPersistencyService, IIntrospectiveKe
/** {@inheritDoc} */
@Override
public synchronized UnmodifiableList<ITopLevelElement> getTopLevelElements() {
if(ITutorialService.getInstance().isTutorialActive()) {
EObject activeRootElement =
ITutorialService.getInstance().getActiveTutorial().getRootElement();
if(tutorialService != null && tutorialService.isTutorialActive()) {
EObject activeRootElement = tutorialService.getActiveTutorial().getRootElement();
return asUnmodifiable(elementCache.stream()
.filter(t -> t.getRootModelElement() == activeRootElement)
.collect(Collectors.toList()));
......
......@@ -67,6 +67,8 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** Stores the registered prototype providers. */
private final List<IPrototypeProvider> prototypeProviderList =
new ArrayList<IPrototypeProvider>();
/** The tutorial service instance. */
private ITutorialService tutorialService;
/** Initializes the service. */
public void initializeService() {
......@@ -76,6 +78,7 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** Starts the service. */
public void startService() {
KernelIntrospectionSystemService.getInstance().registerService(this);
tutorialService = ToolingKernelActivator.getService(ITutorialService.class);
}
/** Registers the given provider with the service. */
......@@ -118,10 +121,10 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** {@inheritDoc} */
@Override
public UnmodifiableList<Prototype> getAllPrototypes() {
if(ITutorialService.getInstance().isTutorialActive()) {
ITutorialService service = ITutorialService.getInstance();
if(tutorialService.isTutorialActive()) {
return asUnmodifiable(getPrototypes(false, true).stream()
.filter(proto -> service.prototypeActive(proto)).collect(Collectors.toList()));
.filter(proto -> tutorialService.prototypeActive(proto))
.collect(Collectors.toList()));
}
return asUnmodifiable(getPrototypes(false, false));
}
......@@ -129,10 +132,10 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** {@inheritDoc} */
@Override
public UnmodifiableList<Prototype> getPrimaryPrototypes() {
if(ITutorialService.getInstance().isTutorialActive()) {
ITutorialService service = ITutorialService.getInstance();
if(tutorialService.isTutorialActive()) {
return asUnmodifiable(getPrototypes(true, true).stream()
.filter(proto -> service.prototypeActive(proto)).collect(Collectors.toList()));
.filter(proto -> tutorialService.prototypeActive(proto))
.collect(Collectors.toList()));
}
return asUnmodifiable(getPrototypes(true, false));
}
......
......@@ -19,6 +19,8 @@ package org.fortiss.tooling.kernel.internal;
import static java.util.Collections.emptyMap;
import static org.conqat.lib.commons.collections.CollectionUtils.asUnmodifiable;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.getService;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.ungetService;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
......@@ -76,6 +78,11 @@ public final class TutorialService implements ITutorialService, CommandStackList
/** The active top-level element. */
private ITopLevelElement activeTopElement = null;
/** The persistency service. */
private IPersistencyService persistencyService;
/** The command stack service. */
private ICommandStackService commandStackService;
/** Initializes the service. */
public void initializeService() {
// nothing to do here
......@@ -154,6 +161,8 @@ public final class TutorialService implements ITutorialService, CommandStackList
/** {@inheritDoc} */
@Override
public void startTutorial(Class<? extends ITutorialProvider> provider) {
persistencyService = getService(IPersistencyService.class);
commandStackService = getService(ICommandStackService.class);
try {
activeTutorial = provider.newInstance();
List<TutorialStepBase> rootSteps = activeTutorial.getDefinition().getSteps();
......@@ -163,9 +172,8 @@ public final class TutorialService implements ITutorialService, CommandStackList
activeStep = atomicStepList.get(0);
finalAtomicStep = atomicStepList.get(atomicStepList.size() - 1);
EObject root = activeTutorial.getRootElement();
activeTopElement =
IPersistencyService.getInstance().addDummyEObjectAsTopLevelElement(root);
ICommandStackService.getInstance().addCommandStackListener(activeTopElement, this);
activeTopElement = persistencyService.addDummyEObjectAsTopLevelElement(root);
commandStackService.addCommandStackListener(activeTopElement, this);
fireTutorialStarted();
} catch(InstantiationException e) {
error(ToolingKernelActivator.getDefault(), e.getMessage(), e);
......@@ -190,9 +198,12 @@ public final class TutorialService implements ITutorialService, CommandStackList
@Override
public void stopTutorial() {
fireTutorialStopped();
ICommandStackService.getInstance().removeCommandStackListener(activeTopElement, this);
IPersistencyService.getInstance().removeDummyTopLevelElement(
activeTutorial.getRootElement());
commandStackService.removeCommandStackListener(activeTopElement, this);
ungetService(ICommandStackService.class);
commandStackService = null;
persistencyService.removeDummyTopLevelElement(activeTutorial.getRootElement());
ungetService(IPersistencyService.class);
persistencyService = null;
activeTopElement = null;
atomicStepList.clear();
activeStep = null;
......
......@@ -20,8 +20,9 @@ package org.fortiss.tooling.kernel.service;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.internal.CommandStackService;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
/**
* The command stack service manages the access to the command stack and editing
......@@ -38,17 +39,16 @@ import org.fortiss.tooling.kernel.internal.CommandStackService;
*/
public interface ICommandStackService {
/**
* Returns the singleton instance of the service.
* Returns the service instance.
*
* @deprecated
* use {@link #getInstance()} instead
* @deprecated use {@link ServicesUtils#getService(org.osgi.framework.Bundle, Class)} and
* {@link ServicesUtils#ungetService(org.osgi.framework.Bundle, Class)}, instead.
* See also {@link ToolingKernelActivator#getService(Class)} and
* {@link ToolingKernelActivator#ungetService(Class)}
*/
@Deprecated
public static final ICommandStackService INSTANCE = new CommandStackService();
/** Returns the service instance. */
public static ICommandStackService getInstance() {
return INSTANCE;
return ToolingKernelActivator.getService(ICommandStackService.class);
}
/** Adds a command stack listener to the stack of the given target element. */
......
......@@ -21,11 +21,12 @@ import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IStorageProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.extension.data.ModelStorageError;
import org.fortiss.tooling.kernel.internal.PersistencyService;
import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
/**
* The persistency service provides the transparent access to the different
......@@ -46,17 +47,16 @@ import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener;
*/
public interface IPersistencyService {
/**
* Returns the singleton instance of the service.
* Returns the service instance.
*
* @deprecated
* use {@link #getInstance()} instead
* @deprecated use {@link ServicesUtils#getService(org.osgi.framework.Bundle, Class)} and
* {@link ServicesUtils#ungetService(org.osgi.framework.Bundle, Class)}, instead.
* See also {@link ToolingKernelActivator#getService(Class)} and
* {@link ToolingKernelActivator#ungetService(Class)}
*/
@Deprecated
public static final IPersistencyService INSTANCE = new PersistencyService();
/** Returns the service instance. */
public static IPersistencyService getInstance() {
return INSTANCE;
return ToolingKernelActivator.getService(IPersistencyService.class);
}
/**
......
......@@ -17,14 +17,17 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.getService;
import java.util.List;
import org.conqat.lib.commons.collections.UnmodifiableList;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.IPrototypeProvider;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.extension.data.PrototypeCategory;
import org.fortiss.tooling.kernel.internal.PrototypeService;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
/**
* The prototype service provides registration and access to model element
......@@ -43,17 +46,16 @@ import org.fortiss.tooling.kernel.internal.PrototypeService;
*/
public interface IPrototypeService {
/**
* Returns the singleton instance of the service.
* Returns the service instance.
*
* @deprecated
* use {@link #getInstance()} instead
* @deprecated use {@link ServicesUtils#getService(org.osgi.framework.Bundle, Class)} and
* {@link ServicesUtils#ungetService(org.osgi.framework.Bundle, Class)}, instead.
* See also {@link ToolingKernelActivator#getService(Class)} and
* {@link ToolingKernelActivator#ungetService(Class)}
*/
@Deprecated
public static final IPrototypeService INSTANCE = new PrototypeService();
/** Returns the service instance. */
public static IPrototypeService getInstance() {
return INSTANCE;
return getService(IPrototypeService.class);
}
/** Returns the list of all registered prototype providers. */
......
......@@ -17,13 +17,16 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service;
import static org.fortiss.tooling.kernel.ToolingKernelActivator.getService;
import java.util.List;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.data.TransformationProviderChain;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
import org.fortiss.tooling.kernel.internal.TransformationService;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
/**
* The transformation service provides registration and access to transformation
......@@ -40,17 +43,16 @@ import org.fortiss.tooling.kernel.internal.TransformationService;
*/
public interface ITransformationService {
/**
* Returns the singleton instance of the service.
* Returns the service instance.
*
* @deprecated
* use {@link #getInstance()} instead
* @deprecated use {@link ServicesUtils#getService(org.osgi.framework.Bundle, Class)} and
* {@link ServicesUtils#ungetService(org.osgi.framework.Bundle, Class)}, instead.
* See also {@link ToolingKernelActivator#getService(Class)} and
* {@link ToolingKernelActivator#ungetService(Class)}
*/
@Deprecated
public static final ITransformationService INSTANCE = new TransformationService();
/** Returns the service instance. */
public static ITransformationService getInstance() {
return INSTANCE;
return getService(ITransformationService.class);
}
/**
......
......@@ -23,12 +23,13 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
import org.fortiss.tooling.kernel.extension.data.TutorialAtomicStep;
import org.fortiss.tooling.kernel.extension.data.TutorialStepBase;
import org.fortiss.tooling.kernel.internal.TutorialService;
import org.fortiss.tooling.kernel.service.listener.ITutorialServiceListener;
import org.fortiss.tooling.kernel.utils.ServicesUtils;
/**
* The tutorial service provides pre-defined models with step-wise
......@@ -47,15 +48,14 @@ import org.fortiss.tooling.kernel.service.listener.ITutorialServiceListener;
*/
public interface ITutorialService extends ITutorialWhitelistProvider {
/**
* Returns the singleton instance of the service.
* Returns the service instance.
*
* @deprecated
* use {@link #getInstance()} instead
* @deprecated use {@link ServicesUtils#getService(org.osgi.framework.Bundle, Class)} and
* {@link ServicesUtils#ungetService(org.osgi.framework.Bundle, Class)}, instead.
* See also {@link ToolingKernelActivator#getService(Class)} and
* {@link ToolingKernelActivator#ungetService(Class)}
*/
@Deprecated
public static final ITutorialService INSTANCE = new TutorialService();
/** Returns the service instance. */
public static ITutorialService getInstance() {
return getService(ITutorialService.class);
}
......
......@@ -22,6 +22,9 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* Utility methods to ease the access to kernel services.
......@@ -36,7 +39,21 @@ public class ServicesUtils {
/** Proxy for {@link IConstraintCheckerService#performAllConstraintChecksRecursively(EObject)} */
public static List<IConstraintViolation<? extends EObject>>
performAllConstraintChecksRecursively(EObject modelElement) {
return IConstraintCheckerService.getInstance()
.performAllConstraintChecksRecursively(modelElement);
return IConstraintCheckerService.getInstance().performAllConstraintChecksRecursively(
modelElement);
}
/** Returns the service for the given interface. */
public static <SERVICE> SERVICE getService(Bundle bundle, Class<SERVICE> clazz) {
BundleContext context = bundle.getBundleContext();
ServiceReference<SERVICE> ref = context.getServiceReference(clazz);
return context.getService(ref);
}
/** Releases the use of the given service. */
public static boolean ungetService(Bundle bundle, Class<?> clazz) {
BundleContext context = bundle.getBundleContext();
ServiceReference<?> ref = context.getServiceReference(clazz);
return context.ungetService(ref);
}
}
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