ATITIT.BSH BeanShell 's dynamic script uses java
1.1.BeanShell is a small, free JAVA source interpreter
, supports object-style scripting language features, and can be embedded in JAVA source code.
It can also be embedded in Java source code, dynamically executes java Source code and extends some features of the scripting language, like JavaScript and Perl that kind of weak type, imperative, closure function, and so on.
BeanShell can understand standard JAVA statements, expressions, and method declarations. The contents of statements and expressions can be: variables, declarations, assignments, method invocations, loops, conditions, and so on.
in Java programs you have to use them strictly, but in BeanShell , you can use the " loose type " ( Loosely typed) way to use them. That is, you can be lazy when writing a script, without declaring the variable type ( Both the original data type and the object can be ). If you try to use the wrong variable type,BeanShell will give you an error.
author:: Nickname:Old Wow's claws( Full Name::AttilaxAkbar Al Rapanui Attilaksachanui) Kanji Name:Ayron, email:[email protected]
Reprint please indicate source: http://www.cnblogs.com/attilax/
2.operating mode:
interface UI mode:java BSH. Console
L command line mode:java BSH. Interpreter
L Run the script file:java BSH. interpreter filename [args]
3.BeanShell will become The third programming language on the Java platform
JCP accepted a new technical specification into the standardization process, and the JSR-274 specification would introduce BeanShell as Java Another programming language supported on the platform.
JSR-274(http://jcp.org/en/jsr/detail?id=274) is byPatrick NiemeyerThe purpose of the technical specification submitted is toBeanShellscripting language (http://www.beanshell.org/) normalized toJavaThe third programming language supported on the virtual machine platform. ExceptJavaOutside,Javavirtual machines also supportGroovyscripting language. Doug Lea,Apacheand theGooglethree xJCPmembers of the Executive Board expressed support for the specification.
According toJavaThe original design ideas, there are many languages can be inJVMon the run (detailed list seehttp://en.wikipedia.org/wiki/List_of_Java_scripting_languages), but most of these languages are not popular. Until2004years,Javathe platform actually has only one programming language, namelyJava. 2004years3months,Groovy(JSR-241) became aJavathe second programming language on the platform.
3.1.Define Method3.2.scripted Methods
You can declare and use methods in BeanShell just as you would in a Java class.
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.
Add (A, b) { return a + B; } Foo = Add (1, 2); 3 Foo = Add ("Oh", "Baby"); "Oh Baby" |
3.3.Implementing Interfaces
Note:implementing arbitrary interfaces requires BeanShell be run under a Java 1.3 or higher environment.
You can use the standard Java anonymous inner class syntax to implement an interface type with a script. For example:
ActionListener Scriptedlistener = new ActionListener () { Actionperformed (Event) {...} } |
You don ' t has to script all of the methods of the interface. You can opt-in script only those this intend to the call if you want to. The calling code would simply throw a exception if it tries to invoke a method of that isn ' t defined. If you wish to override the behavior 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 scripted object. The Invoke () method is called to handle any undefined method invocations:
ml = new MouseListener () { Mousepressed (Event) {...} Handle the rest Invoke (name, args) {print ("Method:" +name+ "invoked!"); } |
4.Refe
BeanShell(JAVA Source code interpreter)_ Baidu Encyclopedia . htm
BeanShell QuickStart ---Java application scripting engine -Love program-blogjava.htm
Quick start.htm
Embedding BeanShell in Your application.htm
BeanShell Commands documentation.htm
ATITIT.BSH BeanShell's dynamic script uses Java