ModelManager (Common API)

Overview - Common API - Client API - Admin API - Runtime API

ModelManager

Manages the Composer model files.

The structure of Resources (Assets, Transactions, Participants) is modelled in a set of Composer files. The contents of these files are managed by the ModelManager. Each Composer file has a single namespace and contains a set of asset, transaction and participant type definitions.

Composer applications load their Composer files and then call the addModelFile method to register the Composer file(s) with the ModelManager. The ModelManager parses the text of the Composer file and will make all defined types available to other Composer services, such as the Serializer (to convert instances to/from JSON) and Factory (to create instances).

Details

  • Module common

Method Summary

Name Returns Description
addDecoratorFactory void Add a decorator factory to this model manager
addModelFile Object Adds a Composer file (as a string) to the ModelManager
addModelFiles Object[] Add a set of Composer files to the model manager
clearModelFiles void Remove all registered Composer files
deleteModelFile void Remove the Composer file for a given namespace
getAssetDeclarations AssetDeclaration[] Get the AssetDeclarations defined in this model manager
getConceptDeclarations ConceptDeclaration[] Get the Concepts defined in this model manager
getDecoratorFactories DecoratorFactory[] Get the decorator factories for this model manager
getEnumDeclarations EnumDeclaration[] Get the EnumDeclarations defined in this model manager
getEventDeclarations EventDeclaration[] Get the EventDeclarations defined in this model manager
getFactory Factory Get a factory for creating new instances of types defined in this model manager
getNamespaces string[] Get the namespaces registered with the ModelManager
getParticipantDeclarations ParticipantDeclaration[] Get the ParticipantDeclarations defined in this model manager
getSerializer Serializer Get a serializer for serializing instances of types defined in this model manager
getSystemTypes ClassDeclaration[] Get all class declarations from system namespaces
getTransactionDeclarations TransactionDeclaration[] Get the TransactionDeclarations defined in this model manager
updateExternalModels Promise Downloads all ModelFiles that are external dependencies and adds or updates them in this ModelManager
updateModelFile Object Updates a Composer file (as a string) on the ModelManager
validateModelFile void Validates a Composer file (as a string) to the ModelManager
validateModelFiles void Validates all models files in this model manager

Method Details

validateModelFile

validateModelFile( string modelfile, string filename )

Validates a Composer file (as a string) to the ModelManager. Composer files have a single namespace. Note that if there are dependencies between multiple files the files must be added in dependency order, or the addModelFiles method can be used to add a set of files irrespective of dependencies.

Parameters

Name Type Mandatory Description
modelFile string Yes The Composer file as a string
fileName string Yes an optional file name to associate with the model file

addModelFile

Object addModelFile( string modelfile, string filename, [boolean disablevalidation] )

Adds a Composer file (as a string) to the ModelManager. Composer files have a single namespace. If a Composer file with the same namespace has already been added to the ModelManager then it will be replaced. Note that if there are dependencies between multiple files the files must be added in dependency order, or the addModelFiles method can be used to add a set of files irrespective of dependencies.

Returns

Object - The newly added model file (internal).

Parameters

Name Type Mandatory Description
modelFile string Yes The Composer file as a string
fileName string Yes an optional file name to associate with the model file
disableValidation boolean Yes If true then the model files are not validated

updateModelFile

Object updateModelFile( string modelfile, string filename, [boolean disablevalidation] )

Updates a Composer file (as a string) on the ModelManager. Composer files have a single namespace. If a Composer file with the same namespace has already been added to the ModelManager then it will be replaced.

Returns

Object - The newly added model file (internal).

Parameters

Name Type Mandatory Description
modelFile string Yes The Composer file as a string
fileName string Yes an optional file name to associate with the model file
disableValidation boolean Yes If true then the model files are not validated

deleteModelFile

deleteModelFile( string namespace )

Remove the Composer file for a given namespace

Parameters

Name Type Mandatory Description
namespace string Yes The namespace of the model file to delete.

addModelFiles

Object[] addModelFiles( modelfiles, [ filenames], [boolean disablevalidation] )

Add a set of Composer files to the model manager.

Returns

Object - The newly added model files (internal).

Parameters

Name Type Mandatory Description
modelFiles Yes An array of Composer files as strings.
fileNames Yes An optional array of file names to associate with the model files
disableValidation boolean Yes If true then the model files are not validated

validateModelFiles

validateModelFiles( )

Validates all models files in this model manager

Parameters

No parameters

updateExternalModels

Promise updateExternalModels( [Object options], [ModelFileDownloader modelfiledownloader] )

Downloads all ModelFiles that are external dependencies and adds or updates them in this ModelManager.

Returns

Promise - a promise when the download and update operation is completed.

Parameters

Name Type Mandatory Description
options Object Yes Options object passed to ModelFileLoaders
modelFileDownloader ModelFileDownloader Yes an optional ModelFileDownloader

clearModelFiles

clearModelFiles( )

Remove all registered Composer files

Parameters

No parameters

getNamespaces

string[] getNamespaces( )

Get the namespaces registered with the ModelManager.

Returns

string - namespaces - the namespaces that have been registered.

Parameters

No parameters

getSystemTypes

ClassDeclaration[] getSystemTypes( )

Get all class declarations from system namespaces

Returns

ClassDeclaration - the ClassDeclarations from system namespaces

Parameters

No parameters

getAssetDeclarations

AssetDeclaration[] getAssetDeclarations( Boolean includesystemtype )

Get the AssetDeclarations defined in this model manager

Returns

AssetDeclaration - the AssetDeclarations defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getTransactionDeclarations

TransactionDeclaration[] getTransactionDeclarations( Boolean includesystemtype )

Get the TransactionDeclarations defined in this model manager

Returns

TransactionDeclaration - the TransactionDeclarations defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getEventDeclarations

EventDeclaration[] getEventDeclarations( Boolean includesystemtype )

Get the EventDeclarations defined in this model manager

Returns

EventDeclaration - the EventDeclaration defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getParticipantDeclarations

ParticipantDeclaration[] getParticipantDeclarations( Boolean includesystemtype )

Get the ParticipantDeclarations defined in this model manager

Returns

ParticipantDeclaration - the ParticipantDeclaration defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getEnumDeclarations

EnumDeclaration[] getEnumDeclarations( Boolean includesystemtype )

Get the EnumDeclarations defined in this model manager

Returns

EnumDeclaration - the EnumDeclaration defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getConceptDeclarations

ConceptDeclaration[] getConceptDeclarations( Boolean includesystemtype )

Get the Concepts defined in this model manager

Returns

ConceptDeclaration - the ConceptDeclaration defined in the model manager

Parameters

Name Type Mandatory Description
includeSystemType Boolean Yes Include the decalarations of system type in returned data

getFactory

Factory getFactory( )

Get a factory for creating new instances of types defined in this model manager.

Returns

Factory - A factory for creating new instances of types defined in this model manager.

Parameters

No parameters

getSerializer

Serializer getSerializer( )

Get a serializer for serializing instances of types defined in this model manager.

Returns

Serializer - A serializer for serializing instances of types defined in this model manager.

Parameters

No parameters

getDecoratorFactories

DecoratorFactory[] getDecoratorFactories( )

Get the decorator factories for this model manager.

Returns

DecoratorFactory - The decorator factories for this model manager.

Parameters

No parameters

addDecoratorFactory

addDecoratorFactory( DecoratorFactory factory )

Add a decorator factory to this model manager.

Parameters

Name Type Mandatory Description
factory DecoratorFactory Yes The decorator factory to add to this model manager.

Inherited methods