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

INDEX

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

504 INDEX

apply( ) method, 263-264 BeanShell, 80, 83-98, 126 architecture commands, 91 BSF (Bean Scripting Framework), downloading, 83 248-249 GUI (graphical user interface), 84 compilers, 9 Java, embedding with, 94-98 hybrid compiler-interpreters, 11 manual, 98 interpreters, 10 methods, 91-92 Java, 80-82 modes, 84 Scripting API, 391 objects, 92 Web Scripting Framework, 448, running, 84 482-488 scripting context, 448-449 autoboxing, 89-90 interaction, 451-453 basic syntax, 86-87 servlet, 449-451 for loop, 88-89 arguments, command-line arguments, interface implementation, 93-94 Groovy, 136 JavaBeans, 88 Ascher, David, 29 loosely typed syntax, 87 ASP (Active Server Pages), 64 switch-case statement, 90 assembly languages, 5 Workspace Editor, 85 assertArrayEquals( ) method, 298 “Best Tool for the Job, The”, 36 assertContains( ) method, 299 Bezroukov, Nikolai, 68 assertEquals( ) method, 294 binding, 186 assertion methods, unit testing, 297-300 dynamic binding, 442 assertLength( ) method, 298 programmatic binding, 442 assertScript( ) method, 299 Scripting API, 404-411 assertToString( ) method, 299 dynamic binding, 442-444 attributes, script context, 419-423 engine scope, 405-411 autoboxing global scope, 411-416 BeanShell, 89-90 script context, 416-428 Groovy, 140 Binding Example listing (9.11), 406 Autoboxing listing (4.7), 140 Binding listing (4.44), 186 AutoCAD, 50 bindings, Web Scripting Framework, 462 application, 462-464 B request handling, 464-467 basic syntax response, 468 BeanShell, 86-87 servlet, 468-469 Python, 101-103 bootstrap class loaders (JVM), 81 Bean Scripting Framework (BSF). See BSF Broadcasters Example listing (8.17), 367 (Bean Scripting Framework) broadcasters pattern, 359 beans, BSF (Bean Scripting Framework) consequences, 362 declaring, 268-270 problem, 359-360 registering, 265-268 related patterns, 369 19_1936_index.qxd 7/11/07 12:14 AM Page 505

INDEX 505

sample code, 362-369 changed( ) method, 347 solution, 360-362 class files, Java, 80 BSF (Bean Scripting Framework), 94, class loaders (JVM), 81 245-246 bootstrap class loaders, 81 Ant scripting, 313-316 user-defined class loaders, 82 applications, 275 classes, 14 JSP (JavaServer Pages), 275-280 Groovy, 159-161 Xalan-J (XSLT), 280-287 JavaAdapter class, 114 architecture, 248-249 Classes listing (4.17), 159 beans classpaths, Groovy, setting, 131-132 declaring, 268-270 closures registering, 265-268 Groovy, 168-177 compilation, 270-275 curly braces, 172 data binding, 264-270 resource handling, 176-177 downloading, 247 method closure, 92 engine initialization, 252 methods, curly braces, 172 exception handling, 255 , 20 functions, 259-264 Closures listing (4.23), 170 manager initialization, 252 code. See also listings; scripts methods, 259-264 active file pattern, 376-380 origins of, 247 as data, 19-23 script files, executing, 257-259 bytecode, 7 Scripting API, compared, 445 development speed, 28-29 scripting language registration, 249-252 extension point pattern, 371-374 scripts, 253-257 mediator scripting pattern, 345-354 BSF Exception Handling listing (6.2), 256 observer pattern, 362-369 BSF JSP Example listing (6.20), 279 operation code, 4 BSFEngine.apply( ) Method Example runtime performance, 26-28 listing (6.7), 263 script object factory pattern, 356-359 BSFEngine.eval( ) Method Example scripted components pattern, 340-341 listing (6.1), 254 source code, production environment, BSFEngine.exec( ) Method Example 12-13 listing (6.3), 256 code generation, Scripting API, 428 BuilderSupport, Groovy, 235-236 method call syntax, 429-431 building tools, Ant scripting, 309-322 output statement, 429 built-in functions, 19 programs, 431-432 bytecode, 7 collect( ) method, Groovy, 173 collect( ) Method listing (4.25), 173 C collections, Groovy, 148 C++, Java, compared, 78 lists, 149-151 call( ) method, 169, 260 maps, 152-153 Cascading Style Sheets (CSS), 66 ranges, 151-152 CBD (component-based development), 40 19_1936_index.qxd 7/11/07 12:14 AM Page 506

506 INDEX

command-line arguments, Groovy, 136 context, Web Scripting Framework commands, 19 architecture, 448-449 BeanShell, 91 Creating an Sql Object with DataSource compatibility, Java and Groovy, 137 listing (5.6), 202 Compilable interface, 437-440 Creating Documents with DomBuilder Compilable listing (9.35), 438 listing (5.28), 233 compilation, BSF (Bean Scripting cross-platform portability, Java, 77 Framework), 270-275 CSS (Cascading Style Sheets), 66 compilation languages, 52 curly braces, closures, methods, 172 Compile Example listing (6.13), 271 currentThread( ) method, 444 Compile Example—Result listing (6.14), 271 Custom Application Context compile( ) method, 275 listing (9.26), 424 Compiled Script Usage Example Custom BuilderSupport Implementation listing (6.18), 274 (BuilderSupport.java) listing (5.30), 235 compileExpr( ) method, 272 Custom Engine Writer Example compilers, 6 listing (9.28), 427 architecture, 9 custom namespaces, 423-427 hybrid compiler-interpreters, 11 Customized compileExpr( ) Method interpreters, compared, 8-12 listing (6.15), 272 compiling scripts, Groovy, 130-133 Cygwin, 323 Compiling Groovy Scripts with Ant listing (4.2), 132 D component-based development (CBD), 40 DAO (Database Access Object) design components pattern (scripting), 337 paradigm, 196 consequences, 339 data binding, BSF (Bean Scripting problem, 337-338 Framework), 264-270 related patterns, 341 data structures, scripting languages, 17-19 sample code, 340-341 Database Access Object (DAO) design solution, 338-339 paradigm, 196 composite types, programming database queries, GroovySQL, 202-205 languages, 14 databases, transactions, GroovySQL, computer programs, 5 208-209 configuration datasets, GroovySQL, 209-212 Groovy, 492 Davidson, James Duncan, 52, 311 Web Scripting Framework, 456-462 debugging, interactive debugging, consequences 304-309 active file pattern, 375 Declare Bean Example—Java Application extension point pattern, 370 listing (6.11), 269 mediator scripting pattern, 345 Declare Bean Example—Script observer pattern, 362 listing (6.12), 270 script object factory pattern, 356 declareBean( ) method, 268-269 scripted components pattern, 339 declaring beans, BSF (Bean Scripting Framework), 268-270 19_1936_index.qxd 7/11/07 12:14 AM Page 507

INDEX 507

Defining a Custom Namespace dynamic linking, Java, 78 listing (9.25), 424 dynamic typing, 15-16 dependencies, Groovy, 131 Groovy, 139-140 design patterns, scripting, 335-337 Dynamic Typing and Polymorphism active file pattern, 375-380 listing (4.6), 139 extension point pattern, 369-374 mediator pattern, 341-354 E observer pattern, 359-369 each( ) method, GroovySQL, 171-172, 211 script object factory pattern, 354-359 each( ) Method listing (4.24), 172 scripted components pattern, 337-341 each( ) Method listing (5.15), 211 Design Patterns, 336 eachByte( ) method, Groovy, 180-181 Determining the Attribute’s Scope eachByte( ) Method listing (4.36), 181 listing (9.21), 420 eachFile( ) method, Groovy, 182 development, CBD (component-based eachFile( ) Method listing (4.40), 182 development), 40 eachFileRecurse( ) method, Groovy, 182 development speed, code, 28-29 eachFileRecurse( ) Method DHTML (Dynamic Hypertext Markup listing (4.41), 182 Language), 66 eachLine( ) method, Groovy, 179 Dickerson, Chad, 56 eachLine( ) Method listing (4.33), 179 disabling scripting, Web Scripting eachRow( ) method, GroovySQL, 202-203 Framework, 456-457 eachRow( ) Method and GString Query discovery mechanism, Scripting API, Parameters listing (5.7), 202 391-393 eachRow( ) Method and List Query Discovery Mechanism listing (9.1), 393 Parameters listing (5.8), 203 DomBuilder, Groovy, 232-233 Eckel, Bruce, 30 doSomeAction( ) method, 374 Eclipse IDE, 130 downloading embedding BeanShell, 83 BeanShell with Java, 94-98 BSF (Bean Scripting Framework), 247 Groovy, 184-190 Groovy, 491 Pyhton with Java, 108-109 , 98 Rhino with Java, 114-120 Rhino, 110 scripting languages, 70 dynamic binding, 442, Scripting API, engine initialization, BSF (Bean Scripting 442-444 Framework), 252 Dynamic Binding—Java Classes engine interfaces, Scripting API, 432 listing (9.39), 443 Compilable interface, 437-440 Dynamic Binding—Java Objects Incovable interface, 432-437 listing (9.38), 443 engine metadata, Scripting API, 393-395 Dynamic Hypertext Markup Language Engine Metadata listing (9.2), 394 (DHTML), 66 engine readers, 427-428 dynamic languages, 6 engine scope “Dynamic Languages—Ready for the Next binding, Scripting API, 405-411 Challenges, by Design,” 29 overriding, 407-409 19_1936_index.qxd 7/11/07 12:14 AM Page 508

508 INDEX

engine writers, 427-428 extensibility, scripting language, 70-71 eval( ) method, 19, 96, 400-404 Extensible Stylesheet Language evaluate( ) method, 184 Transformation (XSLT), 280 evaluating scripts, Scripting API, 400-404 Extension Point Example Evaluating a Script in the Script Context listing (8.18), 371 listing (9.20), 418 extension point pattern, 369 Evaluating Groovy Scripts from Java consequences, 370 listing (4.43), 184 problem, 369 Evaluating Inline Scripts Under Security related patterns, 374 Policy listing (4.49), 193 sample code, 371-374 Evaluating Script Contained in a File solution, 370 listing (9.8), 401 extreme programming, 33-35 Evaluating Script Contained in a String listing (9.7), 400 F every( ) method, Groovy, 175 fail( ) method, 294 every( ) Method listing (4.29), 175 files, system operations, Groovy, 178-182 evolutionary prototyping, 46 filter( ) function, 21 Example php.ini Configuration filter( ) method, 22 listing (9.37), 442 filters, 41 exception handling find( ) method, Groovy, 174 BSF (Bean Scripting Framework), 255 find( ) Method listing (4.27), 174 Python, 107-108 findAll( ) method, Groovy, 174-175 exec( ) method, 270 findAll( ) method, GroovySQL, 211-212 execute( ) method, GroovySQL, 205-206 findAll( ) Method listing (4.28), 174 execute( ) Method listing (5.10), 205 findAll( ) Method listing (5.16), 212 executeUpdate( ) method, GroovySQL, Foemmel, Matthew, 292 204-205 Font dialog box, 351 executeUpdate( ) Method and CSV Files for loop listing (5.9), 204 BeanShell, 88-89 executing script files, BSF (Bean Scripting Groovy, 157 Framework), 257, 259 for Loop listing (4.16), 157 Executing a Script File listing (6.4), 258 forward( ) method, Web Scripting execution engine (JVM), 81-82 Framework, 471-473 explicit memory management, 78 Fowler, Martin, 292 exportAsCSV( ) method, 377 frame( ) method, 237 exportAsSQL( ) method, 377 Function Call Example listing (6.5), 260 exportAsXML( ) method, 377 functions expressions, regular expressions, Groovy, as method arguments, 21-23 146-148 BSF (Bean Scripting Framework), Extended XSLT Example listing (6.22), 282 259-264 Extending the switch-case Mechanism built-in functions, 19 listing (4.15), 156 eval( ), 19 filter( ), 21 19_1936_index.qxd 7/11/07 12:14 AM Page 509

INDEX 509

Incovable interface, 433-434 related patterns, 354 over( ), 21 sample code, 345-354 printColor( ), 140 solution, 342-345 someFunc( ), 103 glue languages, 41 upper( ), 102 graphical user interfaces (GUIs). See GUIs (graphical user interfaces) G Groovlet Deployment Descriptor games, scripting in, 68-69 listing (5.17), 214 garbage collector (JVM), 78 Groovlet Example listing (5.18), 218 General Scripting API, 389 Groovlets, 212-219 generating code, Scripting API, 428-432 variables, 214 generics, Java, 31 Groovy , 80, get( ) method, 95 120-121, 125, 194-195 getBindings( ) method, 412 advantages of, 126 getComponent( ) method, 347 Ant task, 132-133 getEngineByExtension( ) method, 398 any( ) method, 175-177 getEngineByExtension( ) Method Example autoboxing, 140 listing (9.5), 398 BuilderSupport, 235-236 getEngineByMimeType( ) method, 398 classes, 159-161 getEngineByName( ) method, 397 classpaths, setting, 131-132 getEngineByName( ) Method Example closures, 168-177 listing (9.4), 397 curly braces, 172 getInterface( ) method, 97 resource handling, 176-177 getLanguageName( ) method, 394 collect( ) method, 173 getMethodCallSyntax( ) method, 429-431 collections, 148 getOutputStatement( ) method, 429 lists, 149-151 getScriptEngine( ) method, 395-396 maps, 152-153 getScriptEngine( ) Method Example ranges, 151-152 listing (9.3), 395 configuring, 492 getter/setter methods, 165 DomBuilder, 232-233 getText( ) Method listing (4.32), 178 downloading, 491 getText( ) method, Groovy, 178 dynamic typing, 139-140 global scope each( ) method, 171-172 binding, Scripting API, 411-416 every( ) method, 175 initialization, 415-416 find( ) method, 174 variables, overriding, 413-414 findAll( ) method, 174-175 Global Scope Example listing (9.15), 412 Groovlets, 212-219 Global Scope Initialization variables, 214 listing (9.18), 415 GroovyBeans, 165 Glue Code Client listing (8.8), 352 named parameters, 166-167 glue code pattern, 341 object navigation, 167 consequences, 345 properties, 165-166 problem, 341-342 safe navigation, 168 19_1936_index.qxd 7/11/07 12:14 AM Page 510

510 INDEX

GroovySQL, 196-212 security, 190-194 database queries, 202-205 strings, 143-145 datasets, 209-212 GStrings, 145-146 each( ) method, 211 Swing user interfaces, 236-243 eachRow( ) method, 202-203 switch-case structure, 154-156 execute( ) method, 205-206 system operations, 178 executeUpdate( ) method, 204-205 files, 178-182 findAll( ) method, 211-212 processes, 182-183 object creation, 199-207 templates, 220-223 prepared statements, 206-207 testing, 492-493 Sql.loadDriver( ) method, 199-200 type juggling, 140-143 stored procedures, 207-208 Groovy Script Structure listing (4.3), 134 transactions, 208-209 Groovy Shell listing (4.1), 128 IDE support, 495-497 Groovy Template Support inject( ) method, 173-174 listing (5.19), 221 installing, 127, 491-492 GroovyBeans, 165 interactive console, 128-129 named parameters, 166-167 interactive shell, 127-128 object navigation, 167 JAR (Java Archive) files, 491 properties, 165-166 Java safe navigation, 168 compatibility with, 137 GroovyBeans listing (4.21), 165 embedding with, 184-190 GroovySQL, 196-212 statements, 138 datasets, 209-212 language syntax, 137-177 each( ) method, 211 triple-quote syntax, 144-145 eachRow( ) method, 202-203 logical branching, 154-156 execute( ) method, 205-206 looping, 156-158 executeUpdate( ) method, 204-205 loose typing, 138-140 findAll( ) method, 211-212 Markup syntax, 223-236 objects, creation, 199-207 NamespaceBuilder, 234 prepared statements, 206-207 NodeBuilder, 227-229 queries, database queries, 202-205 operator overloading, 162-164 Sql.loadDriver( ) method, 199-200 polymorphism, 139-140 stored procedures, 207-208 regular expressions, 146-148 transactions, 208-209 SaxBuilder, 230-231 GroovySQL Example listing (5.1), 197 script files, evaluating, 129-130 GroovyTestCase class, unit testing, scripts 296-300 command-line arguments, 136 GroovyTestCase Example listing (7.2), 296 compiling, 130-133 GroovyTestCase.assertArrayEquals( ) dependencies, 131 Method Example listing (7.4), 298 running, 127-130 GroovyTestCase.assertContains( ) Method structure, 133, 135-136 Example listing (7.5), 299 19_1936_index.qxd 7/11/07 12:14 AM Page 511

INDEX 511

GroovyTestCase.assertLength( ) Method I Example listing (7.3), 298 IDEs, 130 GroovyTestCase.assertScript( ) Method Groovy, support for, 495-497 Example listing (7.7), 299 Implementing Java Interfaces in Groovy GroovyTestCase.assertToString( ) Method listing (4.46), 189 Example listing (7.6), 299 implicit memory management, 78 GroovyTestCase.shouldFail( ) Method include( ) method, Web Scripting Example listing (7.8), 300 Framework, 469-471 GroovyTestSuite Example Including Resources listing (10.5), 470 listing (7.10), 301 Incovable interface, 432 GStrings, Groovy, 145-146 functions, 433-434 GStrings listing (4.9), 145 interfaces, 435-437 GUIs (graphical user interfaces), 58 methods, 434-437 BeanShell, 84 initialization engines, BSF (Bean Scripting H Framework), 252 handling global scope, 415-416 command-line arguments, Groovy, 136 managers, BSF (Bean Scripting script evaluation results, 402 Framework), 252 ScriptException, 403-404 Sql object with connection, 200-201 sessions, Web Scripting Framework, Initializing the Sql Object with a Connec- 473-478 tion—Groovy Script listing (5.5), 201 Handling Command-Line Arguments in Initializing the Sql Object with a Connec- Groovy listing (4.4), 136 tion—Java Class listing (5.4), 200 Handling Script Evaluation Result inject( ) method, Groovy, 173-174 listing (9.9), 402 inject( ) Method listing (4.26), 173 Handling ScriptException installation listing (9.10), 403 Groovy, 127, 491-492 high-level languages, 6 JSR 223 RI (Reference Implementation), HTML (Hypertext Markup Language), 60 499-502 CSS (Cascading Style Sheets), 66 Jython, 99 DHTML (Dynamic Hypertext Markup interaction, Web Scripting Framework Language), 66 architecture, 451-453 HTTP (HyperText Transfer Protocol), 60 interactive console (Groovy), scripts, HTTP request handling, Web Scripting running, 128-129 Framework, 464-467 interactive debugging, 304-309 HTTP Request Handling—HTML Form Interactive Debugging with the Groovy listing (10.3), 465 Shell listing (7.11), 306 HTTP Request Handling—PHP Script interactive mode, BeanShell, 84 listing (10.4), 466 interactive shell (Groovy), scripts, running, Hunt, Andy, 53 127-128 hybrid compiler-interpreters, 11 Intercepting Method Calls hypertext, 60 listing (4.18), 161 19_1936_index.qxd 7/11/07 12:14 AM Page 512

512 INDEX

interfaces Groovy Compilable interface, 437-440 compatibility with, 137 engine interfaces, Scripting API, embedding with, 184-190 432-440 implicit memory management, 78 implementing JVM (), 78-82 BeanShell, 93-94 BeanShell, 83-98 Python, 105-107 class loaders, 81-82 Rhino, 112-114 execution engine, 81-82 Incovable interface, 435-437 garbage collector, 78 Interfaces listing (9.34), 436 Jython, 98-109 interpreters, 6 other programming languages, architecture, 10 82-83 compilers, compared, 8-12 Python, 98-109 hybrid interpreter-compilers, 11 Rhino, 110-120 Introductory DataSet Example popularity of, 79 listing (5.14), 209 programming Introductory JSP Example administration, 328-334 listing (6.19), 277 Ant scripting, 309-322 Introductory MarkupBuilder Example interactive debugging, 304-309 listing (5.21), 224 management, 328-334 Invocable Example listing (9.32), 433 shell scripting, 323-328 invoice( ) method, 92 unit testing, 292-304 invokeFunction( ) method, 434 programming language, 80 isCase( ) method, 155-156 Python embedding with, 108-109 J scripting in, 103-105 Jacl, 122 Rhino Jakarta Commons Logging project, 247 embedding with, 114-120 JAR (Java Archive) files, Groovy, 491 scripting in, 111-112 Java single inheritance model, 78 API (application programming treading, 77 interface), 80-82 Java Community Process (JCP), 121, 385 applications Java Database Connectivity (JDBC) planning, 79 driver, 196 speed issues, 79 Java Runtime Environment (JRE), 24 architecture, 80-82 Java Specification Request (JSR), 67 BeanShell, embedding with, 94-98 Java Specification Request 241, 121 C++, compared, 78 Java Virtual Machine (JVM). See JVM class files, 80 (Java Virtual Machine) commercial release of, 77 JavaAdapter class, Rhino, 114 cross-platform portability, 77 JavaBeans, BeanShell, 88 dynamic linking, 78 Javagator project, Netscape Navigator, 110 generics, 31 19_1936_index.qxd 7/11/07 12:14 AM Page 513

INDEX 513

JavaScript, web applications, 65-67 Language Tags—Configuration JCP (Java Community Process), 121, 385 listing (10.11), 480 JDBC (Java Database Connectivity) Language Tags—Groovy Script driver, 196 listing (10.12), 481 Jetty servlet, 213 Language Tags—Original Groovy Script JRE (Java Runtime Environment), 24 listing (10.10), 479 JRuby, 122 languages JSP (Java Server Pages), BSF (Bean compilation languages, 52 Scripting Framework), 275-280 programming languages JSR (Java Specification Request), 67 assembly languages, 5 JSR 223 RI (Reference Implementation), code as data, 19-23 installing, 499-502 compilers, 6 , 122 data structures, 17-19 JUnit, 293-295 Groovy programming language, 80, JUnit Example listing (7.1), 294 120-121 JVM (Java Virtual Machine), 7, 24-25, high-level languages, 6 78-82 JRuby, 122 BeanShell, scripting in, 83-98 JudoScript, 122 class loaders, 81 ObjectScript, 123 bootstrap class loaders, 81 OOP (object-oriented programming) user-defined class loaders, 82 languages, 40 execution engine, 81-82 third-generation programming garbage collector, 78 languages, 6 Jython, scripting in, 98-109 typing, 13-17 other programming languages, using in, scripting languages, 4-24 82-83 administration, 55-58 Python, scripting in, 98-109 closures, 20 Rhino, scripting in, 110-120 compilers, 8-12 Jython, 80, 98-109, 126 customization, 49-51 downloading, 98 embedding, 70 installing, 99 extensiblity, 70-71 switches, 101 Groovy, 194 interpreters, 8-12 K-L Java, 80-82 keys, reversed keys, 410-411 learnability, 71-72 keywords (ADD), 5 management, 55-58 Label Widget listing (8.4), 347 method arguments, 21-23 LAMP (Linux, Apache, MySQL, PHP), 386 Perl, 43 language syntax, Groovy, 137-177 prototyping models, 44-48 triple-quote syntax, 144-145 Python, 18 language tags, Web Scripting Framework, software development support, 478-481 51-55 19_1936_index.qxd 7/11/07 12:14 AM Page 514

514 INDEX

source code, 12-13 4.25 {collect( ) Method}, 173 Tcl (Tool Command Language), 4.26 {inject( ) Method}, 173 37-44 4.27 {find( ) Method}, 174 Tcl/Java, 122 4.28 {findAll( ) Method}, 174 UNIX shell languages, 41-42 4.29 {every( ) Method}, 175 user interface programming, 58-59 4.30 {any( ) Method}, 175 virtual machines, 24-25 4.31 (Resource Handling with web applications, 59-69 Closures), 176 wiring, 40-44 4.32 {getText( ) Method}, 178 Web Scripting Framework, 4.33 {eachLine( ) Method}, 179 allowing, 459 4.34 {readLines( ) Method}, 179 Linux, Apache, MySQL, PHP (LAMP), 386 4.35 {splitEachLine( ) Method}, 180 List Box Widget listing (8.5), 348 4.36 {eachByte( ) Method}, 181 listings 4.37 {readBytes( ) Method}, 181 4.1 (Groovy Shell), 128 4.38 {write( ) Method}, 181 4.2 (Compiling Groovy Scripts with 4.39 {append( ) Method}, 182 Ant), 132 4.40 {eachFile( ) Method}, 182 4.3 (Groovy Script Structure), 134 4.41 {eachFileRecurse( ) Method}, 182 4.4 (Handling Command-Line 4.42 (Process Handling), 183 Arguments in Groovy), 136 4.43 (Evaluating Groovy Scripts from 4.5 (Loose Typing), 138 Java), 184 4.6 (Dynamic Typing and 4.44 (Binding), 186 Polymorphism), 139 4.45 (Loading Groovy Scripts as Java 4.7 (Autoboxing), 140 Classes), 187 4.8 (Triple-Quote Syntax), 144 4.46 (Implementing Java Interfaces in 4.9 (GStrings), 145 Groovy), 189 4.10 (Regular Expressions), 147 4.47 (Security Example), 191 4.11 (Lists), 150 4.48 (Security Policy), 191 4.12 (Ranges), 151 4.49 (Evaluating Inline Scripts Under 4.13 (Maps), 153 Security Policy), 193 4.14 (switch-case Structure), 154 5.1 (GroovySQL Example), 197 4.15 (Extending the switch-case 5.2 (SQL Object Creation Mechanism), 156 Alternatives), 199 4.16 (for Loop), 157 5.3 {Sql.loadDriver( ) Method}, 199 4.17 (Classes), 159 5.4 (Initializing the Sql Object with a 4.18 (Intercepting Method Calls), 161 Connection—Java Class), 200 4.19 (Operators), 163 5.5 (Initializing the Sql Object with a 4.20 (Operator Overloading), 164 Connection—Groovy Script), 201 4.21 (GroovyBeans), 165 5.6 (Creating an Sql Object with 4.22 (Safe Navigation), 168 DataSource), 202 4.23 (Closures), 170 5.7 {eachRow( ) Method and GString 4.24 {each( ) Method}, 172 Query Parameters}, 202 19_1936_index.qxd 7/11/07 12:14 AM Page 515

INDEX 515

5.8 {eachRow( ) Method and List Query 6.6 (Method Call Example), 262 Parameters}, 203 6.7 {BSFEngine.apply( ) Method 5.9 {executeUpdate( ) Method and CSV Example}, 263 Files}, 204 6.8 (Register Bean Example—JavaBean 5.10 {execute( ) Method}, 205 Definition), 266 5.11 (Stored Procedure), 207 6.9 (Register Bean Example—Java 5.12 (Stored Procedure Call), 208 Application), 267 5.13 (Transactions), 208 6.10 (Register Bean Example—Script), 5.14 (Introductory DataSet 267 Example), 209 6.11 (Declare Bean Example—Java 5.15 {each( ) Method}, 211 Application), 269 5.16 {findAll( ) Method}, 212 6.12 (Declare Bean Example—Script), 5.17 (Groovlet Deployment 270 Descriptor), 214 6.13 (Compile Example), 271 5.18 (Groovlet Example), 218 6.14 (Compile Example—Result), 271 5.19 (Groovy Template Support), 221 6.15 {Customized compileExpr( ) 5.20 (Template Example), 222 Method}, 272 5.21 (Introductory MarkupBuilder 6.16 (Modified Compile Example), 273 Example), 224 6.17 (Modified Compile Example— 5.22 (Advanced Groovy Programming Result), 274 Example), 225 6.18 (Compiled Script Usage 5.23 (XHTML Markup Example), 226 Example), 274 5.24 (NodeBuilder Example), 227 6.19 (Introductory JSP Example), 277 5.25 (SAX Handler Example), 230 6.20 (BSF JSP Example), 279 5.26 (SaxBuilder), 231 6.21 (Simple XSLT Transformation), 281 5.27 (Parsing Documents with 6.22 (Extended XSLT Example), 282 DomBuilder), 232 6.23 (Xalan-J Extension Example), 283 5.28 (Creating Documents with 6.24 (Xalan-J BSF Example), 285 DomBuilder), 233 7.1 (JUnit Example), 294 5.29 (Namespace Example), 234 7.2 (GroovyTestCase Example), 296 5.30 {Custom BuilderSupport Implemen- 7.3 {GroovyTestCase.assertLength( ) tation (BuilderSupport.java)}, 235 Method Example}, 298 5.31 (SwingBuilder), 237 7.4 (GroovyTestCase.assertArrayEquals( ) 5.32 (TableLayout), 239 Method Example), 298 5.33 (TableModel), 241 7.5 {GroovyTestCase.assertContains( ) 6.1 {BSFEngine.eval( ) Method Method Example}, 299 Example}, 254 7.6 {GroovyTestCase.assertToString( ) 6.2 (BSF Exception Handling), 256 Method Example}, 299 6.3 {BSFEngine.exec( ) Method 7.7 {GroovyTestCase.assertScript( ) Example}, 256 Method Example}, 299 6.4 (Executing a Script File), 258 7.8 {GroovyTestCase.shouldFail( ) 6.5 (Function Call Example), 260 Method Example}, 300 19_1936_index.qxd 7/11/07 12:14 AM Page 516

516 INDEX

7.9 (TestSuite Example), 300 8.21 (Active File Template), 379 7.10 (GroovyTestSuite Example), 301 8.22 (Active File Generator), 380 7.11 (Interactive Debugging with the 9.1 (Discovery Mechanism), 393 Groovy Shell), 306 9.2 (Engine Metadata), 394 7.12 (Ant BSF Support Example), 314 9.3 {getScriptEngine( ) Method 7.13 (Advanced Ant BSF Support Example}, 395 Example), 315 9.4 {getEngineByName( ) Method 7.14 (AntBuilder Example), 317 Example}, 397 7.15 (Advanced AntBuilder 9.5 {getEngineByExtension( ) Method Example), 320 Example}, 398 7.16 (Shell Scripting Example), 327 9.6 (Register Engine Example), 399 7.17 (Administration Script 9.7 (Evaluating Script Contained in a Example), 329 String), 400 7.18 (Script Job Example), 330 9.8 (Evaluating Script Contained in a 7.19 (Quartz Scheduler Configuration File), 401 Example), 332 9.9 (Handling Script Evaluation 8.1 (Scripted Component Pattern Result), 402 Example), 340 9.10 (Handling ScriptException), 403 8.2 (Mediator Interface), 346 9.11 (Binding Example), 406 8.3 (Mediator-Aware Widget 9.12 (Overriding the Engine Scope), 407 Abstraction), 346 9.13 (Advanced Binding Example—Java 8.4 (Label Widget), 347 Application), 408 8.5 (List Box Widget), 348 9.14 (Reserved Keys), 411 8.6 (Mediator Implementation), 349 9.15 (Global Scope Example), 412 8.7 (Mediator Client), 350 9.16 (Variables Overriding—An 8.8 (Glue Code Client), 352 Example), 413 8.9 (Modified Mediator 9.17 (ScriptEngineManager’s Shortcut Component), 353 Methods), 414 8.10 (Ant Task That Compiles All Scripts 9.18 (Global Scope Initialization), 415 Inside the Project), 357 9.19 (Namespace Example), 416 8.11 (Scripted Object Factory Pattern 9.20 (Evaluating a Script in the Script Example), 357 Context), 418 8.12 (Subject Component), 363 9.21 (Determining the Attribute’s 8.13 (Observer Label Widget), 364 Scope), 420 8.14 (Price Observer Label Widget), 364 9.22 (Obtaining an Attribute from the 8.15 (Tax Observer Label Widget), 365 Desired Scope), 421 8.16 (Observer Client), 365 9.23 (Modifying Attributes in script— 8.17 (Broadcasters Example), 367 Script), 422 8.18 (Extension Point Example), 371 9.24 (Modifying Attributes in script— 8.19 (Modified Extension Point Java Application), 422 Example), 372 9.25 (Defining a Custom 8.20 (Active File Example), 376 Namespace), 424 19_1936_index.qxd 7/11/07 12:14 AM Page 517

INDEX 517

9.26 (Custom Application Context), 424 10.14 (PHP to Java—Factory Class), 485 9.27 (Using Custom Application 10.15 (PHP to Java—Client Code), 486 Context), 426 10.16 (PHP to Java—Java Class), 486 9.28 (Custom Engine Writer 10.17 (PHP to Java—Modified Factory Example), 427 Class), 487 9.29 (Output Statement), 429 lists, Groovy, 149-151 9.30 (Method Call Syntax), 430 Lists listing (4.11), 150 9.31 (Program Example), 431 LiveScript, 65 9.32 (Invocable Example), 433 Loading Groovy Scripts as Java Classes 9.33 (Method Call), 435 listing (4.45), 187 9.34 (Interfaces), 436 logical branching, Groovy, 154-156 9.35 (Compilable), 438 lookupBean( ) method, 266 9.36 (Threading), 441 looping, Groovy, 156-158 9.37 (Example php.ini loops, for loop, BeanShell, 88-89 Configuration), 442 loose methods, 134 9.38 (Dynamic Binding—Java loose typing, Groovy, 138-140 Objects), 443 Loose Typing listing (4.5), 138 9.39 (Dynamic Binding—Java loosely defined methods, 91 Classes), 443 loosely typed syntax, BeanShell, 87 10.1 (Sample Web Application Loui, Ronald, 71 Descriptor), 454 LucasArts, 69 10.2 (Accessing Application Context), 463 M 10.3 (HTTP Request Handling—HTML machine instructions, 4-5 Form), 465 machine language, 5 10.4 (HTTP Request Handling—PHP main( ) method, 134, 295, 304 Script), 466 Make tool, 51 10.5 (Including Resources), 470 make( ) method, 222 10.6 (Request Forwarding), 471 Makefiles, 52 10.7 {Session Handling—Login Form management, scripting, 55-58, 328-334 (form.jsp)}, 474 manager initialization, BSF (Bean 10.8 (Session Handling—Login Scripting Framework), 252 Servlet), 475 manuals, BeanShell, 98 10.9 (Session Handling—PHP maps, Groovy, 152-153 Script), 477 Maps listing (4.13), 153 10.10 (Language Tags—Original Groovy Markup syntax, Groovy, 223-236 Script), 479 McIlroy, Doug, 40 10.11 (Language Tags—Configuration), Mediator Client listing (8.7), 350 480 Mediator Implementation listing (8.6), 349 10.12 (Language Tags—Groovy Mediator Interface listing (8.2), 346 Script), 481 mediator scripting pattern, 341 10.13 (PHP to Java—PHP Class), 484 consequences, 345 problem, 341-342 19_1936_index.qxd 7/11/07 12:14 AM Page 518

518 INDEX

related patterns, 354 eachFileRecurse( ), 182 sample code, 345-354 eachLine( ), 179 solution, 342-345 eachRow( ), 202-203 Mediator-Aware Widget Abstraction eval( ), 96, 400-404 listing (8.3), 346 evaluate( ), 184 metadata, engine metadata, Scripting API, every( ) method, 175 393, 395 exec( ), 270 method arguments, functions as, 21, 23 execute( ), 205-206 Method Call Example listing (6.6), 262 executeUpdate( ), 204-205 Method Call listing (9.33), 435 exportAsCSV( ), 377 Method Call Syntax listing (9.30), 430 exportAsSQL( ), 377 method closure, 92 exportAsXML( ), 377 method code syntax, Scripting API, fail( ), 294 429-431 filter( ), 22 method overloading, 139 find( ) method, 174 methods findAll( ), 211-212 addClassPath( ), 324 findAll( ) method, 174-175 any( ) method, 175-177 forward( ) method, 471-473 append( ), 181 frame( ), 237 apply( ), 263-264 get( ), 95 assertArrayEquals( ), 298 getBindings( ), 412 assertContains( ), 299 getComponent( ), 347 assertEquals( ), 294 getEngineByExtension( ), 398 assertLength( ), 298 getEngineByMimeType( ), 398 assertScript( ), 299 getEngineByName( ), 397 assertToString( ), 299 getInterface( ), 97 BeanShell, 91-92 getLanguageName( ), 394 BSF (Bean Scripting Framework), getMethodCallSyntax( ), 429-431 259-264 getOutputStatement( ), 429 call( ), 169, 260 getScriptEngine( ), 395-396 changed( ), 347 getter/setter methods, 165 closures, curly braces, 172 getText( ), 178 collect( ) method, 173 include( ) method, 469-471 compile( ), 275 Incovable interface, 434-437 compileExpr( ), 272 inject( ) method, 173-174 currentThread( ), 444 invoice( ), 92 declareBean( ), 268-269 invokeFunction( ), 434 doSomeAction( ), 374 isCase( ), 155-156 each( ), 211 lookupBean( ), 266 each( ) method, 171-172 loosely defined methods, 91 eachByte( ), 180 main( ), 134, 295, 304 eachFile( ), 182 make( ), 222 19_1936_index.qxd 7/11/07 12:14 AM Page 519

INDEX 519

method closure, 92 Modified Compile Example—Result method overloading, 139 listing (6.17), 274 notifyObservers( ), 363 Modified Extension Point Example panel( ), 237 listing (8.19), 372 put( ), 406 Modified Mediator Component readBytes( ), 181 listing (8.9), 353 readLines( ), 179 Modifying Attributes in script—Java registerBean( ), 266, 268 Application listing (9.24), 422 registerEngineExtension( ), 399 Modifying Attributes in script—Script registerEngineMimeType( ), 399 listing (9.23), 422 registerEngineName( ), 399 mod_perl, 62 run( ), 134 Mythical Man-Month: Essays on Software script( ), 95 Engineering, The, 48 select( ), 22 sendError( ), 468 N set( ), 95 named parameters, GroovyBeans, 166-167 setBindings( ), 407 Namespace Example listing (5.29), 234 setChanged( ), 363 Namespace Example listing (9.19), 416 setClassPath( ), 324 NamespaceBuilder, Groovy, 234 setEmail( ), 308 Namespaces, 234 setPrice( ), 363 custom namespaces, 423-427 setUp( ), 294 script context, 416-419 shouldFail( ), 299 native types, programming languages, 14 show( ), 350 navigation showDialog( ), 346, 350 objects, GroovyBeans, 167 sleep( ), 444 save navigation, GroovyBeans, 168 source( ), 95-96 Netscape Navigator, Javagator project, 110 splitEachLine( ), 180 NodeBuilder, Groovy, 227-229 Sql.loadDriver( ), 199-200 NodeBuilder Example listing (5.24), 227 standalone methods, 134 notifyObservers( ) method, 363 termination( ), 134 testAnimal( ), 156 O testInit( ), 294 O’Reilly, Tim, 61 testIteration( ), 294 object-oriented programming (OOP) unregisterBean( ), 266 languages, 40 update( ), 238, 364 object-oriented technology (OOT), 40 valueChanged( ), 348 Object-Relational Mapping (ORM) waitFor( ), 183 tools, 196 widgetChanged( ), 346, 348, 350 objects write( ), 181 BeanShell, 92 modes, BeanShell, 84 creating, GroovySQL, 199-207 Modified Compile Example GroovyBeans, navigation, 167 listing (6.16), 273 GString objects, Groovy, 145-146 19_1936_index.qxd 7/11/07 12:14 AM Page 520

520 INDEX

ObjectScript, 123 mediator pattern, 341-354 Observer Client listing (8.16), 365 observer pattern, 359-369 Observer Label Widget listing (8.13), 364 script object factory pattern, 354-359 observer pattern, 359 scripted components pattern, 337-341 consequences, 362 Perl programming language, 43 problem, 359-360 web applications, 61-62 related patterns, 369 Pettichord, Bret, 55 sample code, 362-369 PHP, 386 solution, 360-362 classes, 484 Obtaining an Attribute from the Desired client code, 486 Scope listing (9.22), 421 factory class, 486-487 OOP (object-oriented programming) web applications, 62-64 language, 40 PHP to Java—Client Code OOT (object-oriented technology), 40 listing (10.15), 486 operators, overloading, Groovy, 162-164 PHP to Java—Factory Class operands, 4 listing (10.14), 485 operartion code, 4 PHP to Java—Java Class Operator Overloading listing (4.20), 164 listing (10.16), 486 Operators listing (4.19), 163 PHP to Java—Modified Factory Class ORM (Object-Relational Mapping) listing (10.17), 487 tools, 196 PHP to Java—PHP Class Ousterhout, John K., 37 listing (10.13), 484 out variable (Groovlet), 214 polymorphism, 139 Output Statement listing (9.29), 429 Groovy, 139-140 output statements, Scripting API, 429 Portraits of Open Source Pioneers, 68 over( ) function, 21 Pragmatic Unit Testing in Java with overloading operators, Groovy, 162-164 JUnit, 53 overloading methods, 139 prepared statements, GroovySQL, 206-207 overriding Price Observer Label Widget engine scope, 407-409 listing (8.14), 364 variables, global scope, 413-414 primitive types, programming Overriding the Engine Scope languages, 14 listing (9.12), 407 print( ) command (BeanShell), 91 printColor( ) function, 140 P problems panel( ) method, 237 active file pattern, 375 parameters, named parameters, extension point pattern, 369 GroovyBeans, 166-167 mediator scripting pattern, 341-342 Parsing Documents with DomBuilder observer pattern, 359-360 listing (5.27), 232 script object factory pattern, 355 patterns, scripting, 335-337 scripted components pattern, 337-338 active file pattern, 375-380 procedures, stored procedures, GroovySQL, extension point pattern, 369-374 207-208 19_1936_index.qxd 7/11/07 12:14 AM Page 521

INDEX 521

Process Handling listing (4.42), 183 JVM (Java Virtual Machine), using in, processes, system operations, Groovy, 82-83 182-183 Jython, 98-109, 126 processors ObjectScript, 123 machine instructions, execution of, 4 OOP (object-oriented programming) machine language, 5 languages, 40 production environment, source code, Python, 98-109, 126 12-13 Rhino, 110-114, 116-120 Program Example listing (9.31), 431 second-generation programming programmatic binding, 442 languages, 5 programming. See also scripting Tcl/Java, 122 extreme programming, 33-35 third-generation programming Java languages, 6 administration, 328-334 typing, 13, 15 Ant scripting, 309-322 composite types, 14 interactive debugging, 304-309 dynamic typing, 15-16 management, 328-334 native types, 14 shell scripting, 323-328 user-defined types, 14 unit testing, 292-304 weak typing, 17 UNIX, 40 programs user interface programming, 58-59 computer programs, 5 programming languages. See also scripting Scripting API, 431-432 languages project building, scripting languages, assembly languages, 5 51-53 BeanShell, 83-98, 126 properties, GroovyBeans, 165-166 compilers, 6 prototyping models, 44-48 Groovy, 80, 120-121, 125, 194-195 evolutionary prototyping, 46 advantages of, 126 Python, 47-48 configuring, 492 throwaway prototyping, 45-46 downloading, 491 put( ) method, 406 Groovlets, 212-219 Python scripting language, 18, 47-48, GroovySQL, 196-212 98-109, 126 IDE support, 495-497 Java, embedding with, 108-109 installing, 127, 491-492 scripting Markup syntax, 223-236 basic syntax, 101-103 Swing user interfaces, 236-243 exception handling, 107-108 templates, 220-223 in Java, 103-105 testing, 492-493 interface implementation, 105-107 high-level languages, 6 Java, 80 Q-R JRuby, 122 Quartz scheduler, 330-334 JudoScript, 122 Quartz Scheduler Configuration Example listing (7.19), 332 19_1936_index.qxd 7/11/07 12:14 AM Page 522

522 INDEX

queries, database queries, GroovySQL, responses, Web Scripting Framework, 468 202-205 results, Web Scripting Framework, displaying, 460-462 ranges, Groovy, 151-152 reversed keys, 410-411 Ranges listing (4.12), 151 Rhino, 80, 110-120 readBytes( ) method, Groovy, 181 downloading, 110 readBytes( ) Method listing (4.37), 181 Java, embedding with, 114-120 readers, 427-428 scripting readLines( ) method, Groovy, 179 in Java, 111-112 readLines( ) Method listing (4.34), 179 interface implementation, 112-114 refactoring, 33 JavaAdapter class, 114 Register Bean Example—Java Application RI (Reference Implementation) listing (6.9), 267 JSR 223 RI, installing, 499-502 Register Bean Example—JavaBean robustness, scripting languages, 29-32 Definition listing (6.8), 266 run( ) method, 134 Register Bean Example—Script running listing (6.10), 267 BeanShell, 84 Register Engine Example listing (9.6), 399 scripts, Groovy, 127-130 registerBean( ) method, 266, 268 runtime performance, code, 26-28 registerEngineExtension( ) method, 399 registerEngineMimeType( ) method, 399 S registerEngineName( ) method, 399 safe navigation, GroovyBeans, 168 registering Safe Navigation listing (4.22), 168 beans, BSF (Bean Scripting Framework), Sample Web Application Descriptor 265-268 listing (10.1), 454 scripting engines, Scripting API, 399 SAX Handler Example listing (5.25), 230 scripting languages, BSF (Bean SaxBuilder, Groovy, 230-231 Scripting Framework), 249-252 SaxBuilder listing (5.26), 231 regular expressions (regex), Groovy, script context 146-148 attributes, 419-423 Regular Expressions listing (4.10), 147 binding, Scripting API, 416-428 request forwarding, Web Scripting namespaces, 416-419 Framework, 471-473 script directory, Web Scripting Framework, Request Forwarding listing (10.6), 471 457-458 request handling, Web Scripting script files Framework, 464-467 BSF (Bean Scripting Framework), request scope, Web environments, 448 executing, 257-259 request variable (Groovlet), 214 Groovy, evaluating, 129-130 Reserved Keys listing (9.14), 411 Script Job Example listing (7.18), 330 resource handling, closures, Groovy, script methods, Web Scripting 176-177 Framework, 458 Resource Handling with Closures listing (4.31), 176 19_1936_index.qxd 7/11/07 12:14 AM Page 523

INDEX 523

script object factory pattern, 354 script object factory pattern, consequences, 356 354-359 problem, 355 scripted components pattern, related patterns, 359 337-341 sample code, 356-359 Jython, 98-109 solution, 355 management, 328-334 script( ) method, 95 Python, 98-109 Scripted Component Pattern Example basic syntax, 101-103 listing (8.1), 340 embedding, 108-109 scripted components pattern, 337 exception handling, 107-108 consequences, 339 in Java, 103-105 problem, 337-338 interface implementation, 105-107 related patterns, 341 Rhino, 110-120 sample code, 340-341 embedding, 114-120 solution, 338-339 in Java, 111-112 Scripted Object Factory Pattern Example interface implementation, 112-114 listing (8.11), 357 JavaAdapter class, 114 ScriptEngineManager class, shortcut shell scripting, 323-328 methods, 414-415 system programming, 26-35 ScriptEngineManager’s Shortcut Methods hybrids, 35-36 listing (9.17), 414 Web Scripting Framework, disabling, ScriptException, handling, 403-404 456-457 scripting. See also programming Scripting API, 94, 385, 388-391 administration, 328-334 architecture, 391 BeanShell, 83-98 binding, 404-411 autoboxing, 89-90 dynamic binding, 442-444 basic syntax, 86-87 engine scope, 405-411 commands, 91 global scope, 411-416 embedding, 94-98 script context, 416-428 for loop, 88-89 BSF, compared, 445 interface implementation, 93-94 code generation, 428 JavaBeans, 88 method call syntax, 429-431 loosely typed syntax, 87 output statement, 429 methods, 91-92 programs, 431-432 objects, 92 discovery mechanism, 391-393 switch-case statement, 90 engine interfaces, 432 Workspace Editor, 85 Compilable interface, 437-440 design patterns, 335-337 Incovable interface, 432-437 active file pattern, 375-380 engine metadata, 393, 395 extension point pattern, 369-374 General Scripting API, 389 mediator pattern, 341-354 origins of, 386-388 observer pattern, 359-369 script, evaluating, 400-404 19_1936_index.qxd 7/11/07 12:14 AM Page 524

524 INDEX

scripting engines compilers, 8-12 creating, 395-398 customization, 49-51 registering, 399 data structures, 17-19 threading, 440-442 embedding, 70 Web Scripting API, 389 extensiblity, 70-71 Web Scripting Framework, 447, functions, as method arguments, 21-23 453-456 Groovy, 120-121, 125, 194-195 architecture, 448-453, 482-488 advantages of, 126 bindings, 462-469 configuring, 492 configuring, 456-462 downloading, 491 forward( ) method, 471-473 Groovlets, 212-219 include( ) method, 469-471 GroovySQL, 196-212 language tags, 478-481 IDE support, 495-497 session handling, 473-478 installing, 127, 491-492 threading, 481-482 Markup syntax, 223-236 scripting engines Swing user interfaces, 236-243 creating, Scripting API, 395-398 templates, 220-223 registering, Scripting API, 399 testing, 492-493 scripting environments, BSF (Bean interpreters, 8-12 Scripting Framework), 245-246 Java applications, 275-285, 287 API (application programming architecture, 248-249 interface), 80-82 bean declaration, 268-270 architecture, 80-82 bean registration, 265-268 class files, 80 compilation, 270-275 JVM (Java Virtual Machine), 80-82 data binding, 264-270 programming language, 80 downloading, 247 JRuby, 122 engine initialization, 252 JudoScript, 122 exception handling, 255 JVM (Java Virtual Machine), using in, functions, 259-264 82-83 manager initialization, 252 Jython, 98-109, 126 methods, 259-264 learnability, 71-72 origins of, 247 management, 55-58 script files, 257-259 ObjectScript, 123 scripting language registration, 249-252 Perl, 43 scripts, 253-257 prototyping models, 44-48 scripting languages, 4-24. See also evolutionary prototyping, 46 programming languages Pyhton, 47-48 administration, 55-58 throwaway prototyping, 45-46 BeanShell, 83-98, 126 Pyhton, 126 closures, 20 Python, 18, 98-109 code as data, 19-23 registering, BSF (Bean Scripting Framework), 249-252 19_1936_index.qxd 7/11/07 12:14 AM Page 525

INDEX 525

Rhino, 110-114, 116-120 security, Groovy, 190-194 software development support, 51-55 Security Example listing (4.47), 191 project building, 51-53 Security Policy listing (4.48), 191 testing, 53, 55 select( ) method, 22 source code, production environment, sendError( ) method, 468 12-13 servers, web servers, Apache Web Tcl (Tool Command Language), 37-38, server, 62 43-44 servlets, Web Scripting Framework Tcl/Java, 122 architecture, 449-451 typing, 13, 15 session handling, Web Scripting composite types, 14 Framework, 473-478 dynamic typing, 15-16 Session Handling—Login Form (form.jsp) native types, 14 listing (10.7), 474 user-defined types, 14 Session Handling—Login Servlet weak typing, 17 listing (10.8), 475 UNIX shell languages, 41 Session Handling—PHP Script user interface programming, 58-59 listing (10.9), 477 virtual machines, 24-25 session scope, Web environments, 448 web applications, 59, 61-67 session variable (Groovlet), 215 ASP (Activer Server Pages), 64 set( ) method, 95 games, 68-69 setBindings( ) method, 407 JavaScript, 65-67 setChanged( ) method, 363 Perl, 61-62 setClassPath( ) method, 324 PHP, 62-64 setEmail( ) method, 308 UNIX, 68 setPrice( ) method, 363 wiring, 40-44 setting classpaths, Groovy, 131-132 UNIX shell languages, 42 setUp( ) method, 294 scripts shell languages, UNIX, 41-42 evaluating, Scripting API, 400-404 shell scripting, 323-328 Groovy Shell Scripting Example listing (7.16), 327 command-line arguments, 136 shortcut methods, ScriptEngineManager compiling, 130-133 class, 414-415 dependencies, 131 shouldFail( ) method, 299 running, 127-130 show( ) method, 350 structure, 133-136 showDialog( ) method, 346, 350 unit testing, 303-304 Simple XSLT Transformation working with, BSF (Bean Scripting listing (6.21), 281 Framework), 253-257 single inheritance model, Java, 78 SCUMM (Script Creation Utility for Maniac sleep( ) method, 444 Mansion), 69 Smith, Ben, 61 second-generation programming languages, 5 19_1936_index.qxd 7/11/07 12:14 AM Page 526

526 INDEX

software development support, scripting switch-case structure, Groovy, 154-156 languages, 51-55 switch-case Structure listing (4.14), 154 project building, 51-53 switches, jythonc, 101 testing, 53-55 syntax solutions BeanShell active file pattern, 375 autoboxing, 89-90 extension point pattern, 370 basic syntax, 86-87 mediator scripting pattern, 342-345 for loop, 88-89 observer pattern, 360-362 JavaBeans, 88 script object factory pattern, 355 loosely typed syntax, 87 scripted components pattern, 338-339 switch-case statement, 90 someFunc( ) function, 103 Groovy, 137-177 source code, production environment, Python, basic syntax, 101-103 12-13 system operations, Groovy, 178 source( ) method, 95-96 files, 178-182 splitEachLine( ) method, Groovy, 180 processes, 182-183 splitEachLine( ) Method listing (4.35), 180 system programming, scripting SQL Object Creation Alternatives compared, 26-35 listing (5.2), 199 hybrids, 35-36 Sql.loadDriver( ) method, GroovySQL, 199-200 T Sql.loadDriver( ) Method listing (5.3), 199 TableLayout component (Swing), 239-240 standalone methods, 91, 134 TableLayout listing (5.32), 239 statements TableModel component (Swing), 241-243 Groovy, 138 TableModel listing (5.33), 241 prepared statements, GroovySQL, Tag Descriptor (TLD) file, 278 206-207 tags, language tags, Web Scripting switch-case statement, BeanShell, 90 Framework, 478-481 Stored Procedure Call listing (5.12), 208 Tax Observer Label Widget listing (8.15), Stored Procedure listing (5.11), 207 365 stored procedures, GroovySQL, 207-208 Tcl (Tool Command Language), 37-38, strings, Groovy, 143-145 43-44 GStrings, 145-146 Tk extension, 58-59 strongly typed languages, 17 Tcl Blend, 122 structure, scripts, Groovy, 133, 135-136 Tcl/Java, 122 Subject Component listing (8.12), 363 TDD (test-driven development), 33 Swing user interfaces Template Example listing (5.20), 222 TableLayout component, 239-240 templates, Groovy templates, 220-223 TableModel component, 241-243 termination( ) method, 134 SwingBuilder, Groovy, 236-243 test suites, unit testing, 300-303 SwingBuilder listing (5.31), 237 test-driven development (TDD), 33 switch-case statement, BeanShell, 90 testAnimal( ) method, 156 19_1936_index.qxd 7/11/07 12:14 AM Page 527

INDEX 527

testing scripts, 303-304 Groovy, 492-493 test suites, 300-303 scripting languages, 53-55 UNIX testInit( ) method, 294 programming, 40 testIteration( ) method, 294 scripting, 68 TestSuite Example listing (7.9), 300 shell languages, 41-42 Thinking in Java, 30 unregisterBean( ) method, 266 third-generation programming update( ) method, 238, 364 languages, 6 updateObservers( ) method, 364 Thomas, Dave, 53 upper( ) function, 102 threading URLs (unified resource locators), 60 Java, 77 user interface programming, 58-59 Scripting API, 440-442 user manuals, BeanShell, 98 Web Scripting Framework, 481-482 user-defined class loaders (JVM), 82 Threading listing (9.36), 441 user-defined types, programming throwaway prototyping, 45-46 languages, 14 Tk extension (Tcl), 58-59 Using Custom Application Context TLD (Tag Library Descriptor) file, 278 listing (9.27), 426 Tool Command Language (Tcl). See Tcl (Tool Command Language) V transactions, GroovySQL, 208-209 valueChanged( ) method, 348 Transactions listing (5.13), 208 van Rossum, Guido, 32, 48 triple-quote syntax, Groovy, 144-145 variables Triple-Quote Syntax listing (4.8), 144 global scope, overriding, 413-414 type juggling, Groovy, 140-143 Groovlets, 214 type theory, 13 Variables Overriding—An Example types, classes, 14 listing (9.16), 413 typing VBA ( for Applications), 50-51 dynamic typing, Groovy, 139-140 Venners, Bill, 36 loose typing, Groovy, 138-140 virtual machines, 7 programming languages, 13, 15 scripting languages, 24-25 composite types, 14 Visual Basic for Applications (VBA), 50-51 dynamic typing, 15-16 native types, 14 W user-defined types, 14 waitFor( ) method, 183 weak typing, 17, 138 weak typing, 17, 138 weakly typed languages, 17 U web applications, 59, 61-67 unified resource locators (URLs), 60 ASP (Activer Server Pages), 64 unit testing, 292-293 games, 68-69 assertion methods, 297-300 JavaScript, 65-67 GroovyTestCase class, 296-297 Perl, 61-62 JUnit, 293-295 19_1936_index.qxd 7/11/07 12:14 AM Page 528

528 INDEX

PHP, 62-64 wiring scripting languages, 40-44 UNIX, 68 Perl, 43 Web Scripting API, 389 Tcl (Tool Command Language), 43-44 Web Scripting Framework, 447, 453-456 UNIX shell languages, 41-42 architecture, 448, 482-488 Workspace Editor, BeanShell, 85 context, 448-449 write( ) method, Groovy, 181 interaction, 451-453 write( ) Method listing (4.38), 181 servlet, 449-451 writers, engine writers, 427-428 bindings, 462 WWW (World Wide Web), 59 application, 462-464 HTML (Hypertext Markup Language), 60 request handling, 464-467 HTTP (HyperText Transfer Protocol), 60 response, 468 hypertext, 60 servlet, 468-469 URLs (unified resource locators), 60 configuring, 456-462 forward( ) method, 471-473 X–Z include( ) method, 469-471 Xalan-J (XSLT), BSF (Bean Scripting language tags, 478-481 Framework), 280-287 languages, allowing, 459 Xalan-J BSF Example listing (6.24), 285 results, displaying, 460-462 Xalan-J Extension Example script directory, 457-458 listing (6.23), 283 script methods, 458 XHTML Markup Example scripting, disabling, 456-457 listing (5.23), 226 session handling, 473-478 XPath (XML Path Language), 280 threading, 481-482 XSLT (Extensible Stylesheet Language web servers, Apache Web servers, 62 Transformation), 280 widgetChanged( ) method, 346, 348, 350