Using EMF to build a model and generate Java code __java

Source: Internet
Author: User

Connect above: http://blog.csdn.net/qinjienj/article/details/6851112


EMF actually defines 2 kinds of meta model, called Ecore and Genmodel, respectively. Ecore contains the definition of the model, and we do this by creating a new and edited Ecore file when we create the EMF model. Genmodel contains information about the automatic generation of Java code (the Pojo class of the model), such as how to generate Pojo, and where the resulting pojo are placed. When the Ecore is modified, the Genmodel automatically gets the update.


Create an EMF project (or plugin project), and then build a Ecore model.



Open the Properties view, define the name of model, namespace prefix, and namespace URL.



Right-click the new CSDN model and add the child.

The child has 5 types of support.

Eannotation is a combination of Teneo and hibernate as well as a mapping between database schemas;

Eclass refers to a class within a model;

The Edata type represents the types of data, such as int,float, or java.util.Date



I created a blog called Eclass, through the Properties view can modify this Eclass property, by right-clicking the blog, you can add a new child or sibling.

Where Ereference is a link to other eclass, such as a class member variable that can be used to define a blog class, or it can be understood as a foreign key in a database.




After Ecore is created, create a new Genmodel (EMF generator model) and choose Ecore model in the "New EMF generator Model" step



Select the Csdn.ecore you just created, and then click Load




After clicking Finish, Genmodel is finished.


You can configure Genmodel in the Properties view, such as base package to define which path the generated code will be placed under.



Right-clicking the generated Genmodel allows you to choose to generate a variety of code, where "Generate model code" generates model classes and other related Java classes.



The generated Java code is divided into 3 packages, model.csdn,model.csdn.impl,model.csdn.util.

The model package contains all the Eclass interface files (all interfaces are inherited from Eobject, so all Eclass are eobject subclasses), and very important csdnfactory files (for creating instances of Eclass files, The Einstance.createxxx () method of the factory class is the only way to create an instance, Csdnpackage file (containing the meta model for each class, each feature for each class, each enum, each data Type, note that this information is required to create a hibernate mapping file.

Model.impl package inside the model package is mainly the specific types of interface files;

There are adapterfactory inside the model.util bag.



< to Be continued >




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.