00 0131886703 cavfm -...

26
INDEX A Accessing Application Context listing (10.2), 463 Active File Example listing (8.20), 376 Active File Generator listing (8.22), 380 active file pattern, 375 consequences, 375 problem, 375 sample code, 376-380 solution, 375 Active File Template listing (8.21), 379 ADD keyword, 5 addClassPath( ) method, 324 administration scripting, 328-334 scripting languages, 55-58 Administration Script Example listing (7.17), 329 Advanced Ant BSF Support Example listing (7.13), 315 Advanced AntBuilder Example listing (7.15), 320 Advanced Binding Example—Java Application listing (9.13), 408 Advanced Groovy Programming Example listing (5.22), 225 AJAX (Asynchronous JavaScript And XML), 66 Ant build tools, 309-322 Ant BSF Support Example listing (7.12), 314 Ant task, Groovy, 132-133 Ant Task That Compiles All Scripts Inside the Project listing (8.10), 357 AntBuilder Example listing (7.14), 317 any( ) method, Groovy, 175-177 any( ) Method listing (4.30), 175 Apache Web servers, 62 BSF (Bean Scripting Framework), 94 APIs (application programming interfaces), 49 Java, 80-82 append( ) method, Groovy, 181-182 append( ) Method listing (4.39), 182 application scope, Web environments, 449 application variable (Groovlet), 215 applications BSF (Bean Scripting Framework), 275 JSP (JavaServer Pages), 275-280 Xalan-J (XSLT), 280-287 Java, 79 web applications, 59, 61-67 ASP (Active Server Pages), 64 games, 68-69 JavaScript, 65-67 Perl, 61-62 PHP, 62-64 UNIX, 68

Upload: phamlien

Post on 21-Apr-2018

222 views

Category:

Documents


4 download

TRANSCRIPT

INDEX

AAccessing Application Context listing

(10.2), 463Active File Example listing (8.20), 376Active File Generator listing (8.22), 380active file pattern, 375

consequences, 375problem, 375sample code, 376-380solution, 375

Active File Template listing (8.21), 379ADD keyword, 5addClassPath( ) method, 324administration

scripting, 328-334scripting languages, 55-58

Administration Script Example listing (7.17), 329

Advanced Ant BSF Support Example listing (7.13), 315

Advanced AntBuilder Example listing (7.15), 320

Advanced Binding Example—Java Application listing (9.13), 408

Advanced Groovy Programming Examplelisting (5.22), 225

AJAX (Asynchronous JavaScript AndXML), 66

Ant build tools, 309-322

Ant BSF Support Example listing (7.12), 314

Ant task, Groovy, 132-133Ant Task That Compiles All Scripts Inside

the Project listing (8.10), 357AntBuilder Example listing (7.14), 317any( ) method, Groovy, 175-177any( ) Method listing (4.30), 175Apache Web servers, 62

BSF (Bean Scripting Framework), 94APIs (application programming

interfaces), 49Java, 80-82

append( ) method, Groovy, 181-182append( ) Method listing (4.39), 182application scope, Web environments, 449application variable (Groovlet), 215applications

BSF (Bean Scripting Framework), 275JSP (JavaServer Pages), 275-280Xalan-J (XSLT), 280-287

Java, 79web applications, 59, 61-67

ASP (Active Server Pages), 64games, 68-69JavaScript, 65-67Perl, 61-62PHP, 62-64UNIX, 68

19_1936_index.qxd 7/11/07 12:14 AM Page 503

apply( ) method, 263-264architecture

BSF (Bean Scripting Framework), 248-249

compilers, 9hybrid compiler-interpreters, 11interpreters, 10Java, 80-82Scripting API, 391Web Scripting Framework, 448,

482-488context, 448-449interaction, 451-453servlet, 449-451

arguments, command-line arguments,Groovy, 136

Ascher, David, 29ASP (Active Server Pages), 64assembly languages, 5assertArrayEquals( ) method, 298assertContains( ) method, 299assertEquals( ) method, 294assertion methods, unit testing, 297-300assertLength( ) method, 298assertScript( ) method, 299assertToString( ) method, 299attributes, script context, 419-423autoboxing

BeanShell, 89-90Groovy, 140

Autoboxing listing (4.7), 140AutoCAD, 50

Bbasic syntax

BeanShell, 86-87Python, 101-103

Bean Scripting Framework (BSF). See BSF(Bean Scripting Framework)

beans, BSF (Bean Scripting Framework)declaring, 268-270registering, 265-268

504 INDEX

BeanShell, 80, 83-98, 126commands, 91downloading, 83GUI (graphical user interface), 84Java, embedding with, 94-98manual, 98methods, 91-92modes, 84objects, 92running, 84scripting

autoboxing, 89-90basic syntax, 86-87for loop, 88-89interface implementation, 93-94JavaBeans, 88loosely typed syntax, 87switch-case statement, 90

Workspace Editor, 85“Best Tool for the Job, The”, 36Bezroukov, Nikolai, 68binding, 186

dynamic binding, 442programmatic binding, 442Scripting API, 404-411

dynamic binding, 442-444engine scope, 405-411global scope, 411-416script context, 416-428

Binding Example listing (9.11), 406Binding listing (4.44), 186bindings, Web Scripting Framework, 462

application, 462-464request handling, 464-467response, 468servlet, 468-469

bootstrap class loaders (JVM), 81Broadcasters Example listing (8.17), 367broadcasters pattern, 359

consequences, 362problem, 359-360related patterns, 369

19_1936_index.qxd 7/11/07 12:14 AM Page 504

sample code, 362-369solution, 360-362

BSF (Bean Scripting Framework), 94, 245-246Ant scripting, 313-316applications, 275

JSP (JavaServer Pages), 275-280Xalan-J (XSLT), 280-287

architecture, 248-249beans

declaring, 268-270registering, 265-268

compilation, 270-275data binding, 264-270downloading, 247engine initialization, 252exception handling, 255functions, 259-264manager initialization, 252methods, 259-264origins of, 247script files, executing, 257-259Scripting API, compared, 445scripting language registration, 249-252scripts, 253-257

BSF Exception Handling listing (6.2), 256BSF JSP Example listing (6.20), 279BSFEngine.apply( ) Method Example

listing (6.7), 263BSFEngine.eval( ) Method Example

listing (6.1), 254BSFEngine.exec( ) Method Example

listing (6.3), 256BuilderSupport, Groovy, 235-236building tools, Ant scripting, 309-322built-in functions, 19bytecode, 7

CC++, Java, compared, 78call( ) method, 169, 260Cascading Style Sheets (CSS), 66CBD (component-based development), 40

INDEX 505

changed( ) method, 347class files, Java, 80class loaders (JVM), 81

bootstrap class loaders, 81user-defined class loaders, 82

classes, 14Groovy, 159-161JavaAdapter class, 114

Classes listing (4.17), 159classpaths, Groovy, setting, 131-132closures

Groovy, 168-177curly braces, 172resource handling, 176-177

method closure, 92methods, curly braces, 172scripting language, 20

Closures listing (4.23), 170code. See also listings; scripts

active file pattern, 376-380as data, 19-23bytecode, 7development speed, 28-29extension point pattern, 371-374mediator scripting pattern, 345-354observer pattern, 362-369operation code, 4runtime performance, 26-28script object factory pattern, 356-359scripted components pattern, 340-341source code, production environment,

12-13code generation, Scripting API, 428

method call syntax, 429-431output statement, 429programs, 431-432

collect( ) method, Groovy, 173collect( ) Method listing (4.25), 173collections, Groovy, 148

lists, 149-151maps, 152-153ranges, 151-152

19_1936_index.qxd 7/11/07 12:14 AM Page 505

command-line arguments, Groovy, 136commands, 19

BeanShell, 91compatibility, Java and Groovy, 137Compilable interface, 437-440Compilable listing (9.35), 438compilation, BSF (Bean Scripting

Framework), 270-275compilation languages, 52Compile Example listing (6.13), 271Compile Example—Result listing (6.14), 271compile( ) method, 275Compiled Script Usage Example

listing (6.18), 274compileExpr( ) method, 272compilers, 6

architecture, 9hybrid compiler-interpreters, 11interpreters, compared, 8-12

compiling scripts, Groovy, 130-133Compiling Groovy Scripts with Ant

listing (4.2), 132component-based development (CBD), 40components pattern (scripting), 337

consequences, 339problem, 337-338related patterns, 341sample code, 340-341solution, 338-339

composite types, programming languages, 14

computer programs, 5configuration

Groovy, 492Web Scripting Framework, 456-462

consequencesactive file pattern, 375extension point pattern, 370mediator scripting pattern, 345observer pattern, 362script object factory pattern, 356scripted components pattern, 339

506 INDEX

context, Web Scripting Framework architecture, 448-449

Creating an Sql Object with DataSourcelisting (5.6), 202

Creating Documents with DomBuilder listing (5.28), 233

cross-platform portability, Java, 77CSS (Cascading Style Sheets), 66curly braces, closures, methods, 172currentThread( ) method, 444Custom Application Context

listing (9.26), 424Custom BuilderSupport Implementation

(BuilderSupport.java) listing (5.30), 235Custom Engine Writer Example

listing (9.28), 427custom namespaces, 423-427Customized compileExpr( ) Method

listing (6.15), 272Cygwin, 323

DDAO (Database Access Object) design

paradigm, 196data binding, BSF (Bean Scripting

Framework), 264-270data structures, scripting languages, 17-19Database Access Object (DAO) design

paradigm, 196database queries, GroovySQL, 202-205databases, transactions, GroovySQL,

208-209datasets, GroovySQL, 209-212Davidson, James Duncan, 52, 311debugging, interactive debugging,

304-309Declare Bean Example—Java Application

listing (6.11), 269Declare Bean Example—Script

listing (6.12), 270declareBean( ) method, 268-269declaring beans, BSF (Bean Scripting

Framework), 268-270

19_1936_index.qxd 7/11/07 12:14 AM Page 506

Defining a Custom Namespace listing (9.25), 424

dependencies, Groovy, 131design patterns, scripting, 335-337

active file pattern, 375-380extension point pattern, 369-374mediator pattern, 341-354observer pattern, 359-369script object factory pattern, 354-359scripted components pattern, 337-341

Design Patterns, 336Determining the Attribute’s Scope

listing (9.21), 420development, CBD (component-based

development), 40development speed, code, 28-29DHTML (Dynamic Hypertext Markup

Language), 66Dickerson, Chad, 56disabling scripting, Web Scripting

Framework, 456-457discovery mechanism, Scripting API,

391-393Discovery Mechanism listing (9.1), 393DomBuilder, Groovy, 232-233doSomeAction( ) method, 374downloading

BeanShell, 83BSF (Bean Scripting Framework), 247Groovy, 491Jython, 98Rhino, 110

dynamic binding, 442, Scripting API, 442-444

Dynamic Binding—Java Classes listing (9.39), 443

Dynamic Binding—Java Objects listing (9.38), 443

Dynamic Hypertext Markup Language(DHTML), 66

dynamic languages, 6“Dynamic Languages—Ready for the Next

Challenges, by Design,” 29

INDEX 507

dynamic linking, Java, 78dynamic typing, 15-16

Groovy, 139-140Dynamic Typing and Polymorphism

listing (4.6), 139

Eeach( ) method, GroovySQL, 171-172, 211each( ) Method listing (4.24), 172each( ) Method listing (5.15), 211eachByte( ) method, Groovy, 180-181eachByte( ) Method listing (4.36), 181eachFile( ) method, Groovy, 182eachFile( ) Method listing (4.40), 182eachFileRecurse( ) method, Groovy, 182eachFileRecurse( ) Method

listing (4.41), 182eachLine( ) method, Groovy, 179eachLine( ) Method listing (4.33), 179eachRow( ) method, GroovySQL, 202-203eachRow( ) Method and GString Query

Parameters listing (5.7), 202eachRow( ) Method and List Query

Parameters listing (5.8), 203Eckel, Bruce, 30Eclipse IDE, 130embedding

BeanShell with Java, 94-98Groovy, 184-190Pyhton with Java, 108-109Rhino with Java, 114-120scripting languages, 70

engine initialization, BSF (Bean ScriptingFramework), 252

engine interfaces, Scripting API, 432Compilable interface, 437-440Incovable interface, 432-437

engine metadata, Scripting API, 393-395Engine Metadata listing (9.2), 394engine readers, 427-428engine scope

binding, Scripting API, 405-411overriding, 407-409

19_1936_index.qxd 7/11/07 12:14 AM Page 507

engine writers, 427-428eval( ) method, 19, 96, 400-404evaluate( ) method, 184evaluating scripts, Scripting API, 400-404Evaluating a Script in the Script Context

listing (9.20), 418Evaluating Groovy Scripts from Java

listing (4.43), 184Evaluating Inline Scripts Under Security

Policy listing (4.49), 193Evaluating Script Contained in a File

listing (9.8), 401Evaluating Script Contained in a String

listing (9.7), 400every( ) method, Groovy, 175every( ) Method listing (4.29), 175evolutionary prototyping, 46Example php.ini Configuration

listing (9.37), 442exception handling

BSF (Bean Scripting Framework), 255Python, 107-108

exec( ) method, 270execute( ) method, GroovySQL, 205-206execute( ) Method listing (5.10), 205executeUpdate( ) method, GroovySQL,

204-205executeUpdate( ) Method and CSV Files

listing (5.9), 204executing script files, BSF (Bean Scripting

Framework), 257, 259Executing a Script File listing (6.4), 258execution engine (JVM), 81-82explicit memory management, 78exportAsCSV( ) method, 377exportAsSQL( ) method, 377exportAsXML( ) method, 377expressions, regular expressions, Groovy,

146-148Extended XSLT Example listing (6.22), 282Extending the switch-case Mechanism

listing (4.15), 156

508 INDEX

extensibility, scripting language, 70-71Extensible Stylesheet Language

Transformation (XSLT), 280Extension Point Example

listing (8.18), 371extension point pattern, 369

consequences, 370problem, 369related patterns, 374sample code, 371-374solution, 370

extreme programming, 33-35

Ffail( ) method, 294files, system operations, Groovy, 178-182filter( ) function, 21filter( ) method, 22filters, 41find( ) method, Groovy, 174find( ) Method listing (4.27), 174findAll( ) method, Groovy, 174-175findAll( ) method, GroovySQL, 211-212findAll( ) Method listing (4.28), 174findAll( ) Method listing (5.16), 212Foemmel, Matthew, 292Font dialog box, 351for loop

BeanShell, 88-89Groovy, 157

for Loop listing (4.16), 157forward( ) method, Web Scripting

Framework, 471-473Fowler, Martin, 292frame( ) method, 237Function Call Example listing (6.5), 260functions

as method arguments, 21-23BSF (Bean Scripting Framework),

259-264built-in functions, 19eval( ), 19filter( ), 21

19_1936_index.qxd 7/11/07 12:14 AM Page 508

Incovable interface, 433-434over( ), 21printColor( ), 140someFunc( ), 103upper( ), 102

Ggames, scripting in, 68-69garbage collector (JVM), 78General Scripting API, 389generating code, Scripting API, 428-432generics, Java, 31get( ) method, 95getBindings( ) method, 412getComponent( ) method, 347getEngineByExtension( ) method, 398getEngineByExtension( ) Method Example

listing (9.5), 398getEngineByMimeType( ) method, 398getEngineByName( ) method, 397getEngineByName( ) Method Example

listing (9.4), 397getInterface( ) method, 97getLanguageName( ) method, 394getMethodCallSyntax( ) method, 429-431getOutputStatement( ) method, 429getScriptEngine( ) method, 395-396getScriptEngine( ) Method Example

listing (9.3), 395getter/setter methods, 165getText( ) Method listing (4.32), 178getText( ) method, Groovy, 178global scope

binding, Scripting API, 411-416initialization, 415-416variables, overriding, 413-414

Global Scope Example listing (9.15), 412Global Scope Initialization

listing (9.18), 415Glue Code Client listing (8.8), 352glue code pattern, 341

consequences, 345problem, 341-342

INDEX 509

related patterns, 354sample code, 345-354solution, 342-345

glue languages, 41graphical user interfaces (GUIs). See GUIs

(graphical user interfaces)Groovlet Deployment Descriptor

listing (5.17), 214Groovlet Example listing (5.18), 218Groovlets, 212-219

variables, 214Groovy programming language, 80,

120-121, 125, 194-195advantages of, 126Ant task, 132-133any( ) method, 175-177autoboxing, 140BuilderSupport, 235-236classes, 159-161classpaths, setting, 131-132closures, 168-177

curly braces, 172resource handling, 176-177

collect( ) method, 173collections, 148

lists, 149-151maps, 152-153ranges, 151-152

configuring, 492DomBuilder, 232-233downloading, 491dynamic typing, 139-140each( ) method, 171-172every( ) method, 175find( ) method, 174findAll( ) method, 174-175Groovlets, 212-219

variables, 214GroovyBeans, 165

named parameters, 166-167object navigation, 167properties, 165-166safe navigation, 168

19_1936_index.qxd 7/11/07 12:14 AM Page 509

GroovySQL, 196-212database queries, 202-205datasets, 209-212each( ) method, 211eachRow( ) method, 202-203execute( ) method, 205-206executeUpdate( ) method, 204-205findAll( ) method, 211-212object creation, 199-207prepared statements, 206-207Sql.loadDriver( ) method, 199-200stored procedures, 207-208transactions, 208-209

IDE support, 495-497inject( ) method, 173-174installing, 127, 491-492interactive console, 128-129interactive shell, 127-128JAR (Java Archive) files, 491Java

compatibility with, 137embedding with, 184-190statements, 138

language syntax, 137-177triple-quote syntax, 144-145

logical branching, 154-156looping, 156-158loose typing, 138-140Markup syntax, 223-236NamespaceBuilder, 234NodeBuilder, 227-229operator overloading, 162-164polymorphism, 139-140regular expressions, 146-148SaxBuilder, 230-231script files, evaluating, 129-130scripts

command-line arguments, 136compiling, 130-133dependencies, 131running, 127-130structure, 133, 135-136

510 INDEX

security, 190-194strings, 143-145

GStrings, 145-146Swing user interfaces, 236-243switch-case structure, 154-156system operations, 178

files, 178-182processes, 182-183

templates, 220-223testing, 492-493type juggling, 140-143

Groovy Script Structure listing (4.3), 134Groovy Shell listing (4.1), 128Groovy Template Support

listing (5.19), 221GroovyBeans, 165

named parameters, 166-167object navigation, 167properties, 165-166safe navigation, 168

GroovyBeans listing (4.21), 165GroovySQL, 196-212

datasets, 209-212each( ) method, 211eachRow( ) method, 202-203execute( ) method, 205-206executeUpdate( ) method, 204-205findAll( ) method, 211-212objects, creation, 199-207prepared statements, 206-207queries, database queries, 202-205Sql.loadDriver( ) method, 199-200stored procedures, 207-208transactions, 208-209

GroovySQL Example listing (5.1), 197GroovyTestCase class, unit testing,

296-300GroovyTestCase Example listing (7.2), 296GroovyTestCase.assertArrayEquals( )

Method Example listing (7.4), 298GroovyTestCase.assertContains( ) Method

Example listing (7.5), 299

19_1936_index.qxd 7/11/07 12:14 AM Page 510

GroovyTestCase.assertLength( ) MethodExample listing (7.3), 298

GroovyTestCase.assertScript( ) MethodExample listing (7.7), 299

GroovyTestCase.assertToString( ) MethodExample listing (7.6), 299

GroovyTestCase.shouldFail( ) MethodExample listing (7.8), 300

GroovyTestSuite Example listing (7.10), 301

GStrings, Groovy, 145-146GStrings listing (4.9), 145GUIs (graphical user interfaces), 58

BeanShell, 84

Hhandling

command-line arguments, Groovy, 136script evaluation results, 402ScriptException, 403-404sessions, Web Scripting Framework,

473-478Handling Command-Line Arguments in

Groovy listing (4.4), 136Handling Script Evaluation Result

listing (9.9), 402Handling ScriptException

listing (9.10), 403high-level languages, 6HTML (Hypertext Markup Language), 60

CSS (Cascading Style Sheets), 66DHTML (Dynamic Hypertext Markup

Language), 66HTTP (HyperText Transfer Protocol), 60HTTP request handling, Web Scripting

Framework, 464-467HTTP Request Handling—HTML Form

listing (10.3), 465HTTP Request Handling—PHP Script

listing (10.4), 466Hunt, Andy, 53hybrid compiler-interpreters, 11hypertext, 60

INDEX 511

IIDEs, 130

Groovy, support for, 495-497Implementing Java Interfaces in Groovy

listing (4.46), 189implicit memory management, 78include( ) method, Web Scripting

Framework, 469-471Including Resources listing (10.5), 470Incovable interface, 432

functions, 433-434interfaces, 435-437methods, 434-437

initializationengines, BSF (Bean Scripting

Framework), 252global scope, 415-416managers, BSF (Bean Scripting

Framework), 252Sql object with connection, 200-201

Initializing the Sql Object with a Connec-tion—Groovy Script listing (5.5), 201

Initializing the Sql Object with a Connec-tion—Java Class listing (5.4), 200

inject( ) method, Groovy, 173-174inject( ) Method listing (4.26), 173installation

Groovy, 127, 491-492JSR 223 RI (Reference Implementation),

499-502Jython, 99

interaction, Web Scripting Frameworkarchitecture, 451-453

interactive console (Groovy), scripts, running, 128-129

interactive debugging, 304-309Interactive Debugging with the Groovy

Shell listing (7.11), 306interactive mode, BeanShell, 84interactive shell (Groovy), scripts, running,

127-128Intercepting Method Calls

listing (4.18), 161

19_1936_index.qxd 7/11/07 12:14 AM Page 511

interfacesCompilable interface, 437-440engine interfaces, Scripting API,

432-440implementing

BeanShell, 93-94Python, 105-107Rhino, 112-114

Incovable interface, 435-437Interfaces listing (9.34), 436interpreters, 6

architecture, 10compilers, compared, 8-12hybrid interpreter-compilers, 11

Introductory DataSet Example listing (5.14), 209

Introductory JSP Example listing (6.19), 277

Introductory MarkupBuilder Example listing (5.21), 224

Invocable Example listing (9.32), 433invoice( ) method, 92invokeFunction( ) method, 434isCase( ) method, 155-156

JJacl, 122Jakarta Commons Logging project, 247JAR (Java Archive) files, Groovy, 491Java

API (application programming interface), 80-82

applicationsplanning, 79speed issues, 79

architecture, 80-82BeanShell, embedding with, 94-98C++, compared, 78class files, 80commercial release of, 77cross-platform portability, 77dynamic linking, 78generics, 31

512 INDEX

Groovycompatibility with, 137embedding with, 184-190

implicit memory management, 78JVM (Java Virtual Machine), 78-82

BeanShell, 83-98class loaders, 81-82execution engine, 81-82garbage collector, 78Jython, 98-109other programming languages,

82-83Python, 98-109Rhino, 110-120

popularity of, 79programming

administration, 328-334Ant scripting, 309-322interactive debugging, 304-309management, 328-334shell scripting, 323-328unit testing, 292-304

programming language, 80Python

embedding with, 108-109scripting in, 103-105

Rhinoembedding with, 114-120scripting in, 111-112

single inheritance model, 78treading, 77

Java Community Process (JCP), 121, 385Java Database Connectivity (JDBC)

driver, 196Java Runtime Environment (JRE), 24Java Specification Request (JSR), 67Java Specification Request 241, 121Java Virtual Machine (JVM). See JVM

(Java Virtual Machine)JavaAdapter class, Rhino, 114JavaBeans, BeanShell, 88Javagator project, Netscape Navigator, 110

19_1936_index.qxd 7/11/07 12:14 AM Page 512

JavaScript, web applications, 65-67JCP (Java Community Process), 121, 385JDBC (Java Database Connectivity)

driver, 196Jetty servlet, 213JRE (Java Runtime Environment), 24JRuby, 122JSP (Java Server Pages), BSF (Bean

Scripting Framework), 275-280JSR (Java Specification Request), 67JSR 223 RI (Reference Implementation),

installing, 499-502JudoScript, 122JUnit, 293-295JUnit Example listing (7.1), 294JVM (Java Virtual Machine), 7, 24-25,

78-82BeanShell, scripting in, 83-98class loaders, 81

bootstrap class loaders, 81user-defined class loaders, 82

execution engine, 81-82garbage collector, 78Jython, scripting in, 98-109other programming languages, using in,

82-83Python, scripting in, 98-109Rhino, scripting in, 110-120

Jython, 80, 98-109, 126downloading, 98installing, 99switches, 101

K-Lkeys, reversed keys, 410-411keywords (ADD), 5

Label Widget listing (8.4), 347LAMP (Linux, Apache, MySQL, PHP), 386language syntax, Groovy, 137-177

triple-quote syntax, 144-145language tags, Web Scripting Framework,

478-481

INDEX 513

Language Tags—Configuration listing (10.11), 480

Language Tags—Groovy Script listing (10.12), 481

Language Tags—Original Groovy Scriptlisting (10.10), 479

languagescompilation languages, 52programming languages

assembly languages, 5code as data, 19-23compilers, 6data structures, 17-19Groovy programming language, 80,

120-121high-level languages, 6JRuby, 122JudoScript, 122ObjectScript, 123OOP (object-oriented programming)

languages, 40third-generation programming

languages, 6typing, 13-17

scripting languages, 4-24administration, 55-58closures, 20compilers, 8-12customization, 49-51embedding, 70extensiblity, 70-71Groovy, 194interpreters, 8-12Java, 80-82learnability, 71-72management, 55-58method arguments, 21-23Perl, 43prototyping models, 44-48Python, 18software development support,

51-55

19_1936_index.qxd 7/11/07 12:14 AM Page 513

source code, 12-13Tcl (Tool Command Language),

37-44Tcl/Java, 122UNIX shell languages, 41-42user interface programming, 58-59virtual machines, 24-25web applications, 59-69wiring, 40-44

Web Scripting Framework, allowing, 459

Linux, Apache, MySQL, PHP (LAMP), 386List Box Widget listing (8.5), 348listings

4.1 (Groovy Shell), 1284.2 (Compiling Groovy Scripts with

Ant), 1324.3 (Groovy Script Structure), 1344.4 (Handling Command-Line

Arguments in Groovy), 1364.5 (Loose Typing), 1384.6 (Dynamic Typing and

Polymorphism), 1394.7 (Autoboxing), 1404.8 (Triple-Quote Syntax), 1444.9 (GStrings), 1454.10 (Regular Expressions), 1474.11 (Lists), 1504.12 (Ranges), 1514.13 (Maps), 1534.14 (switch-case Structure), 1544.15 (Extending the switch-case

Mechanism), 1564.16 (for Loop), 1574.17 (Classes), 1594.18 (Intercepting Method Calls), 1614.19 (Operators), 1634.20 (Operator Overloading), 1644.21 (GroovyBeans), 1654.22 (Safe Navigation), 1684.23 (Closures), 1704.24 {each( ) Method}, 172

514 INDEX

4.25 {collect( ) Method}, 1734.26 {inject( ) Method}, 1734.27 {find( ) Method}, 1744.28 {findAll( ) Method}, 1744.29 {every( ) Method}, 1754.30 {any( ) Method}, 1754.31 (Resource Handling with

Closures), 1764.32 {getText( ) Method}, 1784.33 {eachLine( ) Method}, 1794.34 {readLines( ) Method}, 1794.35 {splitEachLine( ) Method}, 1804.36 {eachByte( ) Method}, 1814.37 {readBytes( ) Method}, 1814.38 {write( ) Method}, 1814.39 {append( ) Method}, 1824.40 {eachFile( ) Method}, 1824.41 {eachFileRecurse( ) Method}, 1824.42 (Process Handling), 1834.43 (Evaluating Groovy Scripts from

Java), 1844.44 (Binding), 1864.45 (Loading Groovy Scripts as Java

Classes), 1874.46 (Implementing Java Interfaces in

Groovy), 1894.47 (Security Example), 1914.48 (Security Policy), 1914.49 (Evaluating Inline Scripts Under

Security Policy), 1935.1 (GroovySQL Example), 1975.2 (SQL Object Creation

Alternatives), 1995.3 {Sql.loadDriver( ) Method}, 1995.4 (Initializing the Sql Object with a

Connection—Java Class), 2005.5 (Initializing the Sql Object with a

Connection—Groovy Script), 2015.6 (Creating an Sql Object with

DataSource), 2025.7 {eachRow( ) Method and GString

Query Parameters}, 202

19_1936_index.qxd 7/11/07 12:14 AM Page 514

5.8 {eachRow( ) Method and List QueryParameters}, 203

5.9 {executeUpdate( ) Method and CSVFiles}, 204

5.10 {execute( ) Method}, 2055.11 (Stored Procedure), 2075.12 (Stored Procedure Call), 2085.13 (Transactions), 2085.14 (Introductory DataSet

Example), 2095.15 {each( ) Method}, 2115.16 {findAll( ) Method}, 2125.17 (Groovlet Deployment

Descriptor), 2145.18 (Groovlet Example), 2185.19 (Groovy Template Support), 2215.20 (Template Example), 2225.21 (Introductory MarkupBuilder

Example), 2245.22 (Advanced Groovy Programming

Example), 2255.23 (XHTML Markup Example), 2265.24 (NodeBuilder Example), 2275.25 (SAX Handler Example), 2305.26 (SaxBuilder), 2315.27 (Parsing Documents with

DomBuilder), 2325.28 (Creating Documents with

DomBuilder), 2335.29 (Namespace Example), 2345.30 {Custom BuilderSupport Implemen-

tation (BuilderSupport.java)}, 2355.31 (SwingBuilder), 2375.32 (TableLayout), 2395.33 (TableModel), 2416.1 {BSFEngine.eval( ) Method

Example}, 2546.2 (BSF Exception Handling), 2566.3 {BSFEngine.exec( ) Method

Example}, 2566.4 (Executing a Script File), 2586.5 (Function Call Example), 260

INDEX 515

6.6 (Method Call Example), 2626.7 {BSFEngine.apply( ) Method

Example}, 2636.8 (Register Bean Example—JavaBean

Definition), 2666.9 (Register Bean Example—Java

Application), 2676.10 (Register Bean Example—Script),

2676.11 (Declare Bean Example—Java

Application), 2696.12 (Declare Bean Example—Script),

2706.13 (Compile Example), 2716.14 (Compile Example—Result), 2716.15 {Customized compileExpr( )

Method}, 2726.16 (Modified Compile Example), 2736.17 (Modified Compile Example—

Result), 2746.18 (Compiled Script Usage

Example), 2746.19 (Introductory JSP Example), 2776.20 (BSF JSP Example), 2796.21 (Simple XSLT Transformation), 2816.22 (Extended XSLT Example), 2826.23 (Xalan-J Extension Example), 2836.24 (Xalan-J BSF Example), 2857.1 (JUnit Example), 2947.2 (GroovyTestCase Example), 2967.3 {GroovyTestCase.assertLength( )

Method Example}, 2987.4 (GroovyTestCase.assertArrayEquals( )

Method Example), 2987.5 {GroovyTestCase.assertContains( )

Method Example}, 2997.6 {GroovyTestCase.assertToString( )

Method Example}, 2997.7 {GroovyTestCase.assertScript( )

Method Example}, 2997.8 {GroovyTestCase.shouldFail( )

Method Example}, 300

19_1936_index.qxd 7/11/07 12:14 AM Page 515

7.9 (TestSuite Example), 3007.10 (GroovyTestSuite Example), 3017.11 (Interactive Debugging with the

Groovy Shell), 3067.12 (Ant BSF Support Example), 3147.13 (Advanced Ant BSF Support

Example), 3157.14 (AntBuilder Example), 3177.15 (Advanced AntBuilder

Example), 3207.16 (Shell Scripting Example), 3277.17 (Administration Script

Example), 3297.18 (Script Job Example), 3307.19 (Quartz Scheduler Configuration

Example), 3328.1 (Scripted Component Pattern

Example), 3408.2 (Mediator Interface), 3468.3 (Mediator-Aware Widget

Abstraction), 3468.4 (Label Widget), 3478.5 (List Box Widget), 3488.6 (Mediator Implementation), 3498.7 (Mediator Client), 3508.8 (Glue Code Client), 3528.9 (Modified Mediator

Component), 3538.10 (Ant Task That Compiles All Scripts

Inside the Project), 3578.11 (Scripted Object Factory Pattern

Example), 3578.12 (Subject Component), 3638.13 (Observer Label Widget), 3648.14 (Price Observer Label Widget), 3648.15 (Tax Observer Label Widget), 3658.16 (Observer Client), 3658.17 (Broadcasters Example), 3678.18 (Extension Point Example), 3718.19 (Modified Extension Point

Example), 3728.20 (Active File Example), 376

516 INDEX

8.21 (Active File Template), 3798.22 (Active File Generator), 3809.1 (Discovery Mechanism), 3939.2 (Engine Metadata), 3949.3 {getScriptEngine( ) Method

Example}, 3959.4 {getEngineByName( ) Method

Example}, 3979.5 {getEngineByExtension( ) Method

Example}, 3989.6 (Register Engine Example), 3999.7 (Evaluating Script Contained in a

String), 4009.8 (Evaluating Script Contained in a

File), 4019.9 (Handling Script Evaluation

Result), 4029.10 (Handling ScriptException), 4039.11 (Binding Example), 4069.12 (Overriding the Engine Scope), 4079.13 (Advanced Binding Example—Java

Application), 4089.14 (Reserved Keys), 4119.15 (Global Scope Example), 4129.16 (Variables Overriding—An

Example), 4139.17 (ScriptEngineManager’s Shortcut

Methods), 4149.18 (Global Scope Initialization), 4159.19 (Namespace Example), 4169.20 (Evaluating a Script in the Script

Context), 4189.21 (Determining the Attribute’s

Scope), 4209.22 (Obtaining an Attribute from the

Desired Scope), 4219.23 (Modifying Attributes in script—

Script), 4229.24 (Modifying Attributes in script—

Java Application), 4229.25 (Defining a Custom

Namespace), 424

19_1936_index.qxd 7/11/07 12:14 AM Page 516

9.26 (Custom Application Context), 4249.27 (Using Custom Application

Context), 4269.28 (Custom Engine Writer

Example), 4279.29 (Output Statement), 4299.30 (Method Call Syntax), 4309.31 (Program Example), 4319.32 (Invocable Example), 4339.33 (Method Call), 4359.34 (Interfaces), 4369.35 (Compilable), 4389.36 (Threading), 4419.37 (Example php.ini

Configuration), 4429.38 (Dynamic Binding—Java

Objects), 4439.39 (Dynamic Binding—Java

Classes), 44310.1 (Sample Web Application

Descriptor), 45410.2 (Accessing Application

Context), 46310.3 (HTTP Request Handling—HTML

Form), 46510.4 (HTTP Request Handling—PHP

Script), 46610.5 (Including Resources), 47010.6 (Request Forwarding), 47110.7 {Session Handling—Login Form

(form.jsp)}, 47410.8 (Session Handling—Login

Servlet), 47510.9 (Session Handling—PHP

Script), 47710.10 (Language Tags—Original Groovy

Script), 47910.11 (Language Tags—Configuration),

48010.12 (Language Tags—Groovy

Script), 48110.13 (PHP to Java—PHP Class), 484

INDEX 517

10.14 (PHP to Java—Factory Class), 48510.15 (PHP to Java—Client Code), 48610.16 (PHP to Java—Java Class), 48610.17 (PHP to Java—Modified Factory

Class), 487lists, Groovy, 149-151Lists listing (4.11), 150LiveScript, 65Loading Groovy Scripts as Java Classes

listing (4.45), 187logical branching, Groovy, 154-156lookupBean( ) method, 266looping, Groovy, 156-158loops, for loop, BeanShell, 88-89loose methods, 134loose typing, Groovy, 138-140Loose Typing listing (4.5), 138loosely defined methods, 91loosely typed syntax, BeanShell, 87Loui, Ronald, 71LucasArts, 69

Mmachine instructions, 4-5machine language, 5main( ) method, 134, 295, 304Make tool, 51make( ) method, 222Makefiles, 52management, scripting, 55-58, 328-334manager initialization, BSF (Bean

Scripting Framework), 252manuals, BeanShell, 98maps, Groovy, 152-153Maps listing (4.13), 153Markup syntax, Groovy, 223-236McIlroy, Doug, 40Mediator Client listing (8.7), 350Mediator Implementation listing (8.6), 349Mediator Interface listing (8.2), 346mediator scripting pattern, 341

consequences, 345problem, 341-342

19_1936_index.qxd 7/11/07 12:14 AM Page 517

related patterns, 354sample code, 345-354solution, 342-345

Mediator-Aware Widget Abstraction listing (8.3), 346

metadata, engine metadata, Scripting API,393, 395

method arguments, functions as, 21, 23Method Call Example listing (6.6), 262Method Call listing (9.33), 435Method Call Syntax listing (9.30), 430method closure, 92method code syntax, Scripting API,

429-431method overloading, 139methods

addClassPath( ), 324any( ) method, 175-177append( ), 181apply( ), 263-264assertArrayEquals( ), 298assertContains( ), 299assertEquals( ), 294assertLength( ), 298assertScript( ), 299assertToString( ), 299BeanShell, 91-92BSF (Bean Scripting Framework),

259-264call( ), 169, 260changed( ), 347closures, curly braces, 172collect( ) method, 173compile( ), 275compileExpr( ), 272currentThread( ), 444declareBean( ), 268-269doSomeAction( ), 374each( ), 211each( ) method, 171-172eachByte( ), 180eachFile( ), 182

518 INDEX

eachFileRecurse( ), 182eachLine( ), 179eachRow( ), 202-203eval( ), 96, 400-404evaluate( ), 184every( ) method, 175exec( ), 270execute( ), 205-206executeUpdate( ), 204-205exportAsCSV( ), 377exportAsSQL( ), 377exportAsXML( ), 377fail( ), 294filter( ), 22find( ) method, 174findAll( ), 211-212findAll( ) method, 174-175forward( ) method, 471-473frame( ), 237get( ), 95getBindings( ), 412getComponent( ), 347getEngineByExtension( ), 398getEngineByMimeType( ), 398getEngineByName( ), 397getInterface( ), 97getLanguageName( ), 394getMethodCallSyntax( ), 429-431getOutputStatement( ), 429getScriptEngine( ), 395-396getter/setter methods, 165getText( ), 178include( ) method, 469-471Incovable interface, 434-437inject( ) method, 173-174invoice( ), 92invokeFunction( ), 434isCase( ), 155-156lookupBean( ), 266loosely defined methods, 91main( ), 134, 295, 304make( ), 222

19_1936_index.qxd 7/11/07 12:14 AM Page 518

method closure, 92method overloading, 139notifyObservers( ), 363panel( ), 237put( ), 406readBytes( ), 181readLines( ), 179registerBean( ), 266, 268registerEngineExtension( ), 399registerEngineMimeType( ), 399registerEngineName( ), 399run( ), 134script( ), 95select( ), 22sendError( ), 468set( ), 95setBindings( ), 407setChanged( ), 363setClassPath( ), 324setEmail( ), 308setPrice( ), 363setUp( ), 294shouldFail( ), 299show( ), 350showDialog( ), 346, 350sleep( ), 444source( ), 95-96splitEachLine( ), 180Sql.loadDriver( ), 199-200standalone methods, 134termination( ), 134testAnimal( ), 156testInit( ), 294testIteration( ), 294unregisterBean( ), 266update( ), 238, 364valueChanged( ), 348waitFor( ), 183widgetChanged( ), 346, 348, 350write( ), 181

modes, BeanShell, 84Modified Compile Example

listing (6.16), 273

INDEX 519

Modified Compile Example—Result listing (6.17), 274

Modified Extension Point Example listing (8.19), 372

Modified Mediator Component listing (8.9), 353

Modifying Attributes in script—JavaApplication listing (9.24), 422

Modifying Attributes in script—Script listing (9.23), 422

mod_perl, 62Mythical Man-Month: Essays on Software

Engineering, The, 48

Nnamed parameters, GroovyBeans, 166-167Namespace Example listing (5.29), 234Namespace Example listing (9.19), 416NamespaceBuilder, Groovy, 234Namespaces, 234

custom namespaces, 423-427script context, 416-419

native types, programming languages, 14navigation

objects, GroovyBeans, 167save navigation, GroovyBeans, 168

Netscape Navigator, Javagator project, 110NodeBuilder, Groovy, 227-229NodeBuilder Example listing (5.24), 227notifyObservers( ) method, 363

OO’Reilly, Tim, 61object-oriented programming (OOP)

languages, 40object-oriented technology (OOT), 40Object-Relational Mapping (ORM)

tools, 196objects

BeanShell, 92creating, GroovySQL, 199-207GroovyBeans, navigation, 167GString objects, Groovy, 145-146

19_1936_index.qxd 7/11/07 12:14 AM Page 519

ObjectScript, 123Observer Client listing (8.16), 365Observer Label Widget listing (8.13), 364observer pattern, 359

consequences, 362problem, 359-360related patterns, 369sample code, 362-369solution, 360-362

Obtaining an Attribute from the DesiredScope listing (9.22), 421

OOP (object-oriented programming) language, 40

OOT (object-oriented technology), 40operators, overloading, Groovy, 162-164operands, 4operartion code, 4Operator Overloading listing (4.20), 164Operators listing (4.19), 163ORM (Object-Relational Mapping)

tools, 196Ousterhout, John K., 37out variable (Groovlet), 214Output Statement listing (9.29), 429output statements, Scripting API, 429over( ) function, 21overloading operators, Groovy, 162-164overloading methods, 139overriding

engine scope, 407-409variables, global scope, 413-414

Overriding the Engine Scope listing (9.12), 407

Ppanel( ) method, 237parameters, named parameters,

GroovyBeans, 166-167Parsing Documents with DomBuilder

listing (5.27), 232patterns, scripting, 335-337

active file pattern, 375-380extension point pattern, 369-374

520 INDEX

mediator pattern, 341-354observer pattern, 359-369script object factory pattern, 354-359scripted components pattern, 337-341

Perl programming language, 43web applications, 61-62

Pettichord, Bret, 55PHP, 386

classes, 484client code, 486factory class, 486-487web applications, 62-64

PHP to Java—Client Code listing (10.15), 486

PHP to Java—Factory Class listing (10.14), 485

PHP to Java—Java Class listing (10.16), 486

PHP to Java—Modified Factory Class listing (10.17), 487

PHP to Java—PHP Class listing (10.13), 484

polymorphism, 139Groovy, 139-140

Portraits of Open Source Pioneers, 68Pragmatic Unit Testing in Java with

JUnit, 53prepared statements, GroovySQL, 206-207Price Observer Label Widget

listing (8.14), 364primitive types, programming

languages, 14print( ) command (BeanShell), 91printColor( ) function, 140problems

active file pattern, 375extension point pattern, 369mediator scripting pattern, 341-342observer pattern, 359-360script object factory pattern, 355scripted components pattern, 337-338

procedures, stored procedures, GroovySQL,207-208

19_1936_index.qxd 7/11/07 12:14 AM Page 520

Process Handling listing (4.42), 183processes, system operations, Groovy,

182-183processors

machine instructions, execution of, 4machine language, 5

production environment, source code, 12-13

Program Example listing (9.31), 431programmatic binding, 442programming. See also scripting

extreme programming, 33-35Java

administration, 328-334Ant scripting, 309-322interactive debugging, 304-309management, 328-334shell scripting, 323-328unit testing, 292-304

UNIX, 40user interface programming, 58-59

programming languages. See also scriptinglanguagesassembly languages, 5BeanShell, 83-98, 126compilers, 6Groovy, 80, 120-121, 125, 194-195

advantages of, 126configuring, 492downloading, 491Groovlets, 212-219GroovySQL, 196-212IDE support, 495-497installing, 127, 491-492Markup syntax, 223-236Swing user interfaces, 236-243templates, 220-223testing, 492-493

high-level languages, 6Java, 80JRuby, 122JudoScript, 122

INDEX 521

JVM (Java Virtual Machine), using in,82-83

Jython, 98-109, 126ObjectScript, 123OOP (object-oriented programming)

languages, 40Python, 98-109, 126Rhino, 110-114, 116-120second-generation programming

languages, 5Tcl/Java, 122third-generation programming

languages, 6typing, 13, 15

composite types, 14dynamic typing, 15-16native types, 14user-defined types, 14weak typing, 17

programscomputer programs, 5Scripting API, 431-432

project building, scripting languages, 51-53

properties, GroovyBeans, 165-166prototyping models, 44-48

evolutionary prototyping, 46Python, 47-48throwaway prototyping, 45-46

put( ) method, 406Python scripting language, 18, 47-48,

98-109, 126Java, embedding with, 108-109scripting

basic syntax, 101-103exception handling, 107-108in Java, 103-105interface implementation, 105-107

Q-RQuartz scheduler, 330-334Quartz Scheduler Configuration Example

listing (7.19), 332

19_1936_index.qxd 7/11/07 12:14 AM Page 521

queries, database queries, GroovySQL,202-205

ranges, Groovy, 151-152Ranges listing (4.12), 151readBytes( ) method, Groovy, 181readBytes( ) Method listing (4.37), 181readers, 427-428readLines( ) method, Groovy, 179readLines( ) Method listing (4.34), 179refactoring, 33Register Bean Example—Java Application

listing (6.9), 267Register Bean Example—JavaBean

Definition listing (6.8), 266Register Bean Example—Script

listing (6.10), 267Register Engine Example listing (9.6), 399registerBean( ) method, 266, 268registerEngineExtension( ) method, 399registerEngineMimeType( ) method, 399registerEngineName( ) method, 399registering

beans, BSF (Bean Scripting Framework),265-268

scripting engines, Scripting API, 399scripting languages, BSF (Bean

Scripting Framework), 249-252regular expressions (regex), Groovy,

146-148Regular Expressions listing (4.10), 147request forwarding, Web Scripting

Framework, 471-473Request Forwarding listing (10.6), 471request handling, Web Scripting

Framework, 464-467request scope, Web environments, 448request variable (Groovlet), 214Reserved Keys listing (9.14), 411resource handling, closures, Groovy,

176-177Resource Handling with Closures

listing (4.31), 176

522 INDEX

responses, Web Scripting Framework, 468results, Web Scripting Framework,

displaying, 460-462reversed keys, 410-411Rhino, 80, 110-120

downloading, 110Java, embedding with, 114-120scripting

in Java, 111-112interface implementation, 112-114JavaAdapter class, 114

RI (Reference Implementation)JSR 223 RI, installing, 499-502

robustness, scripting languages, 29-32run( ) method, 134running

BeanShell, 84scripts, Groovy, 127-130

runtime performance, code, 26-28

Ssafe navigation, GroovyBeans, 168Safe Navigation listing (4.22), 168Sample Web Application Descriptor

listing (10.1), 454SAX Handler Example listing (5.25), 230SaxBuilder, Groovy, 230-231SaxBuilder listing (5.26), 231script context

attributes, 419-423binding, Scripting API, 416-428namespaces, 416-419

script directory, Web Scripting Framework,457-458

script filesBSF (Bean Scripting Framework),

executing, 257-259Groovy, evaluating, 129-130

Script Job Example listing (7.18), 330script methods, Web Scripting

Framework, 458

19_1936_index.qxd 7/11/07 12:14 AM Page 522

script object factory pattern, 354consequences, 356problem, 355related patterns, 359sample code, 356-359solution, 355

script( ) method, 95Scripted Component Pattern Example

listing (8.1), 340scripted components pattern, 337

consequences, 339problem, 337-338related patterns, 341sample code, 340-341solution, 338-339

Scripted Object Factory Pattern Examplelisting (8.11), 357

ScriptEngineManager class, shortcut methods, 414-415

ScriptEngineManager’s Shortcut Methodslisting (9.17), 414

ScriptException, handling, 403-404scripting. See also programming

administration, 328-334BeanShell, 83-98

autoboxing, 89-90basic syntax, 86-87commands, 91embedding, 94-98for loop, 88-89interface implementation, 93-94JavaBeans, 88loosely typed syntax, 87methods, 91-92objects, 92switch-case statement, 90Workspace Editor, 85

design patterns, 335-337active file pattern, 375-380extension point pattern, 369-374mediator pattern, 341-354observer pattern, 359-369

INDEX 523

script object factory pattern, 354-359

scripted components pattern, 337-341

Jython, 98-109management, 328-334Python, 98-109

basic syntax, 101-103embedding, 108-109exception handling, 107-108in Java, 103-105interface implementation, 105-107

Rhino, 110-120embedding, 114-120in Java, 111-112interface implementation, 112-114JavaAdapter class, 114

shell scripting, 323-328system programming, 26-35

hybrids, 35-36Web Scripting Framework, disabling,

456-457Scripting API, 94, 385, 388-391

architecture, 391binding, 404-411

dynamic binding, 442-444engine scope, 405-411global scope, 411-416script context, 416-428

BSF, compared, 445code generation, 428

method call syntax, 429-431output statement, 429programs, 431-432

discovery mechanism, 391-393engine interfaces, 432

Compilable interface, 437-440Incovable interface, 432-437

engine metadata, 393, 395General Scripting API, 389origins of, 386-388script, evaluating, 400-404

19_1936_index.qxd 7/11/07 12:14 AM Page 523

scripting enginescreating, 395-398registering, 399

threading, 440-442Web Scripting API, 389Web Scripting Framework, 447,

453-456architecture, 448-453, 482-488bindings, 462-469configuring, 456-462forward( ) method, 471-473include( ) method, 469-471language tags, 478-481session handling, 473-478threading, 481-482

scripting enginescreating, Scripting API, 395-398registering, Scripting API, 399

scripting environments, BSF (Bean Scripting Framework), 245-246applications, 275-285, 287architecture, 248-249bean declaration, 268-270bean registration, 265-268compilation, 270-275data binding, 264-270downloading, 247engine initialization, 252exception handling, 255functions, 259-264manager initialization, 252methods, 259-264origins of, 247script files, 257-259scripting language registration, 249-252scripts, 253-257

scripting languages, 4-24. See alsoprogramming languagesadministration, 55-58BeanShell, 83-98, 126closures, 20code as data, 19-23

524 INDEX

compilers, 8-12customization, 49-51data structures, 17-19embedding, 70extensiblity, 70-71functions, as method arguments, 21-23Groovy, 120-121, 125, 194-195

advantages of, 126configuring, 492downloading, 491Groovlets, 212-219GroovySQL, 196-212IDE support, 495-497installing, 127, 491-492Markup syntax, 223-236Swing user interfaces, 236-243templates, 220-223testing, 492-493

interpreters, 8-12Java

API (application programminginterface), 80-82

architecture, 80-82class files, 80JVM (Java Virtual Machine), 80-82programming language, 80

JRuby, 122JudoScript, 122JVM (Java Virtual Machine), using in,

82-83Jython, 98-109, 126learnability, 71-72management, 55-58ObjectScript, 123Perl, 43prototyping models, 44-48

evolutionary prototyping, 46Pyhton, 47-48throwaway prototyping, 45-46

Pyhton, 126Python, 18, 98-109registering, BSF (Bean Scripting

Framework), 249-252

19_1936_index.qxd 7/11/07 12:14 AM Page 524

Rhino, 110-114, 116-120software development support, 51-55

project building, 51-53testing, 53, 55

source code, production environment,12-13

Tcl (Tool Command Language), 37-38,43-44

Tcl/Java, 122typing, 13, 15

composite types, 14dynamic typing, 15-16native types, 14user-defined types, 14weak typing, 17

UNIX shell languages, 41user interface programming, 58-59virtual machines, 24-25web applications, 59, 61-67

ASP (Activer Server Pages), 64games, 68-69JavaScript, 65-67Perl, 61-62PHP, 62-64UNIX, 68

wiring, 40-44UNIX shell languages, 42

scriptsevaluating, Scripting API, 400-404Groovy

command-line arguments, 136compiling, 130-133dependencies, 131running, 127-130structure, 133-136

unit testing, 303-304working with, BSF (Bean Scripting

Framework), 253-257SCUMM (Script Creation Utility for Maniac

Mansion), 69second-generation programming

languages, 5

INDEX 525

security, Groovy, 190-194Security Example listing (4.47), 191Security Policy listing (4.48), 191select( ) method, 22sendError( ) method, 468servers, web servers, Apache Web

server, 62servlets, Web Scripting Framework

architecture, 449-451session handling, Web Scripting

Framework, 473-478Session Handling—Login Form (form.jsp)

listing (10.7), 474Session Handling—Login Servlet

listing (10.8), 475Session Handling—PHP Script

listing (10.9), 477session scope, Web environments, 448session variable (Groovlet), 215set( ) method, 95setBindings( ) method, 407setChanged( ) method, 363setClassPath( ) method, 324setEmail( ) method, 308setPrice( ) method, 363setting classpaths, Groovy, 131-132setUp( ) method, 294shell languages, UNIX, 41-42shell scripting, 323-328Shell Scripting Example listing (7.16), 327shortcut methods, ScriptEngineManager

class, 414-415shouldFail( ) method, 299show( ) method, 350showDialog( ) method, 346, 350Simple XSLT Transformation

listing (6.21), 281single inheritance model, Java, 78sleep( ) method, 444Smith, Ben, 61

19_1936_index.qxd 7/11/07 12:14 AM Page 525

software development support, scriptinglanguages, 51-55project building, 51-53testing, 53-55

solutionsactive file pattern, 375extension point pattern, 370mediator scripting pattern, 342-345observer pattern, 360-362script object factory pattern, 355scripted components pattern, 338-339

someFunc( ) function, 103source code, production environment,

12-13source( ) method, 95-96splitEachLine( ) method, Groovy, 180splitEachLine( ) Method listing (4.35), 180SQL Object Creation Alternatives

listing (5.2), 199Sql.loadDriver( ) method, GroovySQL,

199-200Sql.loadDriver( ) Method listing (5.3), 199standalone methods, 91, 134statements

Groovy, 138prepared statements, GroovySQL,

206-207switch-case statement, BeanShell, 90

Stored Procedure Call listing (5.12), 208Stored Procedure listing (5.11), 207stored procedures, GroovySQL, 207-208strings, Groovy, 143-145

GStrings, 145-146strongly typed languages, 17structure, scripts, Groovy, 133, 135-136Subject Component listing (8.12), 363Swing user interfaces

TableLayout component, 239-240TableModel component, 241-243

SwingBuilder, Groovy, 236-243SwingBuilder listing (5.31), 237switch-case statement, BeanShell, 90

526 INDEX

switch-case structure, Groovy, 154-156switch-case Structure listing (4.14), 154switches, jythonc, 101syntax

BeanShellautoboxing, 89-90basic syntax, 86-87for loop, 88-89JavaBeans, 88loosely typed syntax, 87switch-case statement, 90

Groovy, 137-177Python, basic syntax, 101-103

system operations, Groovy, 178files, 178-182processes, 182-183

system programming, scriptingcompared, 26-35hybrids, 35-36

TTableLayout component (Swing), 239-240TableLayout listing (5.32), 239TableModel component (Swing), 241-243TableModel listing (5.33), 241Tag Library Descriptor (TLD) file, 278tags, language tags, Web Scripting

Framework, 478-481Tax Observer Label Widget listing (8.15),

365Tcl (Tool Command Language), 37-38,

43-44Tk extension, 58-59

Tcl Blend, 122Tcl/Java, 122TDD (test-driven development), 33Template Example listing (5.20), 222templates, Groovy templates, 220-223termination( ) method, 134test suites, unit testing, 300-303test-driven development (TDD), 33testAnimal( ) method, 156

19_1936_index.qxd 7/11/07 12:14 AM Page 526

testingGroovy, 492-493scripting languages, 53-55

testInit( ) method, 294testIteration( ) method, 294TestSuite Example listing (7.9), 300Thinking in Java, 30third-generation programming

languages, 6Thomas, Dave, 53threading

Java, 77Scripting API, 440-442Web Scripting Framework, 481-482

Threading listing (9.36), 441throwaway prototyping, 45-46Tk extension (Tcl), 58-59TLD (Tag Library Descriptor) file, 278Tool Command Language (Tcl). See Tcl

(Tool Command Language)transactions, GroovySQL, 208-209Transactions listing (5.13), 208triple-quote syntax, Groovy, 144-145Triple-Quote Syntax listing (4.8), 144type juggling, Groovy, 140-143type theory, 13types, classes, 14typing

dynamic typing, Groovy, 139-140loose typing, Groovy, 138-140programming languages, 13, 15

composite types, 14dynamic typing, 15-16native types, 14user-defined types, 14weak typing, 17, 138

Uunified resource locators (URLs), 60unit testing, 292-293

assertion methods, 297-300GroovyTestCase class, 296-297JUnit, 293-295

INDEX 527

scripts, 303-304test suites, 300-303

UNIXprogramming, 40scripting, 68shell languages, 41-42

unregisterBean( ) method, 266update( ) method, 238, 364updateObservers( ) method, 364upper( ) function, 102URLs (unified resource locators), 60user interface programming, 58-59user manuals, BeanShell, 98user-defined class loaders (JVM), 82user-defined types, programming

languages, 14Using Custom Application Context

listing (9.27), 426

VvalueChanged( ) method, 348van Rossum, Guido, 32, 48variables

global scope, overriding, 413-414Groovlets, 214

Variables Overriding—An Example listing (9.16), 413

VBA (Visual Basic for Applications), 50-51Venners, Bill, 36virtual machines, 7

scripting languages, 24-25Visual Basic for Applications (VBA), 50-51

WwaitFor( ) method, 183weak typing, 17, 138weakly typed languages, 17web applications, 59, 61-67

ASP (Activer Server Pages), 64games, 68-69JavaScript, 65-67Perl, 61-62

19_1936_index.qxd 7/11/07 12:14 AM Page 527

PHP, 62-64UNIX, 68

Web Scripting API, 389Web Scripting Framework, 447, 453-456

architecture, 448, 482-488context, 448-449interaction, 451-453servlet, 449-451

bindings, 462application, 462-464request handling, 464-467response, 468servlet, 468-469

configuring, 456-462forward( ) method, 471-473include( ) method, 469-471language tags, 478-481languages, allowing, 459results, displaying, 460-462script directory, 457-458script methods, 458scripting, disabling, 456-457session handling, 473-478threading, 481-482

web servers, Apache Web servers, 62widgetChanged( ) method, 346, 348, 350

528 INDEX

wiring scripting languages, 40-44Perl, 43Tcl (Tool Command Language), 43-44UNIX shell languages, 41-42

Workspace Editor, BeanShell, 85write( ) method, Groovy, 181write( ) Method listing (4.38), 181writers, engine writers, 427-428WWW (World Wide Web), 59

HTML (Hypertext Markup Language), 60HTTP (HyperText Transfer Protocol), 60hypertext, 60URLs (unified resource locators), 60

X–ZXalan-J (XSLT), BSF (Bean Scripting

Framework), 280-287Xalan-J BSF Example listing (6.24), 285Xalan-J Extension Example

listing (6.23), 283XHTML Markup Example

listing (5.23), 226XPath (XML Path Language), 280XSLT (Extensible Stylesheet Language

Transformation), 280

19_1936_index.qxd 7/11/07 12:14 AM Page 528