Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bean Scripting Framework.. What is Scripting Language Broader definition: all languages Narrower definition: those programming languages requiring no.

Similar presentations


Presentation on theme: "Bean Scripting Framework.. What is Scripting Language Broader definition: all languages Narrower definition: those programming languages requiring no."— Presentation transcript:

1 Bean Scripting Framework.

2 What is Scripting Language Broader definition: all languages Narrower definition: those programming languages requiring no compilation or with implicit compilation

3 For example: JavaScript source: http://zh.wikipedia.org/wiki/JavaScript

4 Why Scripting Languages? simplicity real time most scripting languages have good UI integration plenty of choices

5 Where to Use Scripting Languages? integrated with UI languages, e.x., html vs. JavaScript event-based scenarios, e.x., XSLT vs. xpath programming with less ability but more simplicity, e.x., JSP

6 Drawbacks Performance!!

7 Java + Scripting Language Background Java performs better, but more complicated in syntax and requires compilation Scripting languages (e.x., JavaScript) are much slower (almost 1000x), but much easier in syntax and requires no compilation

8 Java + Scripting language is a good compromise use java in major part use scripting language for some customizable parts but how?

9 JVM byte code script Scripting Engine load scripting engine with JVM, and pass scripting parts into the scripting engine. However, different scripting engines have different interfaces……

10 Bean Scripting Framework Actually, there is a plan to add common scripting interface into JVM with JavaSE 7.0 but when can we have JavaSE 7.0 ?! Now, we have apache bean scripting framework http://jakarta.apache.org/bsf/

11 BSFManager BSFEngine JRubyEngineJavaScriptEnginePythonEngine ……

12 Usage Register script engine to BSFManager BSFManager.registerScriptingEngine("ruby", "org.jruby.javasupport.bsf.JRubyEngine", new String[]{"rb"}); Create an instance of BSFManager BSFManager manager=new BSFManager(); Load registered script engine from the manager engine=manager.loadScriptingEngine("ruby");

13 Execute the scripting code, so it is kept in the memory engine.exec("ruby", 0, 0, ……script code……); Call target method declared in the scripting code engine.call(null, "actionPerformed", new java.lang.Object[]{self, arg0});

14 This is Ruby!!

15 Why use Ruby? Simple yet powerful exactly the same expressive power with java good bridging with jvm http://jruby.codehaus.org/

16 Language Constructs require 'java' module Java include_package "java.lang" include_package "javax.swing" include_package "util.ws" include_package "java.util" end def actionPerformed(caller, actionEvent) if actionEvent.getActionCommand()=="HelloWorld" Java::JOptionPane.showMessageDialog(caller, "HelloWorld") elsif actionEvent.getActionCommand()=="HelloWS" response=Java::WebServiceClient.send("http://localhost:8084/SpringWSTest/services", " ") Java::JOptionPane.showMessageDialog(caller, response) elsif actionEvent.getActionCommand()=="HelloSoapHeaders" props=Java::HashMap.new props.put("{ns1}key1","value1") props.put("{ns2}key2",['_value1','_value2','_value3'].to_java) response=Java::WebServiceClient.send("http://localhost:8084/SpringWSTest/services", " ", props) Java::JOptionPane.showMessageDialog(caller, response) end load java support import java.lang.*; import javax.swing.*; import util.ws.*; import java.util.*; define function

17 require 'java' module Java include_package "java.lang" include_package "javax.swing" include_package "util.ws" include_package "java.util" end def actionPerformed(caller, actionEvent) if actionEvent.getActionCommand()=="HelloWorld" Java::JOptionPane.showMessageDialog(caller, "HelloWorld") elsif actionEvent.getActionCommand()=="HelloWS" response=Java::WebServiceClient.send("http://localhost:8084/SpringWSTest/services", " ") Java::JOptionPane.showMessageDialog(caller, response) elsif actionEvent.getActionCommand()=="HelloSoapHeaders" props=Java::HashMap.new props.put("{ns1}key1","value1") props.put("{ns2}key2",['_value1','_value2','_value3'].to_java) response=Java::WebServiceClient.send("http://localhost:8084/SpringWSTest/services", " ", props) Java::JOptionPane.showMessageDialog(caller, response) end load java support import java.lang.*; import javax.swing.*; import util.ws.*; import java.util.*; define function


Download ppt "Bean Scripting Framework.. What is Scripting Language Broader definition: all languages Narrower definition: those programming languages requiring no."

Similar presentations


Ads by Google