Wizzi models

Wizzi models are javascript objects, inspired by Xml document objects, that can load mTrees , applying a type to their nodes.

To be loaded in a Wizzi model an mTree node structure must be conformant to the Wizzi schema of the model.

Wizzi models are software artifacts generated by artifact generators of the `wizzi-core` plugin. From a 'wfschema' are generated:

  • a Wizzi Model javascript module
  • a Wizzi model factory javascript module
  • a JSON documentation file.

Wizzi model artifact generators and links to source code

artifact output file name source code
wfschema/factory {schema-name}-factory.g.js ittf javascript
wfschema/model {schema-name}-model.g.js ittf javascript
wfschema/json_docs {schema-name}-schema.g.json ittf javascript
Wizzi models generation

Wizzi models are generated calling the 'generateModelTypes' method of an instance of the wizzi.WizziFactory class, instantiated with the ` wizzi-core `, wizzi-js `, wizzi-web ` plugins.

The wizzi.WizziFactory.generateModelTypes method.

                    
1 ...
2 m generateModelTypes
3 string wfschemaIttfDocumentUri
4 # The full path to the primary ITTF document of the `wfschema` declaration.
5 string outputPackagePath
6 # The full path of the package folder where the generated artifacts will be written
7 string wfschemaName
8 # The schema name, for composing the names of the generated artifacts
9 { mTreeBuildUpContext
10 # An object that will be the evaluation context object
11 # during the mTree processing of the `wfschema` ITTF document
12 callback
13 # Returns error or null
The Wizzi Model module

A Wizzi model module contains a javascript class for each element defined in its 'wfschema' and some standard base classes.

Wizzi model classes

wzSourceLineInfo source map item with source file path, row, col of a node
{schema-name}Exception exception object for this Wizzi Model
{schema-name}Context context object for the methods wzInitialize and wzVerify
{schema-name}Base base class for all element classes
{element-name} one class for each element of the `wfschema`

 

The wzSourceLineInfo API

                    
1 class wzSourceLineInfo
2 ctor
3 integer row
4 # 1-based row position of the source ittf node
5 integer col
6 # 1-based column position position of the source ittf node
7 string sourceKey
8 # Key to the source ittf document infos stored in the 'loadHistory' object
9 # The 'loadHistory' is a property of the root element
10 m toString
11 { elementInstance?
The `schema-name`Exception API

                    
1 class `schema-name`Exception
2 ctor
3 string message
4 { ittfNode
5 { elementInstance
The `schema-name`Context API

                    
1 class `schema-name`Context
2 boolean schemaIsValid
3 m addError
4 string message
5 { mTreeNode
6 m verifyEnum
7 string valueType
8 string valueName
9 string value
10 [ allowed
11 string allowedValue
12 { mTreeNode
The `schema-name`Base API

                    
1 class `schema-name`Base
2 string wzName
3 string wzTag
4 [ wzChildren
5 ctor
6 string name
7 # the node-value of the source mTreeNode
8 # that becomes the 'wzName' of the newly created element
9 { sourceLineInfo
10 api-ref wizzimodel.wzSourceLineInfo
11 m wzRoot
12 # Return the model root element instance
13 m wzSourceFilepath
14 # Returns the filepath of an ittf source document given its 'sourceKey'
15 string sourceKey
16 m wzAddChild
17 # Add a child node to the wzChildren collection
18 { elementInstance
19 m wzLoadToChildColl
20 # Creates a new element instance given the type of its source mTreeNode
21 # Append it to the collection passed as parameter.
22 # Call the loadFromNode method of the newly created element
23 # with the source mTreeNode as argument.
24 { mTreeNode
25 # the mTreeNode that we are loading
26 { type
27 # the javascript class of the Wizzi Model element
28 # that is the type for mTreeNode given its node-name
29 { coll
30 # the collection to which the newly created element should be appended
31 m wzLoadToChildren
32 # Creates a new element instance given the type of its source mTreeNode
33 # Append it to the wzChildren collection.
34 # Call the loadFromNode method of the newly created element
35 # with the source mTreeNode as argument.
36 { mTreeNode
37 { type
38 m wzLoadOneToOne
39 # Creates a new element instance given the type of its source mTreeNode
40 # Assign it to the `fieldName` property.
41 # Call the loadFromNode method of the newly created element
42 # with the source mTreeNode as argument.
43 { mTreeNode
44 { type
45 string fieldName
46 m error
47 # throw a `schema-name`Exception
48 string message
49 { mTreeNode
The `element-name` API

                    
1 class `element-name`
2 m loadChild
3 # Tests if the mTreeNode name is a valid child element or attribute.
4 # If yes call the proper add method and return true.
5 # If no return false.
6 { mTreeNode
7 m loadFromNode
8 # Calls the loadChild method on this element
9 # for each child node of the mTreeNode to load.
10 { mTreeNode
11 m wzInitialize
12 # Initialize the element
13 # Called after the source mTree has been succesfully loaded.
14 param ctx
15 api-ref `schema-name`Context
16 m wzVerify
17 # Verify if the element is valid
18 # Called after the wzInitialize method.
19 { ctx
20 api-ref `schema-name`Context
Wizzi model factory module

The javascript module `schema-name`-factory.g.js exports the method 'createLoadModel', that is an HOF that returns the 'loadModel' function. It must be called passing the 'wizzi' object.

The `schema-name`-factory.g.js API

We have seen already this api in the 'plugin' documentation.


                    
1 {
2 func createLoadModel
3 # HOF : returns the loadModel function for the given factory
4 { wizziObject
5 func loadMTree
6 api-ref wizzi-mtree.loader.loadMTree
7 # This function is prepared by the wizzi.WizziFactory instance class
8 # and has repository access functions and load options in its closure.
9 { file
10 api-ref wizzi.util.file
11 { errors
12 api-ref wizzi.errors
13 ...
14 return
15 func loadModel
16 # This returned function require a complex 'loadContext'
17 # parameter with a lot of interfaces passed.
18 # It will be called by the wizzi.WizziFactory instance and
19 # not directly from client code.
20 string ittfDocumentUri
21 # The path to the primary ittf document from which
22 # the mTree will be loaded
23 { loadContext
24 { __productionManager
25 api-ref wizzi.production.productionManager
26 { productionContext
27 api-ref wizzi.production.productionContext
28 { aclstat
29 api-ref wizzi.production.aclstat
30 { __ittfDocumentStore
31 api-ref wizzi-repo.ittfDocumentStore
32 { mTreeBuildUpContext
33 optional
34 | api-ref wizzi-plugin.wizziModel
35 | POJO
36 callback