The Model-Driven System Builder
JeeWiz Architect's Guide
2.3 Meta-Classes and Meta-models
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.
All meta-classes eventually inherit from a base meta-class class, which provides the following features.
2.3.2 Standard Features of Meta-Classes|
188.8.131.52 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.
- 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).
184.108.40.206 Standard Methods|
There is an extensive list of filtering and helper methods available from the base meta-class class.
See Helper Methods
220.127.116.11 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:
will substitute the name of our parent's parent.
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:
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:
This tells us that in a model governed by this meta-model:
<list name="attribute" />
- 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'.
Meta-models have all the features of other models -
they are used in exactly the same way as other models:
2.3.4 Meta-models are Models|
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.
- 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.
[ 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:
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.
- 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.
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:
2.3.5 Lists of Strings|
For referencing these values, getters are generated to read the list as a single string ("styleA,styleB") or as a list of strings.
- as nested elements, using the name of the list as the element tag values, e.g.
- as a comma-separated list in one string property, e.g.
Note that there is no escape character: if you want to put a ',' in an item, you need to use the nested element approach.
<mo style="styleA,styleB" />
As well as the rendering to generate Java classes as described above, meta-model renderings are also available to create:
2.3.6 Other Features|
- 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.
The OMG has define a framework for data and meta-data in the
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.
2.3.7 The M words|
You may well use JeeWiz to work with the first three levels:
||What is it
||Instance of data
||<Customer name="Joe Bloggs"/>
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).
- 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.
Copyright (c) 2001-2008 New Technology/enterprise Ltd.