home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cayenne Software Inc. 1997
- #
- # File: @(#)importer.tcl /main/hindenburg/5
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)importer.tcl /main/hindenburg/5 7 May 1997 Copyright 1997 Cayenne Software Inc.
-
- # Start user added include file section
-
- require wmt_util.tcl
- require fstorage.tcl
- require cgen_msg.tcl
-
- global booleanOptions
- set booleanOptions { {-trace tracing 0} \
- {-debug debug 0} \
- {-time timing 0} \
- {-all importAll 0} \
- {-new importNew 0} \
- {-selected importSelected 0} }
-
- # End user added include file section
-
-
- Class Importer : {GCObject} {
- constructor
- method destructor
- method generateOopl
- method generateSql
- method getClassNames
- method getFileNamesNotToGenerateFor
- method getOoplFileTypesToGenerateFor
- method getSqlFileTypesToGenerateFor
- method import
- method importAll
- method importNew
- method importSelected
- method parseOptions
- method supportsPersistentCodeGen
- attribute sourceObjects
- attribute targetObjects
- attribute ooplFileTypes
- attribute sqlFileTypes
- attribute ooModel
- attribute ooplModel
- }
-
- constructor Importer {class this} {
- set this [GCObject::constructor $class $this]
- # Start constructor user section
-
- $this sourceObjects [CommandLineInterface::getSourceObjects]
- $this targetObjects [CommandLineInterface::getTargetObjects]
- $this ooplFileTypes [$this getOoplFileTypesToGenerateFor]
- $this sqlFileTypes [$this getSqlFileTypesToGenerateFor]
-
- # End constructor user section
- return $this
- }
-
- method Importer::destructor {this} {
- # Start destructor user section
- # End destructor user section
- }
-
- method Importer::generateOopl {this classes} {
- # !! Implement this function !!
- }
-
- method Importer::generateSql {this files} {
- # !! Implement this function !!
- }
-
- method Importer::getClassNames {this fileList} {
- set result ""
- set excludeNames [$this getFileNamesNotToGenerateFor]
-
- foreach file $fileList {
- set fName [nt_get_name $file]
- set fType [nt_get_type $file]
-
- if {[lsearch $excludeNames $fName] != -1} {
- continue
- }
-
- if {[lsearch [$this ooplFileTypes] $fType] != -1} {
- if [catch {set names [fstorage::get_imp_from $file]} reason] {
- puts stderr $reason
- set names ""
- }
-
- if {$names == ""} {
- m4_warning $W_IMPFROM_NOT_SET $file $fName
- set names $fName
- }
-
- foreach nm $names {
- if {[lsearch $result $nm] == -1} {
- lappend result $nm
- }
- }
- }
- }
-
- return $result
- }
-
- method Importer::getFileNamesNotToGenerateFor {this} {
- return ""
- }
-
- method Importer::getOoplFileTypesToGenerateFor {this} {
- # !! Implement this function !!
- }
-
- method Importer::getSqlFileTypesToGenerateFor {this} {
- return ""
- }
-
- method Importer::import {this} {
- $this parseOptions
- set cc [ClientContext::global]
- set systemNameType [$cc levelNameAt System]
- set phaseNameType [$cc levelNameAt Phase]
- set prevPhaseV [[$cc currentPhase] previous [$cc currentConfig]]
-
- if [$prevPhaseV isNil] {
- m4_error $E_NO_PREV_PHASE $phaseNameType
- return
- }
-
- set prevPhase [$prevPhaseV phase]
- set prevPhaseNameType [$prevPhase name].[$prevPhase name]
-
- if {[$prevPhase type] != "ObjectDesign"} {
- m4_error $E_WRONG_PREV_PHASE $prevPhaseNameType
- return
- }
-
- if {[catch {fstorage::goto_system $systemNameType $prevPhaseNameType} reason]} {
- puts stderr $reason
- return
- }
-
- $this ooModel [OOModel::createModel]
- $this ooplModel [[$this ooModel] ooplModel]
-
- fstorage::goto_system $systemNameType $phaseNameType
-
- if {[[$this ooModel] error] > 0} {
- ##m4_error $E_LOAD_MODEL
- puts stdout "Loading OOPL model failed due to previous errors"
- [$this ooModel] delete
- $this ooModel ""
- return
- }
-
- global importAll importNew
-
- if {$importAll} {
- return [$this importAll]
- }
-
- if {$importNew || [lempty [$this targetObjects]]} {
- return [$this importNew]
- }
-
- return [$this importSelected]
- }
-
- method Importer::importAll {this} {
- $this generateOopl [[$this ooplModel] ooplClassSet]
- }
-
- method Importer::importNew {this} {
- set ooplClasses ""
- set existingFiles [fstorage::dir [$this ooplFileTypes]]
- set excludeNames [$this getClassNames $existingFiles]
-
- foreach className [[$this ooplModel] getClassNames] {
- if {[lsearch $excludeNames $className] == -1} {
- set ooplClass [[$this ooplModel] classByName $className]
-
- if {$ooplClass == ""} {
- m4_warning $W_UNABLE_TO_LOAD_CLASS $className
- } else {
- lappend ooplClasses $ooplClass
- }
- }
- }
-
- if {[$this supportsPersistentCodeGen] &&
- ([lempty [$this sourceObjects]] ||
- [lsearch [$this sourceObjects] "sql"] != -1)} {
- $this generateSql ""
- }
-
- if {[lempty [$this sourceObjects]] ||
- [lsearch [$this sourceObjects] "oopl"] != -1} {
- $this generateOopl $ooplClasses
- }
- }
-
- method Importer::importSelected {this} {
- set ooplFiles ""
- set sqlFiles ""
-
- foreach file [$this targetObjects] {
- set fType [nt_get_type $file]
-
- if {[lsearch [$this ooplFileTypes] $fType] != -1} {
- lappend ooplFiles $file
- continue
- }
-
- if [$this supportsPersistentCodeGen] {
- if {[lsearch [$this sqlFileTypes] $fType] != -1} {
- lappend sqlFiles $file
- continue
- }
- }
-
- m4_warning $W_UNKNOWN_FILE $file
- }
-
- if {![lempty $sqlFiles]} {
- $this generateSql $sqlFiles
- }
-
- if {![lempty $ooplFiles]} {
- set classList ""
-
- foreach className [$this getClassNames $ooplFiles] {
- set ooplClass [[$this ooplModel] classByName $className]
-
- if {$ooplClass == ""} {
- m4_warning $W_UNABLE_TO_LOAD_CLASS $className
- } else {
- lappend classList $ooplClass
- }
- }
-
- $this generateOopl $classList
- }
- }
-
- method Importer::parseOptions {this} {
- global booleanOptions argv
-
- foreach opt $booleanOptions {
- set i [lsearch $argv [lindex $opt 0]]
- set optvar [lindex $opt 1]
- eval "global $optvar"
-
- if {$i == -1} {
- set optdef [lindex $opt 2]
- eval "set $optvar $optdef"
- } else {
- set argv [lreplace $argv $i $i]
- eval "set $optvar 1"
- }
- }
- }
-
- method Importer::supportsPersistentCodeGen {this} {
- return 0
- }
-
- # Do not delete this line -- regeneration end marker
-
-