blob: 71317b2b74645465dc7b3835475133d4ed91f107 [file] [log] [blame]
/******************************************************************************
* *
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG, 69115 Heidelberg, Germany *
* *
* 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 *
* *
*============================================================================*
* Initial contribution: *
* Loetz GmbH & Co. KG *
* *
* based on mwe2 *
******************************************************************************/
package org.eclipse.osbp.xtext.dialogdsl;
import org.eclipse.xtext.junit4.GlobalRegistries;
import org.eclipse.xtext.junit4.GlobalRegistries.GlobalStateMemento;
import org.eclipse.xtext.junit4.IInjectorProvider;
import org.eclipse.xtext.junit4.IRegistryConfigurator;
import com.google.inject.Injector;
public class DialogDslInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
protected GlobalStateMemento stateBeforeInjectorCreation;
protected GlobalStateMemento stateAfterInjectorCreation;
protected Injector injector;
static {
GlobalRegistries.initializeDefaults();
}
public Injector getInjector()
{
if (injector == null) {
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
this.injector = internalCreateInjector();
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
}
return injector;
}
protected Injector internalCreateInjector() {
return new DialogDslStandaloneSetup().createInjectorAndDoEMFRegistration();
}
public void restoreRegistry() {
stateBeforeInjectorCreation.restoreGlobalState();
}
public void setupRegistry() {
getInjector();
stateAfterInjectorCreation.restoreGlobalState();
}
}