EMF Technology Research 2

Source: Internet
Author: User

Ecore Model AnalysisCurrently, there are four main ways to generate the ecore model. Here we use the UML model to generate the ecore model. First, we use rose to design the EMF package, and then create the following class diagram in the package: the generated ecore model is as follows <? 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 = "EMF" nsuri = "http: // EMF. ecore "nsprefix =" EMF "> <eclassifiers xsi: TYPE =" ecore: eclass "name =" customer "esupertypes =" # // element "> <estructuralfeatures xsi: type = "ecore: eattribute" name = "name" etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString"/> <estructuralfeatures xsi: TYPE = "ecore: ereference "name =" orders "upperbound ="-1 "etype =" # // order "Containment =" true "/> </eclassifiers> <eclassifiers xsi: type = "ecore: eclass" name = "order" esupertypes = "# // element"> <estructuralfeatures xsi: TYPE = "ecore: eattribute "name =" ID "etype =" ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//ELong "/> <estructuralfeatures xsi: TYPE =" ecore: eattribute "name =" price "etype =" ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EFloat "/> </eclassifiers> <eclassifiers xsi: TYPE =" ecore: eclass "name =" element "abstract =" true "> <estructuralfeatures xsi: TYPE =" ecore: eattribute "name =" bool "etype =" ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EBoolean "/> </eclassifiers> </ecore: epackage> Let's analyze this file: EpackageThe top-level element of the eore model is epackage, which matches the package in the UML model. The nsuri and nsprefix attributes of the epackage cannot be directly expressed in the UML model, the default values of these attributes are automatically generated based on the package name. The name attribute of the epackage is the same as that of the package in the UML model. <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 = "EMF"Nsuri = "http :/// EMF. Ecore "nsprefix =" EMF">... </Ecore: epackage> Eclass, eenum, edatatypeIn the UML model, the class and the eclass, eenum, and edatatype that can be matched depend on the stereotype of the class ). L if the type of the class in UML is null or interface, eclass is matched; l if the type of the class in UML is enumeration, eenum is matched; l if the type of the class in UML is datatype, it matches edatatype. In our UML model, the type of the Class Customer is null, so it matches eclass. <Eclassifiers Xsi: TYPE = "ecore: eclass"Name = "customer">... </eclassifiers> the class name is the name attribute. <eclassifiers xsi: TYPE = "ecore: eclass" Name = "customer">... </Eclassifiers> if this class has a parent class, you can EsupertypesSpecify: <eclassifiers xsi: TYPE = "ecore: eclass" name = "customer" Esupertypes = "# // element">... </Eclassifiers> if it is an abstract class, AbstractThe property is true. The default value is false. <eclassifiers xsi: TYPE = "ecore: eclass" name = "element" Abstract = "true">... </Eclassifiers> If the class version is interface, InterfaceThe property is true, and the default value is false. Eattribute and ereference UML Each attribute and eattribute in the class Match<Estructuralfeatures Xsi: TYPE = "ecore: eattribute"Name = "name" etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString"/> The Name Of The attribute in UML is the same as the name of the eattribute. <Estructuralfeatures xsi: TYPE = "ecore: eattribute" Name = "name"Etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString"/> the etype attribute of eattribute comes from the type of the attribute in UML, which must be a basic Java type, or the eenum or edatatype defined in the UML model. L. <estructuralfeatures xsi: TYPE = "ecore: eattribute" name = "name" Etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString"/>  UML Every link with arrows in the class (navigable Association ) And ereference Match<Estructuralfeatures Xsi: TYPE = "ecore: ereference"Name = "orders" upperbound = "-1" etype = "# // order" Containment = "true"/> the lowerbound and upperbound attribute values of ereference come from the level (multiplicty) associated with UML ). For example, if you specify that the level element is 0 .. 1, then the property lowerbound is 0, and upperbound is 1, if the order element is 0 .. n, the lowerbound attribute is 0, and the upperbound attribute is-1 (unbounded ). If the UML Association is aggregation and the containment of the target class is "by value", the containment attribute of ereference is true, and the default value is false. EoperationsIn the UML class diagram, each operation matches eoperations. For example, if the get and set methods of name are added to the customer, the code of the ecore model is as follows: <eoperations name = "getname" etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString "/> name attribute corresponds to the operation name, etype attribute corresponds to the type of the Operation Return Value. <Eoperations name = "setname"> <eparameters name = "name" etype = "ecore: edatatype http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eoperations> the eparameters sub-element corresponds to the operation parameter, its name attribute corresponds to the parameter name, And the etype attribute corresponds to the parameter type.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.