天天看點

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.

從類路徑中取得一個源。