home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / importer.tcl < prev    next >
Text File  |  1997-05-07  |  7KB  |  274 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)importer.tcl    /main/hindenburg/5
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)importer.tcl    /main/hindenburg/5   7 May 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12.  
  13. require wmt_util.tcl
  14. require fstorage.tcl
  15. require cgen_msg.tcl
  16.  
  17. global booleanOptions
  18. set booleanOptions    {    {-trace tracing 0} \
  19.                 {-debug debug 0} \
  20.                 {-time timing 0} \
  21.                 {-all importAll 0} \
  22.                 {-new importNew 0} \
  23.                 {-selected importSelected 0} }
  24.  
  25. # End user added include file section
  26.  
  27.  
  28. Class Importer : {GCObject} {
  29.     constructor
  30.     method destructor
  31.     method generateOopl
  32.     method generateSql
  33.     method getClassNames
  34.     method getFileNamesNotToGenerateFor
  35.     method getOoplFileTypesToGenerateFor
  36.     method getSqlFileTypesToGenerateFor
  37.     method import
  38.     method importAll
  39.     method importNew
  40.     method importSelected
  41.     method parseOptions
  42.     method supportsPersistentCodeGen
  43.     attribute sourceObjects
  44.     attribute targetObjects
  45.     attribute ooplFileTypes
  46.     attribute sqlFileTypes
  47.     attribute ooModel
  48.     attribute ooplModel
  49. }
  50.  
  51. constructor Importer {class this} {
  52.     set this [GCObject::constructor $class $this]
  53.     # Start constructor user section
  54.  
  55.     $this sourceObjects [CommandLineInterface::getSourceObjects]
  56.     $this targetObjects [CommandLineInterface::getTargetObjects]
  57.     $this ooplFileTypes [$this getOoplFileTypesToGenerateFor]
  58.     $this sqlFileTypes [$this getSqlFileTypesToGenerateFor]
  59.  
  60.     # End constructor user section
  61.     return $this
  62. }
  63.  
  64. method Importer::destructor {this} {
  65.     # Start destructor user section
  66.     # End destructor user section
  67. }
  68.  
  69. method Importer::generateOopl {this classes} {
  70.     # !! Implement this function !!
  71. }
  72.  
  73. method Importer::generateSql {this files} {
  74.     # !! Implement this function !!
  75. }
  76.  
  77. method Importer::getClassNames {this fileList} {
  78.     set result ""
  79.     set excludeNames [$this getFileNamesNotToGenerateFor]
  80.  
  81.     foreach file $fileList {
  82.         set fName [nt_get_name $file]
  83.         set fType [nt_get_type $file]
  84.  
  85.         if {[lsearch $excludeNames $fName] != -1} {
  86.         continue
  87.         }
  88.  
  89.         if {[lsearch [$this ooplFileTypes] $fType] != -1} {
  90.         if [catch {set names [fstorage::get_imp_from $file]} reason] {
  91.             puts stderr $reason
  92.             set names ""
  93.         }
  94.  
  95.         if {$names == ""} {
  96.             m4_warning $W_IMPFROM_NOT_SET $file $fName
  97.             set names $fName
  98.         }
  99.  
  100.         foreach nm $names {
  101.             if {[lsearch $result $nm] == -1} {
  102.             lappend result $nm
  103.             }
  104.         }
  105.         }
  106.     }
  107.  
  108.     return $result
  109. }
  110.  
  111. method Importer::getFileNamesNotToGenerateFor {this} {
  112.     return ""
  113. }
  114.  
  115. method Importer::getOoplFileTypesToGenerateFor {this} {
  116.     # !! Implement this function !!
  117. }
  118.  
  119. method Importer::getSqlFileTypesToGenerateFor {this} {
  120.     return ""
  121. }
  122.  
  123. method Importer::import {this} {
  124.     $this parseOptions
  125.     set cc [ClientContext::global]
  126.     set systemNameType [$cc levelNameAt System]
  127.     set phaseNameType [$cc levelNameAt Phase]
  128.     set prevPhaseV [[$cc currentPhase] previous [$cc currentConfig]]
  129.  
  130.     if [$prevPhaseV isNil] {
  131.         m4_error $E_NO_PREV_PHASE $phaseNameType
  132.         return
  133.     }
  134.  
  135.     set prevPhase [$prevPhaseV phase]
  136.     set prevPhaseNameType [$prevPhase name].[$prevPhase name]
  137.  
  138.     if {[$prevPhase type] != "ObjectDesign"} {
  139.         m4_error $E_WRONG_PREV_PHASE $prevPhaseNameType
  140.         return
  141.     }
  142.  
  143.     if {[catch {fstorage::goto_system $systemNameType $prevPhaseNameType} reason]} {
  144.         puts stderr $reason
  145.         return
  146.     }
  147.  
  148.     $this ooModel [OOModel::createModel]
  149.     $this ooplModel [[$this ooModel] ooplModel]
  150.  
  151.     fstorage::goto_system $systemNameType $phaseNameType
  152.  
  153.     if {[[$this ooModel] error] > 0} {
  154.         ##m4_error $E_LOAD_MODEL
  155.         puts stdout "Loading OOPL model failed due to previous errors"
  156.         [$this ooModel] delete
  157.         $this ooModel ""
  158.         return
  159.     }
  160.  
  161.     global importAll importNew
  162.  
  163.     if {$importAll} {
  164.         return [$this importAll]
  165.     }
  166.  
  167.     if {$importNew || [lempty [$this targetObjects]]} {
  168.         return [$this importNew]
  169.     }
  170.  
  171.     return [$this importSelected]
  172. }
  173.  
  174. method Importer::importAll {this} {
  175.     $this generateOopl [[$this ooplModel] ooplClassSet]
  176. }
  177.  
  178. method Importer::importNew {this} {
  179.     set ooplClasses ""
  180.     set existingFiles [fstorage::dir [$this ooplFileTypes]]
  181.     set excludeNames [$this getClassNames $existingFiles]
  182.  
  183.     foreach className [[$this ooplModel] getClassNames] {
  184.         if {[lsearch $excludeNames $className] == -1} {
  185.         set ooplClass [[$this ooplModel] classByName $className]
  186.  
  187.         if {$ooplClass == ""} {
  188.             m4_warning $W_UNABLE_TO_LOAD_CLASS $className
  189.         } else {
  190.             lappend ooplClasses $ooplClass
  191.         }
  192.         }
  193.     }
  194.  
  195.     if {[$this supportsPersistentCodeGen] &&
  196.         ([lempty [$this sourceObjects]] ||
  197.          [lsearch [$this sourceObjects] "sql"] != -1)} {
  198.         $this generateSql ""
  199.     }
  200.  
  201.     if {[lempty [$this sourceObjects]] ||
  202.         [lsearch [$this sourceObjects] "oopl"] != -1} {
  203.         $this generateOopl $ooplClasses
  204.     }
  205. }
  206.  
  207. method Importer::importSelected {this} {
  208.     set ooplFiles ""
  209.     set sqlFiles ""
  210.  
  211.     foreach file [$this targetObjects] {
  212.         set fType [nt_get_type $file]
  213.  
  214.         if {[lsearch [$this ooplFileTypes] $fType] != -1} {
  215.         lappend ooplFiles $file
  216.         continue
  217.         }
  218.  
  219.         if [$this supportsPersistentCodeGen] {
  220.         if {[lsearch [$this sqlFileTypes] $fType] != -1} {
  221.             lappend sqlFiles $file
  222.             continue
  223.         }
  224.         }
  225.  
  226.         m4_warning $W_UNKNOWN_FILE $file
  227.     }
  228.  
  229.     if {![lempty $sqlFiles]} {
  230.         $this generateSql $sqlFiles
  231.     }
  232.  
  233.     if {![lempty $ooplFiles]} {
  234.         set classList ""
  235.  
  236.         foreach className [$this getClassNames $ooplFiles] {
  237.         set ooplClass [[$this ooplModel] classByName $className]
  238.  
  239.         if {$ooplClass == ""} {
  240.             m4_warning $W_UNABLE_TO_LOAD_CLASS $className
  241.         } else {
  242.             lappend classList $ooplClass
  243.         }
  244.         }
  245.  
  246.         $this generateOopl $classList
  247.     }
  248. }
  249.  
  250. method Importer::parseOptions {this} {
  251.     global booleanOptions argv
  252.  
  253.     foreach opt $booleanOptions {
  254.         set i [lsearch $argv [lindex $opt 0]]
  255.         set optvar [lindex $opt 1]
  256.         eval "global $optvar"
  257.  
  258.         if {$i == -1} {
  259.         set optdef [lindex $opt 2]
  260.         eval "set $optvar $optdef"
  261.         } else {
  262.         set argv [lreplace $argv $i $i]
  263.         eval "set $optvar 1"
  264.         }
  265.     }
  266. }
  267.  
  268. method Importer::supportsPersistentCodeGen {this} {
  269.     return 0
  270. }
  271.  
  272. # Do not delete this line -- regeneration end marker
  273.  
  274.