blob: 8924aa8dfdec270b8ec5dd15798c6ca1ef6e04af [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Robert Bosch GmbH.
* 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:
* Robert Bosch GmbH - initial API and implementation
*******************************************************************************/
package templates
import SampleModel.SampleModelFactory
import java.io.File
import org.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.amalthea.model.HWModel
import org.eclipse.app4mc.amalthea.model.MappingModel
import org.eclipse.app4mc.amalthea.model.OSModel
import org.eclipse.app4mc.transformation.extensions.ICustomObjectsStore
import org.eclipse.app4mc.transformation.extensions.base.templates.Model2ModelRootTransformer
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
import org.osgi.service.component.annotations.ReferencePolicyOption
import org.osgi.service.component.annotations.ReferenceScope
@Component(property=#[
// CommandProcessor.COMMAND_SCOPE + ":String=app4mc",
"transformation=Amalthea2SampleModel"
], service=Model2ModelRootTransformer)
class AmaltheaModel2ModelTransformer extends Model2ModelRootTransformer {
@Reference
ICustomObjectsStore customObjsStore
/*- Factory initiaization */
val outputModelFactory = SampleModelFactory.eINSTANCE
@Reference( scope=ReferenceScope.
PROTOTYPE_REQUIRED)
SWTransformer sw
@Reference ( scope=ReferenceScope.
PROTOTYPE_REQUIRED)
HWTransformer hw
@Reference( scope=ReferenceScope.
PROTOTYPE_REQUIRED)
OSTransformer os
@Reference( scope=ReferenceScope.
PROTOTYPE_REQUIRED)
MappingTransformer mt
override m2mTransformation(ResourceSet inputResourceSet, ResourceSet outputResourceSet) {
var int fileIndex = 1
for (resource : inputResourceSet.resources) {
for (content : resource.contents) {
// content is a Amalthea model
customObjsStore.getLogger.info("Processing file : " + resource.URI)
val simulationModelRoot = transform(content as Amalthea)
val out_uri = URI.createFileURI(
getProperty("m2m_output_folder",customObjsStore) + File.separator + fileIndex++ + ".root")
val out_resource = outputResourceSet.createResource(out_uri)
out_resource.contents.add(simulationModelRoot)
out_resource.save(null)
customObjsStore.logger.info("Transformed model file generated at : " + out_uri)
}
}
}
def create outputModelFactory.createModel transform(Amalthea amalthea) {
customObjsStore.injectMembers(SWTransformer, sw)
customObjsStore.injectMembers(HWTransformer, hw)
customObjsStore.injectMembers(OSTransformer, os)
customObjsStore.injectMembers(MappingTransformer, mt)
hw.transfromHWModel(amalthea.hwModel as HWModel, it)
os.transfromOSModel(amalthea.osModel as OSModel, it)
mt.transfromMappingModel(amalthea.mappingModel as MappingModel, it)
}
}