Rhino Java Script for Java Rhino Java Script

  • Slides: 16
Download presentation
Rhino – Java. Script for Java

Rhino – Java. Script for Java

Rhino – Java. Script for Java Speaker: Brent Wilkins • Hertz – Applications Consultant

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

Rhino – Java. Script for Java What is it? Rhino is an open-source implementation

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

Rhino – Java. Script for Java Most people who have used Java. Script before

Rhino – Java. Script for Java Most people who have used Java. Script 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 Java. Script 1. 7 Allows direct scripting of Java A Java. Script shell for executing Java. Script scripts A Java. Script compiler to transform Java. Script source files into Java class files • A Java. Script debugger for scripts executed with Rhino

Rhino – Java. Script for Java Outline: • • • Java. Script context Optimization

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

Rhino – Java. Script for Java. Script Context The Rhino Java. Script Context object

Rhino – Java. Script for Java. Script Context The Rhino Java. Script 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 Java. Script. Import org. mozilla. javascript. Context; To associate the current thread with a Context, simply call the enter method of Context: Context js. Context = Context. enter(); Once you are done with execution, simply exit the Context: Context. exit();

Rhino – Java. Script for Java Optimization Levels -1 Interpretive mode is used. No

Rhino – Java. Script for Java Optimization Levels -1 Interpretive mode is used. No objects are compiled. 0 No optimization is performed. Objects are compiled to bytecode. 1– 9 All optimizations are performed.

Rhino – Java. Script for Java Initializing and scripting the basic Java objects org.

Rhino – Java. Script 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 Java. Script Context. This allows for access to custom Java objects from with the Context. Scriptable script = js. Context. init. Standard. Objects();

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Scripting custom objects Convert the object from Java

Rhino – Java. Script for Java Scripting custom objects Convert the object from Java to a Java. Script scriptable object Scriptable js. Args = Context. to. Object( obj, script ); Add the Java. Script object to the other Scriptable objects in the context script. put( object. Name, script, js. Args );

Rhino – Java. Script for Java Evaluating Java. Script expressions Object result = js.

Rhino – Java. Script for Java Evaluating Java. Script expressions Object result = js. Context. evaluate. String( script, expression, exp Determine the result type of the return object: • String string. Result = Context. to. String( resul • Boolean bool. Result = Context. to. Boolean( resul

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Thermal Printing at Hertz • Must be able

Rhino – Java. Script 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

Rhino – Java. Script for Java Thermal Printing at Hertz • Must be able

Rhino – Java. Script 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 NIN Java method is. In. Group( “|” + var + “|”, “|value|value|” ) !is. In. Group()

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Demo time

Rhino – Java. Script for Java Resources http: //www. mozilla. org/rhino/ http: //www. rhino-tutorial.

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