perfect infrastructure: middleware, frameworks, widget sets, services Scripting makes a flexible (agile) applikation layer: views und controller Grails, GSP, JBoss Seam, WebWork, Struts 2 Actions,... Example: combination of XML parser, Java networking and Swing widget set in order to build a standard RSS feed reader Donnerstag, 1. November 12
Java Allow to learn about the business: keep entities, relations, and behaviour flexible through scripting Usages: Spring beans, JBoss components,rule engines (groovyrules.dev.java.net, JSR-94), Grails, enterprise risk management for world-leading insurances Example: calculation rules for bonus allocation Donnerstag, 1. November 12
runtime inspection and modifications Ad-hoc queries are not foreseeable "Backdoor" for the live execution of scripts Particularly useful for product support, failure analysis, hot fixes, emergencies Usages: Oracle JMX Beans, XWiki, SnipSnap, Ant, Canoo WebTest, Grails Console, ULC Admin Console Demo: a Swing remote contol Donnerstag, 1. November 12
im Servlet users = servletContext.getAttribute('users') bad = users.findAll { user -> user.cart.items.any { it.price < 0 } } servletContext.setAttribute('users', users - bad) Probleme mit der Datenbank Verbindung? Gefährliche Benutzer rauswerfen Donnerstag, 1. November 12
It's impossible (and not desirable!) to design for every possible future requirement Allow for easily changing the code without tedious setup for compilation and deployment Follow the lessons of Perl, PHP, Python,... Example: groovyblogs.org Donnerstag, 1. November 12
installer, service monitoring, reports, statistics, automated documentation, functional tests, HTML scraping, Web remote control, XML- RPC, REST, WebServices Usages with Ant, Maven, AntBuilder, Gant, Canoo WebTest, Grails scaffolding, ... Examples: sending mails via dynamic Ant scripting, hooking scripts into Ant Donnerstag, 1. November 12
ant = new AntBuilder() for (user in users) { ant.mail(mailhost: 'my.email.server', subject: 'build done') { from address: '[email protected]' to address: user.email message """ Dear ${user.name}, a new build has finished at ${new Date().toGMTString()}""" } } Heinzelmännchen Beispiel: mail schicken Donnerstag, 1. November 12
Player().play( new Pattern(it) ) } def player = [ targetStarted : { play "D E" } targetFinished : { play "C5maj" } ] project.addBuildListener(player as BuildListener ) </groovy> Es geht auch ein bisschen grooviger ... Donnerstag, 1. November 12
technological or algorithmic ideas with more expressiveness, quicker feedback, and enhanced analysis capabilities Later port to Java is optional Usages: early user feedback about the domain model through a functional Grails prototype, algorithms for image manipulation Example: prime number disassembly Donnerstag, 1. November 12
% y == 0 } } int primeBelow(x) { (x..1).find { isPrime(it) } } List primeFactors(x) { if (isPrime(x)) return [x] int p = primeBelow(x) while (p > 1) { if (x % p == 0) return [p, *primeFactors(x.intdiv(p))] p = primeBelow(p-1) } } for (n in 100..110) { println "$n : "+primeFactors(n)} Prototype example: prime numbers Donnerstag, 1. November 12