rhino – javascript for java. speaker: brent wilkins hertz – applications consultant – cobol...
TRANSCRIPT
![Page 1: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/1.jpg)
Rhino – JavaScript for Java
![Page 2: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/2.jpg)
Speaker: Brent Wilkins
• Hertz – Applications Consultant– Cobol developer – 20+ years– PowerBuilder developer – 6 years– Java developer – 10+ years– Email: [email protected]
Rhino – JavaScript for Java
![Page 3: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/3.jpg)
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.
Rhino – JavaScript for Java
![Page 4: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/4.jpg)
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
Rhino – JavaScript for Java
![Page 5: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/5.jpg)
Outline:
• JavaScript context• Optimization levels• Initializing and scripting the basic Java
objects• Scripting custom objects• Evaluating JavaScript expressions
Rhino – JavaScript for Java
![Page 6: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/6.jpg)
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();
Context.exit();
Once you are done with execution, simply exit the Context:
Rhino – JavaScript for Java
![Page 7: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/7.jpg)
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 – JavaScript for Java
![Page 8: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/8.jpg)
Initializing and scripting the basic Java objects
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.
org.mozilla.javascript.Scriptable
Scriptable script = jsContext.initStandardObjects();
Rhino – JavaScript for Java
![Page 9: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/9.jpg)
Demo time
Rhino – JavaScript for Java
![Page 10: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/10.jpg)
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 );
Rhino – JavaScript for Java
![Page 11: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/11.jpg)
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 boolean boolResult = Context.toBoolean( result );
![Page 12: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/12.jpg)
Demo time
Rhino – JavaScript for Java
![Page 13: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/13.jpg)
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 – JavaScript for Java
![Page 14: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/14.jpg)
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()
Rhino – JavaScript for Java
![Page 15: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/15.jpg)
Demo time
Rhino – JavaScript for Java
![Page 16: Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –](https://reader035.vdocument.in/reader035/viewer/2022071806/56649db35503460f94aa3dec/html5/thumbnails/16.jpg)
Rhino – JavaScript for Java
Resources
http://www.mozilla.org/rhino/http://www.rhino-tutorial.buss.hk/