I'm trying to place all the class data from my package's .class files inside Tcl files as binary strings for loading when required. As a first step in that direction, I've created the following proc, which simply takes all .class files in a given directory, and tries to convert the binary data in those files into java.lang.Class objects:
package require java
set dir "medical"
proc loadClasses {dir} {
set classfiles [glob [file join $dir *.class]]
foreach f $classfiles {
set file [open $f r]
fconfigure $file -translation binary
set data [read $file]
close $file
set class [join [file split [file rootname $f]] .]
# This returns a Java Class object.
if {[catch {java::defineclass $data} res]} {
puts stderr "Error in defining class $class : $res"
} else {
if {![java::isnull $res]} {
global $class
set $class $res
puts stdout "OK: class $class"
catch {
# Get an instance of the object.
set object [[set $class] newInstance]
}
} else {
puts stdout "class $class is $res"
}
}
}
}
loadClasses $dir
However this only works for a handful of the classes; the output from the above procedure is:
% loadClasses $dir
OK: class medical.Contract
class medical.CSE is java0x0
Error in defining class medical.CSEevent :
class medical.Customer is java0x0
class medical.DataGather is java0x0
OK: class medical.Debug
class medical.Dispatcher is java0x0
Error in defining class medical.DispatchEvent :
OK: class medical.Employee
OK: class medical.Engineer
Error in defining class medical.EscalationEvent :
class medical.Event is java0x0
class medical.MachineEvent is java0x0
Error in defining class medical.Maintenance :
class medical.MedicalSystem is java0x0
class medical.ProbabilityDistribution is java0x0
class medical.Problem is java0x0
class medical.Receiver is java0x0
OK: class medical.Region$CSEtoGo
class medical.Region is java0x0
class medical.sendCSEback is java0x0
Error in defining class medical.sendCSEimmediately :
class medical.Simulation is java0x0
class medical.SystemStatus is java0x0
class medical.TSE is java0x0
class medical.Variant is java0x0
OK: class medical.VariantInfo
class medical.World is java0x0
and this output remains identical with repeated calls to loadClasses. Can anyone enlighten me as to what is happening here? (And hopefully how to make this work better?). The basic goal is to be able to place all the class information in .tcl files which can then be wrapped into a single executable using one of the wrap/prowrap/... type tools.
many thanks for any help,
cheers,
Vince.