Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Tcl-Java in Production

Status
Not open for further replies.

RajatM

Technical User
Nov 12, 2001
2
SE
I am working in a product development which uses a in-house framework for generating wrapper client and server code for CORBA. The business implementation is then written by overridding the default generation. The entire code base is in Java.

Now we want to add more flexiblity to it to make it easily customisable, mainly to enable the customer to write his own business logic on-the-fly. I liked the idea of a customer being able to write his customer specific business logic in a simple Tcl script which could then be called from within our Java code.

But I am new to the Tcl world and have no idea how it works. Could you provide me with some information on how 'Tcl-Blend' or 'JACL' could be used for this purpose? Could you also provide me some latest information on it ?
 
Hello, RajatM. Unfortunately, information on this incredibly useful tool is hard to come by. The best overview I've seen of it in a book is Steve Ball's Web Tcl Complete. Other than that, you're going to have to dig up the information on the Web.

TclBlend allows a Tcl script to create and interact with Java object. On the other hand, Jacl is a Tcl interpreter written in Java. TclBlend can be quite easy to use, but requires a native Tcl interpreter on the client's system. Jacl can be easy to use as well, but it's based on a somewhat stripped-down Tcl version 8.0.

Steve Ball gives several examples of calling out to a Java class from a Tcl script in his book. One is an example use calculating an MD5 checksum using an MD5 class in the user's classpath:

Code:
proc MD5 { message } {
    set md5id [java::new MD5]
    $md5id init
    $md5id updateASCII $message
    $md5id finish
    return [$md5id toString]
}

I've started using TclBlend to access the Xerces and Xalan XML and XSLT processors from my Tcl scripts. Here's a simple example that I put together to apply an XSLT stylesheet to an XML document and store the results in a file. I'm not saying that it's the best example of TclBlend code, but I was able to whip it up in just a few minutes:

Code:
# A quick example of using TclBlend and Xalan to do
# XSLT tranformation from a Tcl script

if {$argc != 3} {
    puts stderr "wrong # of argument"
    exit 1
} else {
    foreach {xslfile xmlfile outputfile} $argv {break}
}

package require java

java::import java.io.File
java::import javax.xml.transform.Transformer
java::import javax.xml.transform.TransformerFactory
java::import javax.xml.transform.stream.StreamResult
java::import javax.xml.transform.stream.StreamSource

set tfactory [java::call TransformerFactory newInstance]
set transformer [$tfactory newTransformer     [java::new StreamSource $xslfile ]]
set xml [java::new StreamSource     [java::new java.io.File $xmlfile ]]
set output [java::new StreamResult     [java::new java.io.File $outputfile ]]
$transformer transform $xml $output
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
I just discovered another link that could prove helpful:
I've not had a chance to read through it at length, but it does seem to provide several extended examples. And it seems right up your alley, as the preface includes: "The document focus on the implementation issues involved in embedding a Tcl interpreter into a Java program."

Good luck! - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top