| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| * ******************************************************************************* |
| */ |
| |
| package templates.m2m; |
| |
| import com.google.inject.Inject |
| import com.inchron.realtime.root.RootFactory |
| import java.io.File |
| import org.eclipse.app4mc.amalthea.model.Amalthea |
| import org.eclipse.app4mc.transformation.extensions.base.templates.Model2ModelRootTransformer |
| import org.eclipse.emf.common.util.URI |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| import templates.utils.AmltCacheModel |
| |
| class Amlt2InchronTransformer extends Model2ModelRootTransformer { |
| |
| @Inject ModelTransformer modelTransformer |
| @Inject SettingsTransformer settingsTransformer |
| |
| override m2mTransformation(ResourceSet inputResourceSet, ResourceSet outputResourceSet) { |
| /*- Associating CacheModel to the transformation. |
| * Note: This is a cummulative cache of all the elements from various input AMALTHEA model files. |
| */ |
| var AmltCacheModel cacheModel = new AmltCacheModel |
| |
| customObjsStore.injectMembers(AmltCacheModel, cacheModel) |
| |
| var int fileIndex = 1 |
| |
| for (resource : inputResourceSet.resources) { |
| for (content : resource.contents) { |
| |
| logger.info("Processing file : " + resource.URI) |
| |
| /*- Building INCHRON model from AMALTHEA input model */ |
| val inchronRoot = transform(content as Amalthea) |
| |
| fileIndex++ |
| |
| val out_uri = URI.createFileURI( |
| getProperty("m2m_output_folder") + File.separator + fileIndex + ".iprx") |
| |
| val out_resource = outputResourceSet.createResource(out_uri) |
| |
| /*-Attaching a resource to the INCHRON model element */ |
| out_resource.contents.add(inchronRoot) |
| |
| } |
| } |
| |
| /*- Saving all the root INCHRON model files*/ |
| for (resource : outputResourceSet.resources) { |
| |
| resource.save(null) |
| |
| logger.info("Transformed model file generated at : " + resource.URI) |
| } |
| |
| logger.info("*********************** Completed : Model to Model transformation **************************") |
| |
| } |
| |
| /** |
| * This method is used to transform AMALTHEA model to INCHRON model |
| */ |
| def create RootFactory.eINSTANCE.createRoot transform(Amalthea amalthea) { |
| |
| /*-Step 1: Injecting all the required transformation objects into the CustomObjsStore. Advantage with this approach is, it provides flexibility to access these elements across various transformers */ |
| // customObjsStore.injectMembers(SWTransformer , swTransformer) |
| // customObjsStore.injectMembers(HWTransformer , hwTransformer) |
| // customObjsStore.injectMembers(OSTransformer , osTransformer) |
| // |
| // customObjsStore.injectMembers(StimuliTransformer , stimuliTransformer) |
| /* Step 2: Building INCHRON model by invoking various transformers */ |
| it.model = modelTransformer.createInchronModel(amalthea) |
| it.settings = settingsTransformer.createInchronSettings(amalthea) |
| } |
| |
| |
| } |