Example: MDD-TIF complete case study

<?xml version="1.0"?>
<project default="main">
  
  <epsilon.emf.register file="../metamodels/CompetitionDsl.ecore"/>
  <epsilon.emf.register file="../metamodels/TVAppDsl.ecore"/>
    
  <epsilon.emf.loadModel name="Competition"
                               modelFile="models/WorldCup.model"
                               metamodelUri="CompetitionDsl"
                               read="true" store="false"/>
  
  <epsilon.emf.loadModel name="TVApp"
                               modelFile="models/TVApp3.model"
                               metamodelUri="TVAppDsl"
                               read="false" store="true"/>

  <target name="main">
    <epsilon.evl src="ValidateCompetition.evl">
      <model ref="Competition"/>
    </epsilon.evl>    
    
    <epsilon.etl src="Competition2TVApp.etl">
      <model ref="TVApp"/>
      <model ref="Competition"/>
    </epsilon.etl>
  </target>
  
</project>
rule Competition2Application
  transform c : Competition!Competition
  to a : TVApp!Application, v : TVApp!Vote {

  a.name = c.name + " Application";
  v.name = "Who will win the " + c.name + "?";  
  a.contents.add(v);
  
  for (g in c.groups) {
    v.contents.add(g.equivalent());
    for (comp in g.competitors) {
      v.contents.add(comp.equivalent());
    }
  }
}

rule Competitor2Choice
  transform co : Competition!Competitor
  to ch : TVApp!Choice {

  ch.name = co.name;
  
}

rule Group2Label
  transform g : Competition!Group
  to l : TVApp!Label {
  
  l.name = "Group " + g.name;
}
context Competition!NamedElement {
  
  constraint NameSpecified {
    
    check : self.name.isDefined() and self.name.trim().length > 0
    
    message : self.eClass().name + " must provide a name"
    
  }
  
}

context Competition!Group {
  
  constraint NotEmpty {
    
    guard : self.satisfies("NameSpecified")
    
    check : self.competitors.size() > 0
    
    message : "Group " + self.name + " contains no competitors"
    
  }
  
}

context Competition!Competitor {
  
  constraint InUniqueGroup {
    
    guard : self.satisfies("NameSpecified")
    
    check : Competition!Group.allInstances.
      select(g|g.competitors.includes(self)).size() <= 1
    
    message : "Competitor " + self.name + 
      " exists in more than one groups."
  }
  
}

Check out the code from the SVN:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.examples.mddtif project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.examples.mddtif project
  2. right click the .launch file in the org.eclipse.epsilon.examples.mddtif project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example, we demonstrate how different languages in Epsilon (EVL, EGL, EML, ETL and ECL) can be combined to implement more complex operations.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

More examples are available in the examples folder of the SVN repository.