home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / javaconv.tcl < prev    next >
Text File  |  1996-12-23  |  5KB  |  205 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 1996 by Cayenne Software Inc.
  4. #
  5. # This software is furnished under a license and may be used only in
  6. # accordance with the terms of such license and with the inclusion of
  7. # the above copyright notice. This software or any other copies thereof
  8. # may not be provided or otherwise made available to any other person.
  9. # No title to and ownership of the software is hereby transferred.
  10. #
  11. # The information in this software is subject to change without notice
  12. # and should not be construed as a commitment by Cayenne Software Inc.
  13. #
  14. #---------------------------------------------------------------------------
  15. #
  16. #    File        : @(#)javaconv.tcl    /main/hindenburg/3
  17. #    Author        : Discovery
  18. #    Original date    : December 1996
  19. #    Description    : Tcl Script doing the following conversions on CDM's
  20. #              that are created for generating Java code in the
  21. #              current system:
  22. #                * attribute property
  23. #
  24. #                     default_value -> initial_value
  25. #
  26. #                  - " = <default_value>" is appended to name_type
  27. #                    label
  28. #                  - existing initial_value overrules default_value
  29. #                  - default_value is deleted
  30. #                * row property
  31. #
  32. #                     is_static     -> is_class_feature
  33. #
  34. #                  - "$" is prepended to name_type label if needed
  35. #                  - existing is_class_feature overrules is_static
  36. #                  - is_static is deleted
  37. #    Usage        : otsh -f <this_file>
  38. #
  39. #---------------------------------------------------------------------------
  40. #
  41. # @(#)javaconv.tcl    /main/hindenburg/3    23 Dec 1996 Copyright 1996 Cayenne Software Inc.
  42. #
  43. #---------------------------------------------------------------------------
  44.  
  45. global SCCS_W; set SCCS_W "
  46. @(#)javaconv.tcl    /main/hindenburg/3
  47. "
  48. global file
  49.  
  50. proc rowConv {row} {
  51.     if {[$row getCompType] == "attribute"} {
  52.     set isStatic [$row getProp "is_static" "name_type" "de"]
  53.     } else {
  54.     set isStatic [$row getProp "is_static"]
  55.     }
  56.  
  57.     if {$isStatic != ""} {
  58.     set doConvert 1
  59.     set isClassFeature [$row getProp "is_class_feature"]
  60.  
  61.     if {$isClassFeature != "" && $isStatic != $isClassFeature} {
  62.         puts stderr "WARNING: $file: [$row getCompType] '[$row getLabel "name_type"]' has 'is_static = $isStatic' unequal to 'is_class_feature = $isClassFeature'; latter one overrules"
  63.  
  64.         set doConvert 0
  65.     }
  66.  
  67.     if {[$row getCompType] == "attribute"} {
  68.         $row setProp "is_static" "" "name_type" "de"
  69.     } else {
  70.         $row setProp "is_static" ""
  71.     }
  72.  
  73.     if {$doConvert} {
  74.         set nameType [$row getLabel "name_type"]
  75.         regsub {$} $nameType {} nameType
  76.  
  77.         if {$isStatic == "1"} {
  78.         $row setLabel "name_type" "\$$nameType"
  79.         }
  80.     }
  81.  
  82.     return 1
  83.     }
  84.  
  85.     return 0
  86. }
  87.  
  88. proc attrConv {attr} {
  89.     set defaultValue [$attr getProp "default_value" "name_type" "de"]
  90.  
  91.     if {$defaultValue != ""} {
  92.     set doConvert 1
  93.     set initialValue [$attr getProp "initial_value"]
  94.  
  95.     if {$initialValue != "" && $defaultValue != $initialValue} {
  96.         puts stderr "WARNING: $file: attribute '[$attr getLabel "name_type"]' has 'default_value = $defaultValue' unequal to 'initial_value = $initialValue'; latter one overrules"
  97.  
  98.         set doConvert 0
  99.     }
  100.  
  101.     $attr setProp "default_value" "" "name_type" "de"
  102.  
  103.     if {$doConvert} {
  104.         set nameType [$attr getLabel "name_type"]
  105.         regsub {[ ]*=.*} $nameType {} nameType
  106.         $attr setLabel "name_type" "$nameType = $defaultValue"
  107.     }
  108.  
  109.     return 1
  110.     }
  111.  
  112.     return 0
  113. }
  114.  
  115. proc javaConv {fileV} {
  116.     set diag [EdCDM new [[$fileV file] name] "" "" "" "" "" "" "" 1]
  117.     set isChanged 0
  118.  
  119.     foreach row [$diag getRows] {
  120.     if {[$row getCompType] == "attribute"} {
  121.         set isChanged [expr $isChanged + [attrConv $row]]
  122.     }
  123.  
  124.     set isChanged [expr $isChanged + [rowConv $row]]
  125.     }
  126.  
  127.     if {$isChanged} {
  128.     $diag formatLayout
  129.     $diag save
  130.     } else {
  131.     $diag quit
  132.     }
  133. }
  134.  
  135. proc main {} {
  136.     global file
  137.     set file [string trim $SCCS_W "\n"]
  138.     regsub "@.#.(.*)\t.*" $file {\1} file
  139.  
  140.     set cc [ClientContext::global]
  141.     set sysV [$cc currentSystem]
  142.  
  143.     if {[$cc currentLevel] == "File"} {
  144.     $cc upLevel
  145.     }
  146.  
  147.     if {[$cc currentLevel] != "System"} {
  148.     puts stderr "ERROR: $file: cannot find out current system (levelpath is '[$cc currentLevelString]')"
  149.     exit 1
  150.     }
  151.  
  152.     $cc upLevel
  153.  
  154.     #
  155.     # Now we are at phase level, so we can freeze the system version
  156.     #
  157.  
  158.     set systemName [[$sysV system] name]
  159.  
  160.     if {[$sysV status] != "frozen"} {
  161.     puts "Freezing system '$systemName' before starting conversion."
  162.     $sysV freeze "Freeze before Java conversion ObjectTeam 4.0 to 5.1.1"
  163.     }
  164.  
  165.     #
  166.     # Create new system version
  167.     #
  168.  
  169.     set phaseV [$cc currentPhase]
  170.  
  171.     puts "Creating new version of system '$systemName'"
  172.  
  173.     set sysV [$phaseV derive -systemVersion $sysV [$cc currentConfig]]
  174.  
  175.     $cc downLevelId $sysV
  176.  
  177.     #
  178.     # Create new versions of all files
  179.     #
  180.  
  181.     set fileVersions [$sysV allFileVersions]
  182.  
  183.     foreach fileV $fileVersions {
  184.     set file [$fileV file]
  185.     puts "Creating new version of file '[$file name].[$file type]'"
  186.     $sysV derive -fileVersion $fileV [$cc currentConfig]
  187.     }
  188.  
  189.     puts ""
  190.     puts "Starting conversion"
  191.     puts ""
  192.  
  193.     OTShRegister::importToolEdExt
  194.  
  195.     foreach fileV [$sysV allFileVersions] {
  196.     if {[[$fileV file] type] == "cdm"} {
  197.         javaConv $fileV
  198.     }
  199.     }
  200.  
  201.     exit 0
  202. }
  203.  
  204. main
  205.