JeeWiz Home  
The Model-Driven System Builder

JeeWiz Architect's Guide
 
Contents  >   2.  Overview
 


2.3 Meta-Classes and Meta-models

 2.3.1  Meta-Classes
 2.3.2  Standard Features of Meta-Classes
 2.3.2.1      Standard Properties
 2.3.2.2      Standard Methods
 2.3.2.3      Extra Properties
 2.3.3  Meta-models
 2.3.4  Meta-models are Models
 2.3.5  Lists of Strings
 2.3.6  Other Features
 2.3.7  The M words

2.3.1  Meta-Classes
When JeeWiz reads a model, it converts it into a tree of Java objects. The Java objects that represent a model at generate-time are called 'model objects', and they are instances of 'meta-classes'. The mapping is as follows:
  • Each element in the input XML becomes a Java object (the model object). Normally, the type of the object created (i.e. its meta-class) will be determined by the element tag: <application> elements turn into instances of the Application meta-class, and so on.
  • Each attribute on an element becomes a property on the Java object (using JavaBean get/set conventions to access it)
  • Character data is stored in the special 'text' property on the Java object
  • Nested elements are collected into lists using the role as the name of the list - in the majority of cases, the role is the same as the type of the nested element.


This mapping, and the detailed implementation, are copied from Ant's approach to mapping XML to Java objects.
2.3.2  Standard Features of Meta-Classes
All meta-classes eventually inherit from a base meta-class class, which provides the following features.
2.3.2.1  Standard Properties
The base meta-class has the following properties. They are available via getters and setters (e.g getName() and setName("n"). They can also be overridden in a meta-class definition; for example, the name property in the base is optional, but many meta-classes override the name property to make it required.
  • name
  • description
  • template (which template to use to render instances of this meta-class)
  • text - the nested character data, represented as a single string
  • jwPattern (the pattern or patterns to apply to this object)
  • base-text - used to build wizard pages (Deprecated).

2.3.2.2  Standard Methods
There is an extensive list of filtering and helper methods available from the base meta-class class. See Helper Methods for details.

2.3.2.3  Extra Properties
The base meta-class has an attached 'properties' HashMap. This is used to hold extra values that are not present in the meta-model, but are useful during model construction and read-in. Properties can be set in a number of ways:
  • unmodeled attributes in the input
  • standard names that are built into the JeeWiz engine:
    • this - a reference to the current model object
    • parent - the parent of this (but this is not set for the top-most or root element)
  • per-meta-class property calculations ('component.properties'), which we discuss later
  • from Velocity - #set( $this.p="v" ) will put a property 'p', value 'v' into the HashMap
Note that 'this' and 'parent' above are objects. In other words, the properties HashMap isn't restricted to String values. It can store references to meta-classes and any other sort of object. Velocity renderings often construct ArrayLists or HashMaps and store them as extra properties.

Once set, properties are referenced from Velocity just like any other property. As with Java, Velocity supports multiple references through these objects:
$parent.parent.name
will substitute the name of our parent's parent.

2.3.3  Meta-models
A meta-model is a model that describes the Java classes that are used to read in models. In other words, a meta-model is a specification of the information that can be used in a model.

This is analogous to class definitions in Java, where the class definition tells us what information may appear in an instance of the class.

For example, here is the XML version of a model for an entity in JeeWiz:
<entity           name="Customer">
  <attribute      name="surname"/>
</entity>
This tells us that there is a Customer entity and it has a name attribute. Here is a fragment of meta-model that tells us we can write this model:
<meta-model>
   <meta-class     name="entity">
      <list          name="attribute" />
   </meta-class>
   <meta-class     name="attribute">
      <property      name="name"
                     required="true"
                     />
      <property      name="type"
                     default="String"
                     >
   </meta-class>
</meta-model>
This tells us that in a model governed by this meta-model:

  • there can be instances of the 'entity' meta-class in the XML, which would turn into Java-based entity model objects when the model is read in
  • the entity can have a list of attributes - i.e. nested <attribute elements>
  • there can be attribute elements, with name and type properties.
  • the name property on an attribute is required
  • the default for the type property is 'String'.

2.3.4  Meta-models are Models
Meta-models have all the features of other models - they are used in exactly the same way as other models:
  • the meta-model is expressed using exactly the same style as other models - XML tags, attributes etc.
  • the JeeWiz process creates generate-time object instances representing the model or meta-model
  • a JeeWiz rendering is done to create the output. For a meta-model, the output is the Java classes that are used when the appropriate model is read in.
The main difference between meta-models and normal models is the source of the Java classes. For meta-models, these are built into the JeeWiz engine; for normal models, the Java classes are the output of the meta-model generation, as shown by the green arrow.

[ By the way, if you find the meta-model distinction/similarity confusing, this is quite natural. The best approach to getting it straight is to think about this operationally: a meta-model is there to define the Java classes for reading 'normal' models. ]

There is a special language for meta-models. The key parts are:
  • A meta-model has the <meta-model> element as its root. This defines overall characteristics of the meta-model.
  • The Java classes to be generated are modeled as <meta-class> elements nested within the <meta-model>. A meta-class has a name, which is capitalised to form the name of the Java class.
  • A meta-class has 'properties' - <property> nested elements. These define the fields in the generated Java class.
  • Contained relationships to other objects are specified by <list> elements, also nested within the meta-class. There are powerful features of lists to automatically create indexes, lists of subclassed elements, uniqueness checks and so on.
  • A meta-class can also contain character data. Character data in meta-models is inserted into the generated Java class, where it becomes the hand-written part of the implementation.
  • An important feature is the ability to define validation directly in the meta-model, using Java expressions. The Java expressions can also use helper methods in the meta-model of the current meta-class or others. Validation of models is essential to make the overall system usable, because generation systems will have restrictions on the structure of models.
  • Finally, there is a special <meta-factor>. This is also nested underneath the <meta-model> element, and defines properties, lists and character data that are common to many meta-classes. JeeWiz aggregates the model factors into meta-classes. This means that a model factor only needs to be defined once, simplifying maintenance.
By using the same overall structure to generate meta-models classes as other models, we simplify the construction and maintenance of the meta-models, which in some cases are complex. (This is just the same argument as for using JeeWiz in other domains!) Approximately 80% of the Java code for the standard meta-models is generated from the meta-model elements.
2.3.5  Lists of Strings
We have discussed lists as relationships to other meta-classes. It is also possible to define lists whose item values are Strings. In generating the Java classes for the meta-class, JeeWiz renders these specially so that they can be specified in two ways:
  • as nested elements, using the name of the list as the element tag values, e.g.
    <mo>
       <style>styleA</style>
       <style>styleB</style>
    </mo>
  • as a comma-separated list in one string property, e.g.
    <mo   style="styleA,styleB" />
    Note that there is no escape character: if you want to put a ',' in an item, you need to use the nested element approach.
For referencing these values, getters are generated to read the list as a single string ("styleA,styleB") or as a list of strings.
2.3.6  Other Features
As well as the rendering to generate Java classes as described above, meta-model renderings are also available to create:
  • detailed documentation. For example, the JeeWiz Meta-Model Reference chapter is generated this way.
  • modeling plug-ins, e.g. the UML plug-in for Rational Rose.

2.3.7  The M words
The OMG has define a framework for data and meta-data in the MOF specification. This section relates the JeeWiz structure to that framework. The levels of 'meta-ness' are given numbers, and the level is referred to as M0, M1, M2 and M3.
Mi What is it JeeWiz format Manual name Example
M0 Instance of data XML - <Customer name="Joe Bloggs"/>
M1 Model object XML Model Model object <entity name="Customer"/>
M2 Meta-Model object XML Meta-Model Meta-class <meta-class name="entity"/>
M3 Meta-Meta-Model object Built-in - <meta-class name="meta-class"/>
You may well use JeeWiz to work with the first three levels:
  • you can use JeeWiz to process XML data into other formats
  • models created by your development team (e.g. UML models) will be converted into 'native format' JeeWiz XML models (or specifications). When the model is read in at generate time, a "model object" defined in Java is created.
  • you may write your own meta-models or enhance existing ones using XML and Java.
Although the M3 level is built-in to the engine, so you can't affect it directly, there is a meta-model for it, just like other meta-models (in jeewiz/resources/JeeWiz/specification - this is used to generate the detailed documentation).  


Copyright (c) 2001-2008 New Technology/enterprise Ltd.