1 / 16

Rhino – JavaScript for Java

Rhino – JavaScript for Java. Rhino – JavaScript for Java. Speaker: Brent Wilkins. Hertz – Applications Consultant Cobol developer – 20+ years PowerBuilder developer – 6 years Java developer – 10+ years Email: bwilkins@hertz.com. Rhino – JavaScript for Java. What is it?

naiara
Download Presentation

Rhino – JavaScript for Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rhino – JavaScript for Java

  2. Rhino – JavaScript for Java Speaker: Brent Wilkins • Hertz – Applications Consultant • Cobol developer – 20+ years • PowerBuilder developer – 6 years • Java developer – 10+ years • Email: bwilkins@hertz.com

  3. Rhino – JavaScript for Java What is it? Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users.

  4. Rhino – JavaScript for Java Most people who have used JavaScript before have done so by adding scripts to their HTML web pages. However, Rhino is an implementation of the core language only and doesn't contain objects or methods for manipulating HTML documents. • Rhino contains: • All the features of JavaScript 1.7 • Allows direct scripting of Java • A JavaScript shell for executing JavaScript scripts • A JavaScript compiler to transform JavaScript source files into Java class files • A JavaScript debugger for scripts executed with Rhino

  5. Rhino – JavaScript for Java Outline: • JavaScript context • Optimization levels • Initializing and scripting the basic Java objects • Scripting custom objects • Evaluating JavaScript expressions

  6. Rhino – JavaScript for Java JavaScript Context The Rhino JavaScript Context object is used to store thread-specific information about the execution environment. There should be one and only one Context associated with each thread that will be executing JavaScript. Import org.mozilla.javascript.Context; To associate the current thread with a Context, simply call the enter method of Context: Context jsContext = Context.enter(); Once you are done with execution, simply exit the Context: Context.exit();

  7. Rhino – JavaScript for Java Optimization Levels

  8. Rhino – JavaScript for Java Initializing and scripting the basic Java objects org.mozilla.javascript.Scriptable The basic Java objects (String, Boolean, Integer, etc.) must be initialized within the JavaScript Context. This allows for access to custom Java objects from with the Context. Scriptable script = jsContext.initStandardObjects();

  9. Rhino – JavaScript for Java Demo time

  10. Rhino – JavaScript for Java Scripting custom objects Convert the object from Java to a JavaScript scriptable object Scriptable jsArgs = Context.toObject( obj, script ); Add the JavaScript object to the other Scriptable objects in the context script.put( objectName, script, jsArgs );

  11. Rhino – JavaScript for Java Evaluating JavaScript expressions Object result = jsContext.evaluateString( script, expression, expression, 1, null ); • Determine the result type of the return object: • String String stringResult = Context.toString( result ); • Boolean booleanboolResult = Context.toBoolean( result );

  12. Rhino – JavaScript for Java Demo time

  13. Rhino – JavaScript for Java Thermal Printing at Hertz • Must be able to access data from the Rental Agreement • Must be able to evaluate psuedocode that contains: • AND, OR • () order of operations • =, <>, <, >, <=, >= • IN and NIN – Evaluates if a variable is in a group of values

  14. Rhino – JavaScript for Java Thermal Printing at Hertz • Must be able to access data from the Rental Agreement • Must be able to evaluate psuedocode that contains: • AND, OR &&, || • () order of operations • =, <>, <, >, <=, >= ==, != • IN and NIN – Evaluates if a variable is in a group of values • IN Java method isInGroup( “|” + var + “|”, “|value|value|value|” ) • NIN !isInGroup()

  15. Rhino – JavaScript for Java Demo time

  16. Rhino – JavaScript for Java Resources http://www.mozilla.org/rhino/ http://www.rhino-tutorial.buss.hk/

More Related