Sunday, March 23, 2008

How do ccpn data models get written

Here are my brief results from digging around the ccpn data-model production software (v2.1) from source forge to see how data-model writing gets carried out (note these are my random doodlings and may not represents how it really works i.e. ymmv)

  1. you call python makeJavaApi.py from the command line which lives in ccpn/python/memops/scripts_v2
  2. This then uses XmlModelIo.readModel() to read the pure ccpn metamodel which returns the root meta-package as its result
  3. a thing called the ModelPortal gets constructed from the meta-model. (This seems to provide functions that access the meta-model in particular ways, examples include for example leafPackagesByImport - leaf packages sorted by import (imported before importing), dataTypesByInheritance - data types sorted by inheritance (supertype before subtype), dataObjTypesAlphabetic - data types sorted alphabetically by name etc...)
  4. JavaFileModelAdapt.processModel(modelPortal) processes the model-portal (and its owned meta-model) to adapt it to the idiosyncrasies of the requirements of the java language
  5. the class method JavaFileApiGen.writeApi gets called with the model-portal as its first parameter and information in the other parameters about where to store the model the version.
  6. finally inside JavaFileApiGen.writeApi we do some more setup create a JavaFileApiGen object and then call processModel() on it this then calls a general meta-model traverser which is in the class ModelTraverse.processModel
  7. now comes the interesting bit! This then causes a series of callbacks on the JavaFileApiGen class to be called. Using the following hack I think I can work out most of them...
    grep def ../metamodel/ModelTraverse_py_2_1.py | tr '(' ' ' | awk '{print $2}'
  8. this then visits the following list of apparently interesting methods
    • processBranchPackage
    • initLeafPackage
    • processLeafPackage
    • endLeafPackage
    • processDataType
    • processConstant
    • processException
    • initClass
    • processClass
    • endClass
    • initDataObjType
    • processDataObjType
    • endDataObjType
    • processAttribute
    • processRole
    • initOperation
    • processOperation
    • endOperation
    • processParameter
    which seem to correspon well with the parts of the datamodel... ;-)

No comments: