Groovy for Domain-specific Languages - Second Edition
http://www.ebook3000.com ...
[ 139 ] Power Groovy DSL Features In this chapter, we will cover some more advanced Groovy features. Coincidentally, these are a ...
Power Groovy DSL Features [ 140 ] Named parameters We have touched upon the concept of named parameters already. In a previous c ...
Chapter 7 [ 141 ] def namedParamsMethod1(Map params) { assert params.a == 1 assert params.b == 2 assert params.c == 3 true } exp ...
Power Groovy DSL Features [ 142 ] These features combine neatly together for use in a DSL. Consider a method call to transfer fu ...
Chapter 7 [ 143 ] static String sentMessage static def sendMessage1(id, message) { sentMessage = "Sending (${message}) to ${id}" ...
Power Groovy DSL Features [ 144 ] Command chains We already knew that Groovy allows us to leave out parentheses when calling met ...
Chapter 7 [ 145 ] The breakdown of the calling sequence is then as follows: Calling deposit returns a Map with an entry currenc ...
Power Groovy DSL Features [ 146 ] The builder design pattern It would be useful to have a means of constructing objects such tha ...
Chapter 7 [ 147 ] In fact, I can claim to have come up with one of the patterns myself. In 1989, while working for Glockenspiel ...
Power Groovy DSL Features [ 148 ] Constructing this simple snippet of XML in Java requires numerous method calls to create XML e ...
Chapter 7 [ 149 ] Namespaced XML What if we would like to create namespaced XML? In GroovyMarkup, tags conform to the method cal ...
Power Groovy DSL Features [ 150 ] This technique is not limited to namespaces. We can use it anywhere that we need to output a c ...
Chapter 7 [ 151 ] Within the closure, we can reference a variable, mkp, which allows us to give instructions to the builder in o ...
Power Groovy DSL Features [ 152 ] To begin with, we define the root node of our XML by invoking MarkupBuilder.customers() on the ...
Chapter 7 [ 153 ] } body { h1 "Groovy Builders are cool!" } } then: xmlIsIdentical writer.toString(), "simple.html" In the next ...
Power Groovy DSL Features [ 154 ] <table> <tr> <td>groovy.util.NodeBuilder</td> </tr> <tr> & ...
Chapter 7 [ 155 ] } } tr { td "groovy.util.FactoryBuilderSupport" td { table { tr { td "groovy.util.NodeBuilder" } tr { td "groo ...
Power Groovy DSL Features [ 156 ] street:"2 Rock Road",city:"Bedrock") def customerList = [ fred, barney] when: builder.customer ...
Chapter 7 [ 157 ] NodeBuilder NodeBuilder is used to build tree structures of node instances in memory. We use exactly the same ...
«
4
5
6
7
8
9
10
11
12
13
»
Free download pdf