Presentasjon lastes. Vennligst vent

Presentasjon lastes. Vennligst vent

Model til tekst transformasjoner med MOFScript

Liknende presentasjoner


Presentasjon om: "Model til tekst transformasjoner med MOFScript"— Utskrift av presentasjonen:

1 Model til tekst transformasjoner med MOFScript

2 MOFScript Brukes for å generere tekst fra modeller (f.eks. kode, dokumentasjon) Delvis imperativt og delvis deklarativt Regelebasert språk Plugin til eclipse

3 Bruk av MOFScript For å skrive et MOFScript program lager man en fil som har extensionen ’.m2t’. En vil da få MOFScript funksjonaliteten tilgjengelig. Metamodeller som skal benyttes legges i mappa ’eclipse\plugins\org.sintef.mofscript.editor_1.1.11\repository\metamodels’.

4 Bruk av MOFScript Output directory for transformasjonen settes ved å høyreklikke på MOFScript fila, velge Properties, og deretter sette en path i Select Root Output Directory propertiet under MOFScript. Input modellen (den modellen det skal genereres tekst fra velges første gang transformasjonen kjøres)

5 Eksempel: Generere SQL kode fra relational modellen vi genererte forige øvingstime

6 Metamodellen

7 Inputmodellen

8 relational2sql.m2t texttransformation relationalModel2sql (in relational : " property fileExtension = '.sql' relational.DBModel::main(){ stdout.println( 'starting transformation ' ) self.mapDBModel() }

9 relational2sql.m2t relational.DBModel::mapDBModel(){
file(self.name + fileExtension) '\nCREATE DATABASE ' self.name ';' self.tables -> forEach( table:relational.Table ){ table.mapTable() }

10 relational2sql.m2t relational.Table::mapTable(){
'\n\nCREATE TABLE ' self.name '(' self.columns -> forEach ( col:relational.Column ){ col.mapColumn() if( !self.columns.last() == col ){ ',' } '\n);'

11 relational2sql.m2t relational.Column::mapColumn(){
'\n\t' self.name ' ' self.type.mapType() if( self.keyOf != null ){ ' PIMARY KEY NOT NULL' }

12 relational2sql.m2t relational.Type::mapType(){
if(self.name.equalsIgnoreCase("INTEGER")){ 'INT' }else if( self.name.equalsIgnoreCase("STRING")){ 'VARCHAR(255)' }

13 Resultatet CREATE DATABASE ScoolSystem; CREATE TABLE Student(
StudentId INT PIMARY KEY NOT NULL, name VARCHAR(255), age INT ); CREATE TABLE Course( courseName VARCHAR(255), courseLocationID INT, CourseId INT PIMARY KEY NOT NULL CREATE TABLE CourseLocation( CourseLocationId INT PIMARY KEY NOT NULL, buildingName VARCHAR(255), roomNr INT CREATE TABLE Adresses( Adresses VARCHAR(255) CREATE TABLE Student_courses( coursesId INT PIMARY KEY NOT NULL

14 Tekst vs Model CREATE DATABASE ScoolSystem; CREATE TABLE Student(
StudentId INT PIMARY KEY NOT NULL, name VARCHAR(255), age INT ); CREATE TABLE Course( courseName VARCHAR(255), courseLocationID INT, CourseId INT PIMARY KEY NOT NULL CREATE TABLE CourseLocation( CourseLocationId INT PIMARY KEY NOT NULL, buildingName VARCHAR(255), roomNr INT CREATE TABLE Adresses( Adresses VARCHAR(255) CREATE TABLE Student_courses( coursesId INT PIMARY KEY NOT NULL


Laste ned ppt "Model til tekst transformasjoner med MOFScript"

Liknende presentasjoner


Annonser fra Google