- 浏览: 90349 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
httpping:
谢了
《oracle SQL性能优化》中文电子书 -
phywhm:
多谢多谢,看到这个解决到问题了,Hoho
[Exception... "Not enough arguments [nsIDOMHTMLSel -
qinkangwencai:
我遇到过这个问题,根据你 的方法解决了!万分感谢!
[Exception... "Not enough arguments [nsIDOMHTMLSel -
hn_evian:
不错,谢谢
《oracle SQL性能优化》中文电子书 -
alexyao8:
顶上
[Exception... "Not enough arguments [nsIDOMHTMLSel
更详尽的英文资料请参考IBM在线文档,或 http://jacl.sourceforge.net/
Java Command Language
Java is a remarkable programming language, but it isn't the only programming language to be developed at Sun. The Tool Command Language, or Tcl, is another extraordinary programming language that was developed (by John Ousterhout) at Sun. Tcl is an embedded scripting language that was originally created to support the rapid development of applications that run under the X Window System. However, Tcl's power, flexibility, and ease of use have caused it to be ported to almost all popular operating systems. Tcl is associated with the GUI toolkit named Tk, which provides a rich set of components for developing GUIs.
NOTE: Tcl is pronounced "tickle."
Because Java is a general-purpose, platform-independent programming language and Tcl is a cross-platform scripting language, the software engineers at Sun launched a research project to determine how the languages could be used together. The result of this effort is the Java Command Language (Jacl). Jacl is a 100% Java implementation of Tcl that allows Tcl scripts to take full advantage of the Java API. Jacl allows Tcl to be used as the scripting language for Java.
In this chapter, you'll be introduced to Jacl and learn how it provides programmers with the best features of both Java and Tcl. You'll use Tcl to quickly script an AWT-based Java application. You'll also learn how another product of the Java-Tcl research team, Tcl Blend, can be used to convert legacy C applications to Java. When you finish this chapter, you'll be able to use Tcl to script Java applications.
What's Jacl?
Jacl is the result of a very successful research effort to combine the best features of Java and Tcl. In a nutshell, Jacl is a 100% pure Java implementation of Tcl that give Tcl scripts full access to the Java API. Jacl enables Tcl to be used as the scripting language for Java applications. It lets you very quickly and easily generate GUI-based Java programs with just a few lines of Tcl code.
The power of Jacl lies in its capability to expose the Java API to Tcl. It does this through a software component referred to as the Java Package , which provides an interface between Java and Tcl. This interface provides Tcl scripts with the following capabilities:
- Scripts can create instances of Java classes.
- Scripts can invoke the methods of Java objects and classes. (Both static and non-static methods.)
- Scripts can access the public fields of Java objects.
- Scripts can determine the class of an object and its position within the overall Java class hierarchy.
- Scripts can load classes from a class path.
- Scripts can define new classes from byte streams.
Jacl also exploits the Reflection API to provide Tcl scripts with the capability to access the methods, properties, and events of JavaBeans. It allows Tcl scripts to create JavaBeans, invoke their methods, and get and set their properties. It also provides exceptional support of bean event handling. Bean events are exposed to Tcl, and these events may be handled in Tcl by binding Tcl code to the events.
NOTE: Don't worry if you are unfamiliar with Tcl. The next section provides an introductory Tcl primer.
One benefit of Jacl-to-Tcl programmers is that Jacl provides a platform-independent implementation of Tcl. This means that anywhere that Java will run, Tcl will also run. Another advantage is the feature-rich Java API. The capabilities of the Java API are reason alone for a Tcl programmer to switch from a C-based Tcl environment to Jacl.
Jacl is available for download from Sun's Web site at http://sunscript.sun.com/java/. It is packaged as a self-extracting installation file. You should download and install Jacl before going to the next section. Also, make sure that you put the \Jacl1.0 directory in your PATH.
NOTE: Jacl supports Tcl version 8.0. You do not need to install Tcl to run Jacl.
A Tcl Primer
This section teaches you how Tcl works and shows you how to write simple Tcl scripts. Having made it through 54 chapters of this book, you are on your way to becoming an accomplished programmer and should be able to pick up Tcl's syntax rather easily. The next section shows how to use Jacl to access the Java API from within Tcl scripts.
The syntax of Tcl, like Java, is based on C. It is organized into a set of commands that are executed by a Tcl interpreter. Tcl supports a single datatype--the string datatype. Everything in Tcl, including commands, is implemented using strings. The Tcl interpreter can be viewed as a very flexible and efficient string processor.
Command Syntax
Tcl commands are line-oriented, separated by the new line character or by semicolons. Commands consist of one or more fields, separated by spaces or tabs, where the first field is the name of the command. All fields after the first field are the arguments to the command. For example, the following command sets the value of the variable x to 5:
set x 5
Including Spaces as Part of a Field
Double quotes are used to include a space as part of a field. The following command sets the value of x to This is a test:
set x "This is a test"
Curly braces ({ and }) may also be used to delimit a field.
Command Substitution
Brackets ([ and ]) are used to delimit commands that are embedded in a field. Embedded commands are executed and their values are returned as part of the field in which they occur. Bracketed commands may span multiple lines. For example, the following commands set the value of x to 12:
set y 12
set x [set y]
In this command, the value returned by the command set y is 12.
Variable Substitution
The dollar sign ($) is used to substitute the value of a variable for the variable itself. For example, if the value of the variable y is 12, the following statement sets the value of x to 12:
set x $y
Arrays
Tcl arrays associate values with array elements. Array indices are not ordered as Java arrays and may consist of non-integer string values. Paired opening and closing parentheses are used to identify array indices. If a variable name is followed by an opening parenthesis, all characters up to the closing parenthesis are used to determine the array index. For example, if y(5) is 10, the following command assigns 10 to x:
set x y(5)
Escape Characters
Backslashes are used as escape characters in a similar manner as Java. For example, \n represents a new line character.
Comments
Tcl comments begin with the pound character (#) and extend to the end of the line on which they occur.
Expressions
Some Tcl commands treat their arguments as expressions. The operators used in Tcl expressions are based on C and are very similar to Java operators.
Lists
Tcl also supports list processing. Tcl lists are strings in which the individual list elements are separated by spaces, tabs, or new line characters. List elements are also delimited by curly braces. For example, the following list consists of the three elements a, {b c}, and {c {d e}}:
a {b c} {c {d e}}
The last element of the list is itself a list consisting of c and {d e}.
Variable Declaration
Tcl variables do not need to be declared.
Built-In Commands
Tcl supports a rich set of built-in commands. The following subsections cover some of the most important commands.
set
The set command is used to assign a value to a variable. It has the following syntax:
set variableName expression
The value of variableName is set to the result of expression . The set command can also be used to return a value when enclosed within brackets. The expression [set variableName ] returns the value of variableName .
if
The Tcl if command is similar to that of other languages. It has the following form:
if { expression1 } {
commands1
} elseif { expression2 }
commands2
} else {
commands3
}
Multiple elseif clauses may be used. The elseif and else clauses are optional and may be omitted. Note that the expressions are enclosed in curly braces instead of the parentheses used with Java.
for
The for command is similar to the Java statement. Its syntax follows:
for {start } {test } {update } {body }
The start is typically a set command that assigns a value to a loop iterator variable. The test is a condition that is evaluated to determine whether the loop should continue. The update updates the iterator between loop iterations. The body consists of commands that are the body of the for loop.
The following Tcl for command iterates i from 0 to 10 and executes commands:
for {set i 0} {$i < 10} {incr i} { commands }
break
The break command may be used to break out of a for command. It is used in the same way it is in Java. For example, the break command causes the following for loop to be exited when i is 5:
for {set i 0} {$i < 10} {incr i} {
if {i == 5} break
}
Other Commands
Tcl supports many other commands, such as while, case, continue, and others. Consult an introductory Tcl book for more information on these commands. Tcl and the Tk Toolkit by John Ousterhout is the definitive reference on Tcl.
Built-In Variables
Tcl also supports several built-in variables that provide access to the environment and error codes.
Accessing Java from Tcl Scripts
Jacl makes it easy to access Java objects from Tcl scripts. The best way to learn how to do this is through an example. Listing 55.1 shows an example program named Demo.tcl. We'll run this program and then examine how it works. Make sure that you have Jacl installed and the \Jacl1.0 directory in your PATH.
TIP: The C:\Jacl\jacl.bat file assumes you have JDK 1.1. You must modify this file so that it contains the correct CLASSPATH for your JDK installation.
Open a console window and switch to the \ju\ch55 directory. Launch Jacl and enter the following command at the Jacl prompt:
%source Demo.tcl
The Java window shown in Figure 55.1 is displayed. This window contains a text field, a label, and a button. Click on the button and the text field is updated, as shown in Figure 55.2. When you are finished, close the window and exit Jacl by entering exit at the Jacl prompt.
FIGURE 55.1. The Demo.tcl opening window.
FIGURE 55.2. The text field is updated when the button is clicked.
LISTING 55.1. THE Demo.tcl SCRIPT.
set frame [java::new java.awt.Frame]
set panel [java::new java.awt.Panel]
$frame setLayout [java::new java.awt.BorderLayout]
$frame setTitle "Jacl Demo"
set label [java::new java.awt.Label]
$label setText "Click to update the text field:"
set button [java::new java.awt.Button]
$button setLabel "Update text"
$panel {add java.awt.Component} $label
$panel {add java.awt.Component} $button
$frame {add java.lang.String java.awt.Component} "Center" $panel
set text [java::new java.awt.TextField]
$text setText "An AWT TextField"
$frame {add java.lang.String java.awt.Component} "North" $text
$frame setSize 400 400
$frame show
$frame toFront
java::bind $frame windowClosing "set done yes"
set newText {"THE TEXT HAS BEEN UPDATED!!!"}
java::bind $button actionPerformed "$text setText $newText"
vwait done
$frame dispose
The first line of the script sets the value of [java::new java.awt.Frame] to the frame variable. The java::new command creates a new Java object. In this case, it is a Frame object. The end result is that a Frame object is created and assigned to the frame variable.
The next line creates a Panel object and assigns it to the panel variable.
The third line invokes the setLayout() method of the Frame object, passing it a new object of the BorderLayout class. Whenever a Java object is the first field in a command, the second field identifies the method being invoked and the remaining fields identify the arguments for the method invocation.
The next line invokes the setTitle() method of the Frame object with the "Jacl Demo" argument.
The fifth and sixth lines of the script create a Label object and assign it to the label variable. The label's text is set to "Click to update the text field:".
The next two lines create a Button object that is labeled Update text.
The ninth line of the script adds the Label object to the Panel object. The add() method of the container class has more than one version, so the specific version must be identified by placing the method name and its argument types in a list (surrounded by braces).
The tenth line adds the Button object to the Panel object.
The eleventh line adds the Panel object to the center of the Frame object. Note that the add() method with two arguments (String and Component) is used.
The next two lines create a TextField object and initialize its text to An AWT TextField.
In lines 14-17, the text field is added to the frame, the frame's size is set to 400 by 400, the frame is shown, and it is set to the front window.
The next line shows how Java events are handled by Tcl. The java::bind command is used to bind a Java event with a Tcl command. The first argument to java::bind is the Java object whose events are being handled. The second argument is the event name, and the third argument is the Tcl command that is executed to handle the event. This command sets the done variable to yes.
The following line sets the value of newText to the list containing the string "THE TEXT HAS BEEN UPDATED!!!". The text is put in a list so that it appears as a single argument to a method.
The actionPerformed event of the button is handled by this command:
$text setText $newText
This command updates the text of the TextField object referenced by the text variable.
The vwait command causes the script to wait while events are handled. The vwait command waits until the done variable is set by an event handler and the event handler has completed its processing. This variable is set by the handling of the windowClosing event. The Frame object is disposed after the vwait command finishes its processing.
Jacl Versus Tcl
Because Jacl supports the integration of both Java and Tcl, it is natural to ask which part of an application should be written in Java and which part should be written in Tcl. The developers of Jacl envisioned a development approach in which Java would be used to develop reusable components, such as JavaBeans. As such, Java is referred to as a component developer . Tcl, on the other hand, is referred to as an application assembler . Tcl scripts are the "glue" used to integrate Java components into applications.
This symbiosis between Java and Tcl can be compared to the complimentary relationship between Microsoft's Visual C++ and Visual Basic. Visual C++ is used to develop Component Object Model (COM) components, and Visual Basic is used to assemble COM components into final applications. In the same way, Java is used to create JavaBeans, and Tcl is used to integrate the beans into Jacl applications.
Jacl can also be used in another context that has a Microsoft analogy. The individual programs of Microsoft Office, such as Word and Excel, support Visual Basic as an application scripting language. Visual Basic can be used to extend the capabilities of the Office application programs. It is envisioned that Tcl will be used in the same manner to extend Jacl-enabled Java applications. Imagine a Java-based office suite that uses Tcl to create extensions to the individual office programs.
Tcl Blend
Tcl Blend is another product of the Java-Tcl research team. It's an extension to the C-based Tcl environment that allows the C-based Tcl interpreter to interact with the JVM, and vice versa. Tcl Blend is the middle ground between the standard Tcl environment and Jacl. It supports Tcl, C, and Java, and provides a bridge between the C and Java-based Tcl environments so that legacy code, written in C, can be incrementally ported to Java.
Tcl Blend uses the same Java Package software component as Jacl. This means that Tcl scripts have the same visibility into the Java API as they do in Jacl. For this reason, Tcl Blend is a great way for Tcl programmers to move over to Java without sacrificing their investment in C code. Tcl programmers can write Tcl scripts that use both the Java API and C-based Tcl extensions. As the C-based Tcl extensions are replaced by the Java API, the Tcl applications can be ported to the 100-percent Java environment of Jacl.
Tcl Blend is available from the Sun Web site at http://sunscript.sun.com/java/ .
NOTE: Tcl Blend requires Tcl version 8.0.
Summary
In this chapter, you were introduced to Jacl and learned how it provides programmers with the best features of both Java and Tcl. You used Tcl to script an AWT-based Java application. You were then introduced to Tcl Blend and learned how it can be used to convert legacy C applications to Java. In the next chapter, you'll learn about the visual design tools that are available to support Java software development.
发表评论
-
Android2.2模拟器屏幕定制
2010-07-25 23:06 5538Android 模拟器屏幕定制 由于项目需要把Android ... -
spring+struts2+freemarker+hibernate里的openSessionViewFiler
2009-12-09 09:32 0原先在spring+struts1+hibernate架构应用 ... -
用实例揭示notify()和notifyAll()的本质区别
2009-09-15 10:48 3119非常好的教学例子. 转自http://blog.csdn.n ... -
ClassLoader机制
2009-07-01 10:49 0理解Java ClassLoader机制 |用Java说话,人 ... -
JDK5.0垃圾收集优化之--Don't Pause
2009-02-24 15:02 933作者:江南白衣 ,最新版链接:http://blog.csdn ... -
Tomcat5中文文档
2009-02-11 12:55 1007http://tomcat.jaxwiki.org/是它的在线 ... -
新闻被抢~~
2009-01-08 23:03 877Artifactory 2今天发布的新闻被抢 ,呵呵。 话 ... -
Artifactory Maven Repository Manager 2.0 发布
2009-01-08 22:51 1902Artifactory Maven Repository ... -
Tomcat中SSI的配置
2008-12-29 00:44 2205转篇CSDN上的关于SSI的博,有些地方总结的非常不错。 转自 ... -
Tomcat中SSI配置异常的解决办法
2008-12-29 00:32 3446以下异常可能很多人都会碰到,而网上很多解决办法都说得不尽然。 ... -
Mylyn简介——一个不错的eclipse工具
2008-11-25 23:25 5677Mylyn(旧称Mylar)是eclips ... -
Odd Ant error when using the Ant sql task in RAD
2008-11-22 22:53 1382Odd Ant error when using the An ... -
JACL中文文档
2008-11-13 13:06 4075博主注: 最近要写WAS的wsadmin脚本和JACL脚本, ... -
XFire在Websphere Application Server5.1里运行的空指针异常的解决
2008-10-31 23:02 3142最近在部署Server方面碰到了一个非常棘手的问题,在WAS5 ...
相关推荐
Jacl(Java Command Language)是TCL的一个实现,它允许TCL脚本在Java平台上运行,提供了与Java的紧密集成。SpringSource是一家知名的Java技术提供商,他们为许多开源项目提供了支持,包括这个TCL的Java接口。 "jar...
### Jacl:一种基于Java环境的Tcl实现 #### 概述 《Jacl:一种Tcl在Java环境中的实现》是一篇详细介绍了如何将Tcl脚本语言与Java技术结合的文章。该文最初发表于1997年波士顿第五届年度Tcl/Tk研讨会的论文集中。...
tcl.lang.Interp 依赖包jacl-1.2.6.jar
火龙果软件工程技术中心本文内容包括:1RSA的模型转换框架2WebSphere与Jacl语言3服务集成总线建模(SIBUS)4SIBUS模型到Jacl脚本的转换开发结束语参考资料RationalSoftwareArchitect(RSA)是IBMRational软件家族中的...
在压缩包中的文件 "JACL+A+TCL+implementation+in+Java.pdf" 很可能是关于JACL的详细教程或技术文档,涵盖了JACL的安装、配置、使用方法以及实际案例。而 "jaclBinary141.zip" 文件可能包含了JACL的二进制版本,供...
2. **错误类型和原因**:针对每一道题目或者报错实例,文档会解释出错的原因,可能是语法错误、逻辑错误,或者是配置问题、兼容性问题等。 3. **错误解决步骤**:在分析完错误原因后,会给出详细的解决步骤,包括...
it is a sample for websphere application server's asset wsadmin. use wsadmin & jacl you can auto deploy your enterprise archive file.
4. **Java API for Lotus Domino (JACL)**:对于更复杂的应用需求,开发者可以使用JACL进行服务器端编程,JACL提供了与LotusScript类似的接口,但使用Java语言,可以充分利用Java的强大功能。 5. **XPages**:随着...
Lotus Domino R5是一款在20世纪末到21世纪初广泛应用的企业级协同软件平台,它集成了电子邮件、日程管理、文档共享、数据库和Web应用开发等功能。此资源"中文Lotus_Domino_R5_Web_高级编程.rar"似乎包含了一份关于...
本资源摘要信息的标题是"Evolving the Java Platform-Ola Bini.pdf",该文件是一份技术文档分享,标签为"技术文档分享"。在这份文件中,作者 Ola Bini 介绍了 Java 平台的演进,讨论了其他语言对 Java 平台的影响,...
自述文件:Tcl 这是Tcl 9.0a2源分发。 您可以从获得Tcl的任何源版本。 8.6(生产发布,每日构建) 8.7(开发中,每日构建) 9.0(开发中,每日构建)内容简介Tcl提供了一个强大的平台来创建将各种应用程序,协议,...
1. **Java API for Lotus Domino (JACL)**:这是IBM提供的一套Java接口,使得开发者可以使用Java来操作Domino对象,如数据库、文档、视图、表单等。 2. ** Domino JNA (Java Native Access)**:这是一种技术,通过...
- 运行Jacl脚本:`wsadmin.bat -profile sample.jacl` - 运行Jython脚本:`wsadmin.bat -lang jython -profile sample.py` ### Jython语言介绍 Jython是动态类型的,不需要提前声明变量类型。其基本数据类型包括...
Tcl / CSharp是完全用C#编写的Tcl解释器的实现。 Tcl / CSharp是从Jacl(Tcl Java实现)版本1.3.1移植而来的,它为Tcl代码提供了到.NET Framework的桥梁。
唯一的,完整的Java XUL /嵌入式脚本解决方案。 JFCML不仅仅支持AWT和Swing;还支持AWT和Swing。 但是Java的ClassLoader... 此外,大多数主要的脚本语言,包括JavaScript,BeanShell,Jython,Jacl(Tcl),JRuby等。
- **Portal脚本**:基于Websphere扩展,支持TCL和JACL脚本,适用于复杂的管理任务,例如用户迁移和数据库迁移。它还整合了ANT的构建和批处理功能。 - **XML配置接口**:通过XML文件直接修改Portal配置,支持导入...
- 或者,使用ConfigureWebServerDefinition.jacl脚本来自动化此过程。 5. **应用程序映射** - 应用程序在安装时会被自动映射到Web服务器,或者在安装后手动进行映射。 6. **配置插件** - 可以通过管理控制台或...