blob: 865ce5df24da02a049f3270105bbdabcc591df1b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010, 2012 E.D.Willink 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:
* E.D.Willink - initial API and implementation
*******************************************************************************/
package org.eclipse.ocl.examples.xtext.essentialocl;
import java.util.Map;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.ocl.examples.xtext.base.BaseStandaloneSetup;
import org.eclipse.ocl.examples.xtext.base.services.CompatibilityGrammarProvider;
import org.eclipse.ocl.examples.xtext.essentialocl.essentialoclcs.EssentialOCLCSPackage;
import org.eclipse.ocl.examples.xtext.essentialocl.scoping.EssentialOCLScoping;
import org.eclipse.ocl.examples.xtext.essentialocl.utilities.EssentialOCLASResourceFactory;
import com.google.inject.Injector;
/**
* Initialization support for running Xtext languages
* without equinox extension registry
*/
public class EssentialOCLStandaloneSetup extends EssentialOCLStandaloneSetupGenerated
{
private static Injector injector = null;
public static void doSetup() {
assert !EMFPlugin.IS_ECLIPSE_RUNNING; // Enforces Bug 382058 fix
if (injector == null) {
new EssentialOCLStandaloneSetup().createInjectorAndDoEMFRegistration();
}
}
public static void doTearDown() {
injector = null;
}
public static void init() {
BaseStandaloneSetup.doSetup();
EssentialOCLScoping.init();
EssentialOCLASResourceFactory.INSTANCE.getClass();
// EssentialOCLCS2Pivot.FACTORY.getClass();
// EssentialOCLPivot2CS.FACTORY.getClass();
EPackage.Registry.INSTANCE.put(EssentialOCLCSPackage.eNS_URI, EssentialOCLCSPackage.eINSTANCE);
// EValidator.Registry.INSTANCE.put(EssentialOCLCSPackage.eINSTANCE, EssentialOCLCSValidator.INSTANCE);
}
/**
* Return the Injector for this plugin.
*/
public static final Injector getInjector() {
return injector;
}
@Override
public Injector createInjector() {
Map<String, Object> globalExtensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
if (globalExtensionToFactoryMap.containsKey("xmi"))
globalExtensionToFactoryMap.remove("xmi");
if (!globalExtensionToFactoryMap.containsKey(Resource.Factory.Registry.DEFAULT_EXTENSION))
globalExtensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
injector = super.createInjector();
return injector;
}
@Override
public Injector createInjectorAndDoEMFRegistration() {
init();
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
@SuppressWarnings("unused")Class<?> loadClass = classLoader.loadClass("org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl");
return super.createInjectorAndDoEMFRegistration();
}
catch (ClassNotFoundException e) { // Xtext 2.3 - super code with custom BinaryResourceFactory
// register default ePackages
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xtextbin", CompatibilityGrammarProvider.BinaryGrammarResourceFactoryImpl.INSTANCE);
if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE);
Injector injector = createInjector();
register(injector);
return injector;
}
}
}