EMF Demo

来源:互联网 发布:浙江大学人工智能 编辑:程序博客网 时间:2024/06/10 05:04

Install EMF Plugin of Eclipse

Ecore Diagram Editor

Create EMF Project

Take "Empty EMF Project" for instance

Create Ecore Model

New "Ecore Model" under folder "model"

Create "EPackage", "EInterface", "EClass", "EEnum"

Create "EReference", "EAttribute", "EOperation"


Open With "XML Editor"
<?xml version="1.0" encoding="UTF-8"?><ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="fruit" nsURI="http:///fruit.ecore" nsPrefix="fruit">  <eClassifiers xsi:type="ecore:EClass" name="Fruit" abstract="true" interface="true">    <eOperations name="grow">      <eParameters name="years" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>    </eOperations>    <eOperations name="harvest" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject">      <eParameters name="amount" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>    </eOperations>    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>    <eStructuralFeatures xsi:type="ecore:EAttribute" name="weight" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>  </eClassifiers>  <eClassifiers xsi:type="ecore:EClass" name="Apple" eSuperTypes="#//Fruit">    <eOperations name="appleColor" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>    <eStructuralFeatures xsi:type="ecore:EAttribute" name="color" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>  </eClassifiers>  <eClassifiers xsi:type="ecore:EClass" name="Pear" eSuperTypes="#//Fruit">    <eOperations name="pearWater" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>    <eStructuralFeatures xsi:type="ecore:EAttribute" name="water" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>  </eClassifiers>  <eClassifiers xsi:type="ecore:EClass" name="Factory">    <eOperations name="create" eType="#//Fruit">      <eParameters name="fruitKind" eType="#//FruitKind"/>    </eOperations>  </eClassifiers>  <eClassifiers xsi:type="ecore:EEnum" name="FruitKind">    <eLiterals name="APPLE" value="1"/>    <eLiterals name="PEAR" value="2"/>    <eLiterals name="PEACH" value="3"/>  </eClassifiers></ecore:EPackage>

Create EMF Generator Model

New "EMF Generator Model" via loading above "Ecore Model" file

Open With "EMF Generator"


Generate Model Code

Select "generate * Code"



After do "Generate Model Code", you can see model code as below:


Install UML Plugin of Eclipse

UML Designer

Export UML Model

Click "Export Model..."


Choose "UML model"


Finally you can see UML Model file as below:

Generate Ecore Diagram

Right click "Initialize Ecore Diagram..."



Select a representation type



Select a semantic element


Select all and navigate to class diagram



Add Related Elements



Select all Related Elements



Layout Diagram



Finally you can see diagram as below:

Export diagram as image



0 0
原创粉丝点击