001/*******************************************************************************
002 * Copyright (c) 2018 Red Hat Inc
003 * All rights reserved. This program and the accompanying materials
004 * are made available under the terms of the Eclipse Public License v1.0
005 * which accompanies this distribution, and is available at
006 * http://www.eclipse.org/legal/epl-v10.html
007 *
008 * Contributors:
009 *     Jens Reimann - initial API and implementation
010 *******************************************************************************/
011package de.dentrassi.varlink.idl;
012
013import com.google.inject.Guice;
014import com.google.inject.Injector;
015import de.dentrassi.varlink.idl.varlinkIdl.VarlinkIdlPackage;
016import org.eclipse.emf.ecore.EPackage;
017import org.eclipse.emf.ecore.resource.Resource;
018import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
019import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
020import org.eclipse.xtext.ISetup;
021import org.eclipse.xtext.XtextPackage;
022import org.eclipse.xtext.resource.IResourceFactory;
023import org.eclipse.xtext.resource.IResourceServiceProvider;
024import org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl;
025
026@SuppressWarnings("all")
027public class VarlinkIdlStandaloneSetupGenerated implements ISetup {
028
029        @Override
030        public Injector createInjectorAndDoEMFRegistration() {
031                // register default ePackages
032                if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
033                        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
034                                "ecore", new EcoreResourceFactoryImpl());
035                if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
036                        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
037                                "xmi", new XMIResourceFactoryImpl());
038                if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
039                        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
040                                "xtextbin", new BinaryGrammarResourceFactoryImpl());
041                if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI))
042                        EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
043
044                Injector injector = createInjector();
045                register(injector);
046                return injector;
047        }
048        
049        public Injector createInjector() {
050                return Guice.createInjector(new VarlinkIdlRuntimeModule());
051        }
052        
053        public void register(Injector injector) {
054                if (!EPackage.Registry.INSTANCE.containsKey("http://www.dentrassi.de/varlink/idl/VarlinkIdl")) {
055                        EPackage.Registry.INSTANCE.put("http://www.dentrassi.de/varlink/idl/VarlinkIdl", VarlinkIdlPackage.eINSTANCE);
056                }
057                IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
058                IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
059                
060                Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("varlink", resourceFactory);
061                IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("varlink", serviceProvider);
062        }
063}