Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Texo/Runtime Model"

(New page: __TOC__ To Be Done)
 
Line 1: Line 1:
 
__TOC__  
 
__TOC__  
  
To Be Done
+
== Introduction ==
 +
 
 +
Runtime model access is very useful when trying to implement generic functions like export/import, security, archiving etc. Also when the model is explicitly used in the application then it can make sense to access model objects (entities) in a model-driven way.
 +
 
 +
To support a model-driven approach at runtime, Texo generates two extra java class files for each EPackage. These can be normally be found in the same package as the generated entities:
 +
* ModelPackage: provides access to the EPackage and its content
 +
* ModelFactory: contains factory methods to create instances of an EClassifier and for String conversion. In addition this class provides access to the model wrappers.
 +
 
 +
== Model Wrappers: the ModelObject ==
 +
 
 +
As noted in the previous section, the ModelFactory class contains so-called ModelWrappers. The model wrappers provides a 'model-face' on top of a pojo.
 +
 
 +
To illustrate this with the EMF library example. For the EMF Library EClass, the following is generated:
 +
* a Library java class (a true pojo)
 +
* a LibraryModelObject which can be found inside the generated LibraryModelFactory class
 +
 
 +
The Library java class will have methods like getName, getBooks, etc. The LibraryModelObject has three methods:
 +
* eClass(): returning the Library EClass
 +
* eGet(EStructuralFeature): to get the value of an EStructuralFeature
 +
* eSet(EStructuralFeature, Object): to set the value of an EStructuralFeature
 +
 
 +
== Access to the ModelFactory and ModelPackage ==
 +
 
 +
There are several ways to get to the ModelFactory or ModelPackage instance. The first method is to use the generated statics:
 +
<source lang="java">
 +
final LibraryModelFactory modelFactory = LibraryModelPackage.MODELFACTORY;
 +
final LibraryModelPackage modelPackage = LibraryModelPackage.INSTANCE;
 +
</source>
 +
 
 +
The other method is to use the ModelResolver. The ModelResolver roughly has the same meaning as the EMF EPackageRegistry. All initialized ModelPackage instances are present in the global ModelResolver instance.
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
Texo generates two types of java files:
 +
* pojo's without explicit model information
 +
* two Model* classes which provide runtime model access
 +
 
 +
Runtime mo

Revision as of 06:46, 7 March 2010

Introduction

Runtime model access is very useful when trying to implement generic functions like export/import, security, archiving etc. Also when the model is explicitly used in the application then it can make sense to access model objects (entities) in a model-driven way.

To support a model-driven approach at runtime, Texo generates two extra java class files for each EPackage. These can be normally be found in the same package as the generated entities:

  • ModelPackage: provides access to the EPackage and its content
  • ModelFactory: contains factory methods to create instances of an EClassifier and for String conversion. In addition this class provides access to the model wrappers.

Model Wrappers: the ModelObject

As noted in the previous section, the ModelFactory class contains so-called ModelWrappers. The model wrappers provides a 'model-face' on top of a pojo.

To illustrate this with the EMF library example. For the EMF Library EClass, the following is generated:

  • a Library java class (a true pojo)
  • a LibraryModelObject which can be found inside the generated LibraryModelFactory class

The Library java class will have methods like getName, getBooks, etc. The LibraryModelObject has three methods:

  • eClass(): returning the Library EClass
  • eGet(EStructuralFeature): to get the value of an EStructuralFeature
  • eSet(EStructuralFeature, Object): to set the value of an EStructuralFeature

Access to the ModelFactory and ModelPackage

There are several ways to get to the ModelFactory or ModelPackage instance. The first method is to use the generated statics:

final LibraryModelFactory modelFactory = LibraryModelPackage.MODELFACTORY;
final LibraryModelPackage modelPackage = LibraryModelPackage.INSTANCE;

The other method is to use the ModelResolver. The ModelResolver roughly has the same meaning as the EMF EPackageRegistry. All initialized ModelPackage instances are present in the global ModelResolver instance.




Texo generates two types of java files:

  • pojo's without explicit model information
  • two Model* classes which provide runtime model access

Runtime mo

Back to the top