blob: 4e9b665d36949c79f90b508e116eb47950669ccd [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 app4mc.example.transform.m2m.transformers
import app4mc.example.transform.samplemodel.SampleModelFactory
import java.io.File
import java.util.Map
import org.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.amalthea.model.HWModel
import org.eclipse.app4mc.transformation.ServiceConstants
import org.eclipse.app4mc.transformation.transformers.Model2ModelRootTransformer
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.ConfigurationPolicy
import org.osgi.service.component.annotations.Reference
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Component(
configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
property=#[
"transformation=Amalthea2SampleModel"
], service=Model2ModelRootTransformer)
class AmaltheaModel2ModelTransformer extends Model2ModelRootTransformer {
static final Logger LOG = LoggerFactory.getLogger(typeof(AmaltheaModel2ModelTransformer))
/*- Factory initiaization */
val outputModelFactory = SampleModelFactory.eINSTANCE
String outputFolder
@Reference HWTransformer hardwareTransformer
@Activate
def package void activate(Map<String, ?> properties) {
LOG.debug("AmaltheaModel2ModelTransformer activated")
outputFolder = getProperty("m2m_output_folder", properties)
}
override m2mTransformation(ResourceSet inputResourceSet, ResourceSet outputResourceSet) {
LOG.debug("HWTransformer : "+hardwareTransformer.hashCode())
var int fileIndex = 1
for (resource : inputResourceSet.resources) {
for (content : resource.contents) {
LOG.info("Processing file : " + resource.URI)
val simulationModelRoot = transform(content as Amalthea)
val out_uri = URI.createFileURI(
outputFolder + File.separator + fileIndex++ + ".root")
val out_resource = outputResourceSet.createResource(out_uri)
out_resource.contents.add(simulationModelRoot)
out_resource.save(null)
LOG.info("Transformed model file generated at : " + out_uri)
}
}
}
def create outputModelFactory.createModel transform(Amalthea amalthea) {
hardwareTransformer.transfromHWModel(amalthea.hwModel as HWModel, it)
}
}