zoukankan      html  css  js  c++  java
  • atitit.bsh BeanShell 的动态脚本使用java

    atitit.bsh BeanShell 的动态脚本使用java

     

     

    1.1. BeanShell是一个小巧免费的JAVA源码解释器

    ,支持对象式的脚本语言特性,亦可嵌入到JAVA源代码中。

    亦可嵌入到JAVA源代码中,能动态执行JAVA源代码并为其扩展了脚本语言的一些特性,像JavaScriptperl那样的弱类型、命令式、闭包函数等等特性都不在话下

     

    BeanShell能理解标准的JAVA语句,表达式,和方法宣告。语句和表达式的内容可以是:变量,宣告,赋值,方法调用,循环,条件等。
    在 Java程序中你必须严格的使用它们,但在BeanShell中,你可以用宽松类型”(loosely typed)的方式来使用它们。也就是说,你可以在写脚本时偷懒,不进行变量类型的宣告(在原始数据类型和对象都可以)。如果你试着用错变量类 型,BeanShell将会给出一个错误。

    作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

    转载请注明来源: http://blog.csdn.net/attilax

     

    2. 运行方式:

    界面UI方式 :java bsh.Console

    命令行方式 :java bsh.Interpreter

    l运行脚本文件:java bsh.Interpreter filename [ args ]

    3. BeanShell将成为Java平台上的第三种编程语言

    JCP接纳了一个新的技术规范进入标准化进程,这个编号为JSR-274的技术规范将把BeanShell引入为Java平台上支持的又一种编程语言。

    JSR- 274http://jcp.org/en/jsr/detail?id=274)是由 Patrick Niemeyer提交的技术规范,其目标是将BeanShell脚本语言(http://www.beanshell.org/)规范化为Java虚拟机 平台上支持的第三种编程语言。除了Java之外,Java虚拟机还支持Groovy脚本语言。Doug LeaApacheGoogle三个JCP执委会成员对此规范表示了支持。

    按照Java最初的设计思路,有很多语言都可以在JVM上 运行(详细列表参见http://en.wikipedia.org/wiki/List_of_Java_scripting_languages), 但这些语言大多没有流行起来。直到2004年为止,Java平台事实上只有一种编程语言,也就是Java20043月,GroovyJSR- 241)成为了Java平台上的第二种编程语言。

    3.1. Define  method

    3.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 have to script all of the methods of an interface. You can opt to script 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 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

     

    BeanShellJAVA源码解释器)_百度百科.htm

    BeanShell快速入门---Java应用程序脚本引擎 - Love program - BlogJava.htm

    Quick Start.htm

    Embedding BeanShell in Your Application.htm

    BeanShell Commands Documentation.htm

  • 相关阅读:
    Apex API 请求
    Apex 的 API 简介
    Salesforce 自定义元数据类型
    Apex 中 DML 进阶知识小结
    深度学习中的Attention机制
    从FM推演各深度CTR预估模型(附代码)
    深入浅出Word2Vector原理解析
    GBDT算法用于分类问题
    特征交叉
    方差膨胀因子VIF
  • 原文地址:https://www.cnblogs.com/attilax/p/5963503.html
Copyright © 2011-2022 走看看