blob: 79d202d3afdd54ed136b33b79db5625fcccc8a0a [file] [log] [blame]
package templates
import com.inchron.realtime.root.RootFactory
import com.inchron.realtime.root.model.Model
import com.inchron.realtime.root.model.ModelFactory
import org.apache.log4j.ConsoleAppender
import org.apache.log4j.PatternLayout
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.EObject
import org.eclipse.emf.ecore.resource.ResourceSet
import templates.utils.AmltCacheModel
class AmaltheaTransformer extends Model2ModelRootTransformer{
/*- Factory initiaization */
val inchronRootFactory = RootFactory.eINSTANCE
val inchronModelFactory = ModelFactory.eINSTANCE
/*- Transformer classes initiaization */
@Inject extension SWTransformer swTransformer
@Inject extension HWTransformer hwTransformer
@Inject extension OSTransformer osTransformer
@Inject extension StimuliTransformer stimuliTransformer
* This method performs the transformation of AMALTHEA model to INCHRON model and saves the transformed model in the output directory.
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) {"Processing file : " + resource.URI)
/*- Building INCHRON model from AMALTHEA input model */
val inchronRoot = transform(content as Amalthea)
val out_uri = URI.createFileURI(
getProperty("m2m_output_folder") + File.separator + fileIndex++ + ".root")
val out_resource = outputResourceSet.createResource(out_uri)
/*-Attaching a resource to the INCHRON model element */
/*- Saving all the root INCHRON model files*/
for (resource : outputResourceSet.resources) {"Transformed model file generated at : " + resource.URI)
}"*********************** Completed : Model to Model transformation **************************")
* This method is used to transform AMALTHEA model to INCHRON model
def create inchronRootFactory.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 */
model = createInchronModel(amalthea)
* This method creates the object of INCHRON Model element, and fills it by invoking various transformations
def create inchronModelFactory.createModel createInchronModel(Amalthea amalthea) {
setRequiredAttributes(amalthea, it)
* Each transformation object should be set with the required attributes.
* At present the required attributes are : amaltheaModel and inchronModel elements. In future this list can grow
protected def EObject setRequiredAttributes(Amalthea amalthea, Model inchronModel) {
* Overriding the logger creation method and attaching "ConsoleAppender" to it.
override protected getLogger() {
var logger=super.getLogger()
return logger