I've been neglecting my blog, but just a quick note to mention that my latest
talk at JavaOne, DSLs with Groovy, is posted up on Slideshare.
The talk's designed for someone with no significant Groovy experience (unlike
most Groovy DSL talks), so if it's interesting to you, check it out.
I'm hoping (but not promising) to turn the talk into a series of Blog entries
in the coming weeks.
So if you want, just wait, and I'll send you explanations in more digestible
bits and pieces in the coming weeks.
(As usual, this entry is cross posted to my main blog site.)
... (more)
Now that we've gone over some Groovy basics, it's time to switch back to
writing in the Java language, and talk about how to run Groovy programs
inside your Java programs. Like most general purpose programming languages,
there's more than one way to do things in Groovy, and that's never more true
when it comes to executing Scripts - I once counted 7 ways to use the String
"System.exit(0)" to shut down the VM, and I'm quite sure that I missed a few.
For this example, we'll use the method I consider to be the best and most
extensible, which uses the class GroovyShell.
Before we ... (more)
Before I start talking about using Groovy's capabilities to create a DSL
(mostly in Java), let's take a few minutes to go over what Groovy is.
Groovy is a general purpose scripting language which runs on the JVM, and can
largely be viewed as a superset of Java. Take the following program:
public class Hello {
String name; public void sayHello() { System.out.println("Hello
"+getName()+"!"); } public void setName(String name) { this.name = name; }
public String getName() { return name; } public static void main(String[]
args) { Hello hello = new Hello(); hello.setName("world"); hel... (more)
In my previous post, I started with a simple Java program (which also worked
in Groovy), and slowly stripped out the cruft until I was left with the
following Groovy script:
def sayHello(name) { println("Hello $name!") } def name = 'world'
sayHello(name)
Now, let's add a little change to use an array. Since Groovy is a rough
superset of Java, you might be tempted to do something like:
def sayHello(name) { println("Hello $name!") } String[] names = {"SintSi",
"Kaitlyn", "Keira"} for (String name : names) { sayHello(name) }
But this won't work. This is one place where Java syntax d... (more)
The Open Ajax Alliance is a standards organization with the mission of
ensuring interoperability within Web based Ajaxified applications. One of
their standards relates to intercomponent communication - the ability to
subscribe and publish messages which can then be picked up by code written by
other authors.
Please note that if you don't have an interest in Open Ajax, this post may
not be especially illuminating - I've talked about the addOnEvent function
before, even recently.
To write an Open Ajax application, you need to subscribe to events, much like
in JSF 2, by register... (more)