package android.security.execute.transformations;



import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmt.modisco.java.ThisExpression;
import org.eclipse.m2m.atl.core.ATLCoreException;
import org.eclipse.m2m.atl.core.IExtractor;
import org.eclipse.m2m.atl.core.IInjector;
import org.eclipse.m2m.atl.core.IModel;
import org.eclipse.m2m.atl.core.IReferenceModel;
import org.eclipse.m2m.atl.core.ModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFExtractor;
import org.eclipse.m2m.atl.core.emf.EMFInjector;
import org.eclipse.m2m.atl.core.emf.EMFModel;
import org.eclipse.m2m.atl.core.emf.EMFModelFactory;
import org.eclipse.m2m.atl.core.emf.EMFReferenceModel;
import org.eclipse.m2m.atl.core.launch.ILauncher;
import org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher;
import org.eclipse.ui.internal.handlers.WizardHandler.New;
import org.omg.CORBA.ORB;
import android.security.extractor.Utility;

public class ICCModelExtractorForAbundleOFOneToTwentyApps {
	
	public static void runATL(String inputURI1, String inputURI2, String inputURI3, String inputURI4 ,String inputURI5, String inputURI6, String inputURI7, String inputURI8, String inputURI9, String inputURI10, String inputURI11, String inputURI12, String inputURI13, String inputURI14 ,String inputURI15, String inputURI16, String inputURI17, String inputURI18, String inputURI19, String inputURI20, String outputURI) {
        try {
        	System.out.println("ATLinitial:\n");
            ILauncher transformationLauncher = new EMFVMLauncher();
            ModelFactory modelFactory = new EMFModelFactory();
            IInjector injector = new EMFInjector();
            IExtractor extractor = new EMFExtractor();
            
             
            System.out.println("recievemodels:\n");
            IReferenceModel androidMetaModel = modelFactory.newReferenceModel();
            injector.inject(androidMetaModel, Utility.ANDROID_SECURITY_METAMODEL_PATH);
            
            IReferenceModel ICCMetamodel = modelFactory.newReferenceModel();
    		injector.inject(ICCMetamodel, Utility.ICC_METAMODEL_PATH);
            

            IModel inModel1 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel1, inputURI1);
            
            IModel inModel2 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel2, inputURI2);
            
            IModel inModel3 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel3, inputURI3);
            
            IModel inModel4 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel4, inputURI4);
            
            IModel inModel5 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel5, inputURI5);
            
            IModel inModel6 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel6, inputURI6);
            
            IModel inModel7 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel7, inputURI7);
            
            IModel inModel8 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel8, inputURI8);
            
            IModel inModel9 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel9, inputURI9);
            
            IModel inModel10 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel10, inputURI10);
            
            
            IModel inModel11 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel11, inputURI11);
            
            IModel inModel12 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel12, inputURI12);
            
            IModel inModel13 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel13, inputURI13);
            
            IModel inModel14 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel14, inputURI14);
            
            IModel inModel15 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel15, inputURI15);
            
            IModel inModel16 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel16, inputURI16);
            
            IModel inModel17 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel17, inputURI17);
            
            IModel inModel18 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel18, inputURI18);
            
            IModel inModel19 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel19, inputURI19);
            
            IModel inModel20 = modelFactory.newModel(androidMetaModel);
            injector.inject(inModel20, inputURI20);
            
            
            
            

            IModel outModel = modelFactory.newModel(ICCMetamodel);
            transformationLauncher.initialize(new HashMap());
            transformationLauncher.addInModel(inModel1, "IN", "ASAMM");
            transformationLauncher.addInModel(inModel2, "IN1", "ASAMM");
            transformationLauncher.addInModel(inModel3, "IN2", "ASAMM");
            transformationLauncher.addInModel(inModel4, "IN3", "ASAMM");
            transformationLauncher.addInModel(inModel5, "IN4", "ASAMM");
            transformationLauncher.addInModel(inModel6, "IN5", "ASAMM");
            transformationLauncher.addInModel(inModel7, "IN6", "ASAMM");
            transformationLauncher.addInModel(inModel8, "IN7", "ASAMM");
            transformationLauncher.addInModel(inModel9, "IN8", "ASAMM");
            transformationLauncher.addInModel(inModel10, "IN9", "ASAMM");
            transformationLauncher.addInModel(inModel11, "IN10", "ASAMM");
            transformationLauncher.addInModel(inModel12, "IN11", "ASAMM");
            transformationLauncher.addInModel(inModel13, "IN12", "ASAMM");
            transformationLauncher.addInModel(inModel14, "IN13", "ASAMM");
            transformationLauncher.addInModel(inModel15, "IN14", "ASAMM");
            transformationLauncher.addInModel(inModel16, "IN15", "ASAMM");
            transformationLauncher.addInModel(inModel17, "IN16", "ASAMM");
            transformationLauncher.addInModel(inModel18, "IN17", "ASAMM");
            transformationLauncher.addInModel(inModel19, "IN18", "ASAMM");
            transformationLauncher.addInModel(inModel20, "IN19", "ASAMM");
          
            
            transformationLauncher.addOutModel(outModel, "OUT", "ICCMM");
            transformationLauncher.launch(ILauncher.RUN_MODE, new NullProgressMonitor(), new HashMap(),
                    new FileInputStream(Utility.ICC_MODEL_EXTRACTOR_For_A_Bundle_With_One_To_Twenty_Path));
            System.out.println("executeATL:\n");
            extractor.extract(outModel,  outputURI);
            System.out.println("savemodel:\n");
           
            EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
            emfModelFactory.unload((EMFModel) inModel1);
            emfModelFactory.unload((EMFModel) inModel2);
            emfModelFactory.unload((EMFModel) inModel3);
            emfModelFactory.unload((EMFModel) inModel4);
            emfModelFactory.unload((EMFModel) inModel5);
            emfModelFactory.unload((EMFModel) inModel6);
            emfModelFactory.unload((EMFModel) inModel7);
            emfModelFactory.unload((EMFModel) inModel8);
            emfModelFactory.unload((EMFModel) inModel9);
            emfModelFactory.unload((EMFModel) inModel10);
            emfModelFactory.unload((EMFModel) inModel11);
            emfModelFactory.unload((EMFModel) inModel12);
            emfModelFactory.unload((EMFModel) inModel13);
            emfModelFactory.unload((EMFModel) inModel14);
            emfModelFactory.unload((EMFModel) inModel15);
            emfModelFactory.unload((EMFModel) inModel16);
            emfModelFactory.unload((EMFModel) inModel17);
            emfModelFactory.unload((EMFModel) inModel18);
            emfModelFactory.unload((EMFModel) inModel19);
            emfModelFactory.unload((EMFModel) inModel20);
            
            emfModelFactory.unload((EMFModel) outModel);
            emfModelFactory.unload((EMFReferenceModel) androidMetaModel);
            emfModelFactory.unload((EMFReferenceModel) ICCMetamodel);
        } catch (ATLCoreException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}
