Beanshell翻譯11


1.Undefined Variables 沒有定義的變量
You can test to see if a variable is defined using the special value void. For example:
你可以看一下,當一個變量用特殊的值void來進行定義的時候,例如:
if ( foobar == void )
// undefined 沒有定義
You can return a variable to the undefined state using the unset() command:
你可以使用unset()命令,返回一個沒有定義狀態的變量。
a == void; // true
a=5;
unset("a"); // note the quotes 注意這個引用
a == void; // true
Setting the Command Prompt 設置命令提示
Users may set the command line prompt string for use in interactive mode
by setting the value of the variable bsh.prompt or
by defining the scrīpted method (or command) getBshPrompt().
用戶可以通過設置命令行prompt字符串,
設置變量bsh.prompt的值或者是通過定義腳本函數getBshPrompt()
來在交互模式下使用。
If the command or method getBshPrompt() is defined
it will be called to get a string to display as the user prompt.
For example, one could define the following method
to place the current working directory into their command prompt:
如果命令或者函數getBshPrompt()被定義,它將被調用,取得一個用於提示用戶的字符串。
例如,一個人可以定義下面的函數,將當前的工作路徑進入它的命令提示。
getBshPrompt() { return bsh.cwd + " % "; }
The default getBshPrompt() command returns the value of the variable bsh.prompt
if it is defined or the string "bsh % " if not.
If the getBshPrompt() method or command does not exist, throws an exception,
or does not return a String, a default prompt of "bsh % " will be used.
默認的getBshPrompt()命令返回變量bsh.prompt的值,條件是如果它被定義了或者
字符串"bsh % "沒有定義。
如果getBshPrompt()函數或者命令不存在,拋出一個異常,
或者沒有返回一個字符串,一個默認的"bsh % "的提示將被使用。
BeanShell Commands Beanshell命令
BeanShell commands appear to the user as pre.defined methods such as print(), load(), or save().
BeanShell Commands can be implemented as scrīpted methods or compiled Java classes
which are dynamically loaded on demand from the classpath.
We'll talk about adding your own commands in the next section "Adding BeanShell Commands".
Beanshell命令對用戶來說就是一些提前定義的函數例如print(),load(),或者save().
Beanshell命令可以使用腳本函數或者編譯好的Java類來實現,其中
Java類是可以按要求從類路徑中動態加載的。
我們將在下一章"Adding BeanShell Commands"中談談添加你自己的命令。
Tip: 提示:
You can easily override any BeanShell command simply
by defining the method yourself in your scrīpt. For example:
通過在腳本中定義你自己的函數,你可以很容易的重寫Beanshell命令。例如:
print( arg ) {
System.out.println( "You printed: " + arg );
}
If you define the method in the global scope it will apply everywhere.
If you define it local to a scrīpted object it will only apply in that object context.
如果你定義函數在全局的作用域中,它將在任何地方應用。
如果你在一個腳本對象中定義它爲本地的,它將只能在對象環境中應用。
2.Commands Overview 命令的總的看法
This is a high level overview of the BeanShell command set.
You can find full documentation for all BeanShell commands
in the "BeanShell Commands Documentation" section of this manual.
See also the "BshDoc" section
which covers javadoc style documentation of BeanShell scrīpt files.
這裏是Beanshell的命令設置的高度概括。
你可以找到關於Beanshell命令的完整文檔,在"Beanshell Commands Documentation"章節中。
也可以"BshDoc"章節,這個章節講解了Beanshell腳本文件的javadoc樣式的文檔。
3.Interpreter Modes 解釋器模式
The following commands affect general modes of operation of the interpreter.
下面的命令影響解釋器操作的常用模式。
exit() Exit the interpreter. (Also Control.D).
退出解釋器
show()
Turn on "show" mode
which prints the result of every evaluation that is not of void type.
show() 打開"show"模式,這個模式是用來打印每個計算的結果的。
setAccessibility()
Turn on access to private and protected members of Java classes.
setAccessibility() 打開Java類的私有和受保護變量的存取。
server()
Launch the remote access mode,
allowing remote access to the interpreter from a web browser or telnet client.
server() 打開遠程存取模式,允許從一個web瀏覽器或者是遠程登錄客戶端,對解釋器進行遠程存取。
debug()
Turns on debug mode. Note: this is very verbose, unstructured output and is primarily of
interest to developers.
debug() 打開調試模式。注意:這裏是非常詳細的,非結構化的輸出,並且最初對開發者來說是很有趣的。
setStrictJava()
Turn on "strict Java" mode
which enforces Java compatibility by dissallowing loose types and undeclared variables.
setStrictJava() 打開"strict Java"模式,
這個模式,這個模式可以強迫Java不接受鬆散類型和未定義的變量。
Output 輸出
The following commands are used for output:
下面的命令是用來做輸出的:
print(), error() Print output to standard out or standard error.
print(), error()打印輸出到標準輸出或者標準錯誤。
print() always goes to the console,
whereas System.out may or may not be captured by a GUI console or servlet.
print()也可以去控制檯,
然而System.out可以被一個GUI控制檯或者servlet捕捉,也可以不這樣。
frame() Display the AWT or Swing component in a Frame
frame()在一個Frame中顯示AWT或者Swing組件
4.Source and Evaluation 源和計算表達式
The following commands are used for evaluation or to run external scrīpts or applications:
下面的命令是用來計算表達式或者運行第三方的腳本或者應用程序:
eval() Evaluate a string as if it were typed in the current scope.
eval() 計算一個字符串,當它定義在當前的作用域中。
source(), sourceRelative()
Read an external scrīpt file into the interpreter and evaluate it in the current scope
讀取一個第三方的腳本文件進入解釋器並且在當前的作用域中計算它。
run(), bg()
Run an external file in a subordinate interpreter or
in a background thread in a subordinate interpreter.
在一個從屬的解釋器中,運行一個第三方的文件。
exec()
Run a native executable in the host OS
在主機OS中,運行一個本地的可以執行的腳本。
Utilities 有效性
The following commands are useful utilities:
下面的命令是很有效的:
javap() Print the methods and fields of an object, similar to the output of javap
javap() 打印一個對象的方法和屬性,和javap的輸出類似。
which()
Like the Unix 'which' command for executables.
Map the classpath and determine the location of the specified class.
就像Unix中的'which'命令一樣。
繪製類路徑,並且決定特殊類的位置。
load(), save()
load a serializable object from a file or save one to a file.
Special handling is provided for certain objects.
從一個文件中,加載一個序列化的對象,或者將它存到文件中。
特殊處理是提供確定的對象。
object() Create an "empty" object context to hold variables; analogous to a Map.
創建一個空對象環境,用來保存變量;類似於一個Map.
5.Variables and Scope 變量和作用域
The following commands affect the current scope: 下面的命令影響當前的作用域:
clear() Clear all variables, methods and imports from the current scope.
clear() 清理所有的變量,方法和從當前作用域中導入的東西。
unset() Remove a variable from the current scope. (Return it to the "undefined" state).
unset() 從一個當前的作用域中移除一個變量。(將它返回個"undefined"狀態)。
setNameSpace()
Set the current namespace to a specified scope.
Effectively bind the current scope to a new parent scope.
設置當前名字空間爲一個特殊的作用域。
有效的將當前的作用域綁定到一個新的父親作用域上面。
6.Classpath 類路徑
The following commands manipulate or access the classpath:
下面的命令巧妙的操作來存取類路徑:
addClassPath(), setClassPath(), getClassPath() Modify the BeanShell classpath.
修改Beanshell類路徑。
reloadClasses() Reload a class or group of classes.
重新加載一個類或者一羣類。
getClass()
Load a class explicitly taking into account the BeanShell classpath.
從Beanshell類路徑下面明確的加載一個類。
getResource() Get a resource from the classpath.
從類路徑中取得一個源。
發佈了0 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章