Beanshell翻译3

上一篇 / 下一篇  2008-09-02 20:12:12 / 个人分类:Beanshell

Beanshell翻译3

http://user.qzone.qq.com/281696143/blog/1194238270  Ronger
1.Quick Start 快速开始
Welcome to BeanShell. This is a crash course to get you going. We'll leave out many important options and details.
Please see the rest of the user's guide for more information.
欢迎来到Beanshell,这是一个快速前进的过程。我们将列出很多重要的项和细节.请看用户手册获取更多的信息。
2.Download and Run BeanShell  下载和运行Beanshell
Download the latest JAR file fromhttp://www.beanshell.organd start up BeanShell either in the graphical desktop mode or on the command line.
If you just want to start playing around you may be able to launch the BeanShell desktop by simply double clicking on the BeanShell JAR file.
More generally however you'll want to add the jar to your classpath so
that you can work with your own classes and applications easily.
To do this you can either drop the BeanShell JAR file into your Java extensions folder or add it to your classpath.
(Important: If you put BeanShell in the extensions folder and wish to use it with BSF applications
like Jakarta Ant you must install the bsf.jar in the same location).
http://www.beanshell.org上下载最新的Jar文件并且不管是以图形桌面模式或者是命令行模式开始Beanshell.
如果你仅仅想了解一下你可以通过简单的点击Beanshell的Jar文件来发动Beanshell的桌面。更通用的,如果你将Jar文件
加到你的类路径中,你可以像使用你自己的类或者应用程序一样轻松的使用它。
要想这样,你可以将Beanshell的Jar文件拖到你的Java扩展文件夹中或者加到你的类路径中。(重要:如果你将Beanshell放到
你的扩展文件夹中并且希望使用BSF应用程序中类似于Jakarta Ant的功能,你必须把bsf.jar放在同样的位置)。
To install as an extension place the bsh.jar file in your
$JAVA_HOME/jre/lib/ext folder.
(OSX users: place the bsh.jar in /Library/Java/Extensions or ~/Library/Java/Extensions for individual users.)
Or add BeanShell to your classpath like this:
在$JAVA_HOME/jre/lib/ext文件夹中安装bsh.jar
或者是像这样将Beanshell加到你的类路径中:
unix: export CLASSPATH=$CLASSPATH:bsh.xx.jar
windows: set classpath %classpath%;bsh.xx.jar
Tip:   提示
You can modify the classpath from within BeanShell using the addClassPath() and setClassPath() commands.
You can then run BeanShell in either a GUI or command line mode:
你可以使用addClassPath()和setClasPath()来修改类路径。
你可以在GUI或者是命令行上运行Beanshell.
java bsh.Console // run the graphical desktop   运行在图形桌面上
or
java bsh.Interpreter // run as text.only on the command line  在命令行行运行文本
or
java bsh.Interpreter filename [ args ] // run scrīpt file  运行脚本文件。
It's also possible to call BeanShell from within your own Java applications, to reach it in a remote server mode for debugging,
to use it as a servlet, or even in an applet. See "BeanShell Modes of Operation" for more details.
也可以从你的Java应用程序上调用Beanshell,通过远程服务器模式调试它,当成Servlet甚至是applet来使用它。
请看“Beanshell操作模式”获得详细信息。
3.The BeanShell GUI  
The BeanShell GUI desktop is meant to allow some experimentation with the features of BeanShell. It is not
intended to be a replacement for a full featured IDE. Please check out the jEdit editor for an example of a full
featured development environment based in part on BeanShell scrīpting capabilities. Upon starting the BeanShell in GUI mode a console window will open.
By right clicking on the desktop background you can open additional console windows and other tools such as a simple class browser.
Beanshell GUI 桌面将实验的特性加入进来。它并没有打算成为一个全功能的IDE.作为一个例子,请检查jEdit编辑器
的Beanshell脚本功能。
使用Beanshell的GUI模式时一个平台窗口将会打开。通过在平台上正确的点击你可以打开附加的平台窗口和其它的一些工具,
比如一个简单的类浏览器。
4.Quick Start 快速开始
Each console window runs a separate instance of the BeanShell interpreter. The graphical console supports
basic command history, line editing, cut and paste, and even class and variable name completion. From the
console you can open a simple editor window. In it you can write scrīpts and use the 'eval' option to evaluate
the text in the attached console's workspace or a new workspace.
每个平台窗口运行一个Beanshell解释者的独立实例。图形平台支持历史上的基本命令,图形编辑,剪切和粘贴,申明类和变量。
从平台上你可以打开一个简单的编辑窗口。在它里面你可以写脚本,在一个隶属于平台的工作空间或者一个新工作空间中使用
'eval'命令计算表达式的值。
5.Java Statements and Expressions Java申明和表达式
BeanShell understands standard Java statements, expressions, and method declarations. Statements and
expressions are all of the normal things that you'd say inside a Java method such as variable declarations and
assignments, method calls, loops, and conditionals.
Beanshell理解标准的Java申明,表达式,和方法定义。申明和表达式是最常见的,你可以在一个Java方法中进行变量定义和
分配,方法调用,循环和条件语句。
You can use these exactly as they would appear in Java, however in BeanShell you also have the option of working with "loosely typed" variables.
That is, you can simply omit the types of variables that you use (both
primitives and objects).
BeanShell will only signal an error if you attempt to misuse the actual type of the variable.
你可以完全使用在Java中出现的,但是在Beanshell中你还可以使用宽松类型来定义变量。
那就是说,你可以忽略你使用的变量的类型(包括简单类型和对象)。如果你用错了变量的类型,
Beanshell将仅仅标记一个错误。
Here are some examples:  以下是示例:
foo = "Foo";
four = (2 + 2)*2/2;
print( foo + " = " + four ); // print() is a BeanShell command  print()是Beanshell提供的命令
// Do a loop  循环
for (i=0; i<5; i++)
print(i);
// Pop up a frame with a button in it  在一个面板上放一个按钮
button = new JButton( "My Button" );
frame = new JFrame( "My Frame" );
frame.getContentPane().add( button, "Center" );
frame.pack();
frame.setVisible(true);
Useful BeanShell Commands 使用Beanshell的命令。
In the previous example we used a convenient "built.in" BeanShell command called print(), to display values. print() does pretty much the same thing as System.out.println() except that it insures that the output always goes to the command line.
print() also displays some types of objects (such as arrays) more verbosely than
Java would. Another related command is show(),which toggles on and off automatic display of the result of every line you type.
在上面的例子中,我们使用了一个方便的Beanshell的命令pring(),来显示值。
print()可以和System.out.println()做的一样好,并且它还可以将输出显示在命令行中。
print()可以显示对象的时候比Java冗长。另外一个相关的命令是show(),可以
显示和关闭你选择的每一行结果的自动显示。
Here are a few other examples of BeanShell commands: 这儿是一些Beanshell命令的其它的例子:
· source(), run() . Read a bsh scrīpt into this interpreter, or run it in a new interpreter
对一个bsh脚本进入解释者,或者在一个新的解释者中运行它。
· frame() . Display a GUI component in a Frame or JFrame.
在一个面板中显示一个GUI组件。
· load(), save() . Load or save serializable objects to a file.
加载或者存储一个序列化对象到一个文件中。
· cd(), cat(), dir(), pwd(), etc. . Unix.like shell commands  Unix的命令很像shell命令
· exec() . Run a native application   运行一个本地应用程序。
· javap() . Print the methods and fields of an object,
similar to the output of the Java javap command. 打印一个对象的方法和属性,类似于
Java中的javap命令。
· setAccessibility() . Turn on unrestricted access to private and protected components.
See the complete list of BeanShell Commands for more information.
打开通往私有和受保护组件的入口。通过Beanshell命令的完全列表来获得更多信息。
6. Java Statements and Expressions   Java申明和表达式
Tip:  提示
BeanShell commands are not really "built.in"
but are simply BeanShell scrīpts that are automatically loaded
from the classpath.
You can add your own scrīpts to the classpath to extend the basic command set.
Beanshell命令不是编译进来的,而是简单的从类路径中加载的Beanshell脚本。
你可以将你自己的脚本增加到类路径中来扩展基本的命令。
7.scrīpted Methods 脚本函数
You can declare and use methods in BeanShell just as you would in a Java class.
你可以在Beanshell中就像在一个Java类一样申明函数。
int addTwoNumbers( int a, int b ) {
return a + b;
}
sum = addTwoNumbers( 5, 7 ); // 12
Bsh methods may also allow dynamic (loose) argument and return types.
Bsh方法也允许宽松的参数类型和返回类型。
add( a, b ) {
return a + b;
}
foo = add(1, 2); // 3
foo = add("Oh", " baby"); // "Oh baby"
Implementing Interfaces 实现接口
Note: implementing arbitrary interfaces requires BeanShell be run under a Java 1.3 or higher environment.
注意:想实现任意的接口,Beanshell需要运行在Java1.3或者是更高的环境上。
You can use the standard Java anonymous inner class syntax to
implement an interface type with a scrīpt. For example:
在脚本中你可以使用标准Java匿名内部类去实现一个接口。示例:
ActionListener scrīptedListener = new ActionListener() {
actionPerformed( event ) { ... }
}
You don't have to scrīpt all of the methods of an interface.
You can opt to scrīpt only those that you intend to call if you want to.
The calling code will simply throw an exception
if it tries to invoke a method that isn't defined.
If you wish to override the behavīor of a large number of methods .
say to produce a "dummy" adapter for logging .
you can implement a special method signature:
invoke(name, args) in your scrīpted object.
The invoke() method is called to handle any undefined method invocations:
你不需要实现接口中的所有方法。你可以选择实现那些你打算调用的方法。
如果你尝试调用一个你没有实现的方法,调用代码仅仅简单的抛出一个异常。
如果你希望去覆盖很多方法的行为,制造一个“虚拟”适配器来进行记录。
你可以实现一个特别的方法:invoke(name, args)在你的脚本对象中。
通过invoke()方法调用一些没有定义的方法。
ml = new MouseListener() {
mousePressed( event ) { ... }
// handle the rest 调用其它方法
invoke( name, args ) { print("Method: "+name+" invoked!");
}
8.scrīpted Objects 脚本对象
In BeanShell, as in Javascrīpt and Perl, method "closures" allow you to create scrīpted objects.
You can turn the results of a method call into an object reference
by having the method return the special value this.
You can then use the reference to refer to any variables set during the method call. Useful objects need methods of scrīpted Methods course,
so in BeanShell scrīpted methods may also contain methods at any level.
For example:
在Beanshell中,就像在Javascrīpt和Perl中一样,方法"closures"允许你创建脚本对象。
你可以将一个方法的调用结果通过返回特殊的值this赋给一个对象引用。
在方法的调用中你甚至可以将这个引用赋给一些变量.
有用的对象需要出现在脚本函数中,
于是在Beanshell中脚本方法中的任何地方也可以包含方法。示例:
foo() {
print("foo");
x=5;
bar() {
print("bar");
}
return this;
}
myfoo = foo(); // prints "foo"
print( myfoo.x ); // prints "5"
myfoo.bar(); // prints "bar"
If this "closure" thing seems strange to don't worry.
It's just an evolutionary step that languages acquired along the path to Objects.
Please see the user's manual for a more thorough explanation.
如果这个“closure”看起来很陌生,你也不要担心。
它仅仅是一个渐进的的步骤,是语言需要顺着路径找到对象的步骤。
请看用户使用手册来获取更多信息。
Within your scrīpts, BeanShell scrīpted objects
(i.e. any 'this' type reference like myfoo in the previous example)
can automatically implement any Java interface type.
When Java code calls methods on the interface
the corresponding scrīpted methods will be invoked to handle them.
BeanShell will automatically "cast" your scrīpted object
when you attempt to pass it as an argument to a method that takes an interface type. For passing scrīpt references outside of BeanShell,
you can perform an explicit cast where necessary.
Please see the user manual for full details.
在你的脚本中,Beanshell脚本对象(比如上例中的myfoo这个this引用)可以自动的实现一些Java接口。
当Java代码在接口中调用方法的时候,响应的脚本函数将被调用去处理它们。
当你通过传入一个参数调用一个函数的时候,Beanshell将自动的转换你的脚本对象。
因为允许的脚本引用是在Beanshell之外,你可以在需要的时候执行一个强制转型。
请看用户使用手册来获取完整细节。
Calling BeanShell From Your Application 从你的应用程序中调用Beanshell
You can evaluate text and run scrīpts from within your application
by creating an instance of the BeanShell interpreter and using the eval() or source() commands. You may pass in variable references to objects you wish
to use in scrīpts via the set() method and retrieve results with the get() method.
你可以通过创建一个Beanshell解释者实例和使用eval(),source()命令
,计算一个文本和通过你的引用程序来运行脚本。
你可以通过使用set()和通过get(),将变量引用赋给特定的对象。
import bsh.Interpreter;
Interpreter i = new Interpreter(); // Construct an interpreter 构造一个解释者
i.set("foo", 5); // Set variables 设置变量
i.set("date", new Date() );
Date date = (Date)i.get("date"); // retrieve a variable 返回一个变量
// Eval a statement and get the result 计算一个语句并且返回结果
i.eval("bar = foo*10");
System.out.println( i.get("bar") );
// Source an external scrīpt file 发起一个外部脚本文件
i.source("somefile.bsh");
Tip: 提示
In the above example the Interpreter's eval() method
also returned the value of bar as the result of the evaluation.
在上面的例子中解释者的eval()方法也返回变量bar的值。
9。Conclusion 结束语
We hope this brief introduction gets you started.
Please see the full user manual for more details.
Please consult the mailing list archives for more useful information.http://www.beanshell.org/
我希望这一份摘要可以让你开始。请看完整的用户手册或者更多细节。
请参考邮件列表获取更多有用的信息。http://www.beanshell.org/
             -------------------------20080714北京 


相关阅读:

TAG: Beanshell

引用 删除 wanglihua604   /   2008-09-27 17:23:11
只翻译到12吗?
后面的没有了吗?
我现在在学习这个,一点头绪都没有,如果后面有的话,希望能够给提供一下!
wanglihua604@163.com
谢啦!
 

评分:0

我来说两句

日历

« 2024-04-27  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 25975
  • 日志数: 25
  • 建立时间: 2008-08-27
  • 更新时间: 2008-09-02

RSS订阅

Open Toolbar