<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3449578868254929667</id><updated>2011-09-25T10:26:48.781-07:00</updated><category term='Commons FtpClient'/><category term='ZipOutputStream'/><category term='Observer closure Groovy'/><title type='text'>David's Dev Notes</title><subtitle type='html'>Yep, another Java developer starting a blog to try to give back to the community.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>27</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-6506954263597623983</id><published>2011-05-26T06:40:00.001-07:00</published><updated>2011-05-26T06:40:20.156-07:00</updated><title type='text'>Using Date and Calendar – At your own risk!</title><content type='html'>&lt;p&gt;You can find lots of issues discussed on the ‘net about the problems of the Calendar/Date classes in Java. Here are a few that recently reared their ugly head in our code:&lt;/p&gt;  &lt;p&gt;1. This one is actually not in either of these but in trying to output our Date. Beware of the mm instead of MM when using SimpleDateFormat. Yep, one of my team members used the following code: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#333333" size="2"&gt;SimpleDateFormat sdf = new SimpleDateFormat(“yyyymmdd”);&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Surprisingly everyone in our tests had a birthday of the first of the month! I think that the right solution would be that mm is wrong and mi is minutes and mo is month. This would solve the confusion.&lt;/p&gt;  &lt;p&gt;2. Did you know that there is a difference whether you use Calendar.HOUR or Calendar.HOUR_OF_DAY? Ok, i admit it this one is documented in the javdocs, but i would still think that it is a bit of surprise that in the afternoon, if you do &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#333333" size="2"&gt;cal.set(Calendar.HOUR,0);&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;that you will get 12:00 PM!&lt;/p&gt;  &lt;p&gt;3. Why does toString() of Calendar not put out the date in some format?&lt;/p&gt;  &lt;p&gt;4. Beware that DAY_OF_WEEK is not zero based while MONTH is.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-6506954263597623983?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/6506954263597623983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/05/using-date-and-calendar-at-your-own.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6506954263597623983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6506954263597623983'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/05/using-date-and-calendar-at-your-own.html' title='Using Date and Calendar – At your own risk!'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-5468734726109291925</id><published>2011-04-28T04:15:00.000-07:00</published><updated>2011-04-28T04:16:03.811-07:00</updated><title type='text'>Using StAX to extract records from an XML file</title><content type='html'>When processing large XML files, it is impossible to build a DOM of the whole file as you are sure to run out of memory. Java 6 includes StAX (it was around earlier of courser) and it is the best solution to deal with large XML files to build a scalable XML file processor. However, it still may be desirable to build a Document Model when processing an individual record due to decisions in code that may need to be made based on information lower in the node. Due to this requirement, we use StAX to extract each record from our gargantuan XML files and then pass to a different class that builds a DOM for the processing the record. Here is the very simple code with explanation of what we did.&lt;br /&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; StaxExtracter {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;     XMLEventReader reader;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; headerRead = false;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; openStream(InputStream s) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; XMLStreamException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         XMLInputFactory inputFactory = XMLInputFactory.newInstance();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         reader = inputFactory.createXMLEventReader(s);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; close() &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; XMLStreamException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         reader.close();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;//function to allow us to read part of a document that does not include the header&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; setHeaderRead(&lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; val) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         headerRead = val;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;The above is some boilerplate code needed for our class. The heavy work is the XMLEventReader, created in the openStream function on line 7.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Following this we have two main functions. The first is used to read the open XML tag of the document and any important attributes in this tag, and the second is to read an actual record. Since the class is written to read recursively all sub elements of a record, it is important that we not read the open XML tag of our document as a regular record, since that will mean we wind up reading our entire document as one record! However, since there may be need to work on part of a file, i allowed an override on line 15 above so we can skip reading the header. The open XML tag is obviously not a complete XML tag so we do some heavier work here, returning the attributes as a map for use by our application, in addition to the raw line which can be used upstream in our application.&lt;/p&gt;Here is the actual code:&lt;br /&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     * Since header is not a complete element we need to do special treatment so we will read the header attributes&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     * into a hashmap to save all the attributes besides returning the raw data&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     *&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     * @return the rawData of document start and header&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     * @throws XMLStreamException&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;     */&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; String getHeaderAndAttributesAsMap(Map&amp;lt;String, String&amp;gt; attributes) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; XMLStreamException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; documentStart = false;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         StringBuffer rawData = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StringBuffer();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (reader.hasNext() &amp;amp;&amp;amp; !headerRead) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;             XMLEvent e = reader.nextEvent();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isStartDocument()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;                 documentStart = true;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             } &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isStartElement()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;                 headerRead = true;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;                 StartElement startElement = e.asStartElement();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (Iterator i = startElement.getAttributes(); i.hasNext();) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;                     Attribute attr = (Attribute) i.next();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;                     attributes.put(attr.getName().getLocalPart(), attr.getValue());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;                 }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;//skip whitespace before document&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (documentStart) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;                 rawData.append(e.toString());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!headerRead)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; null;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; rawData.toString();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Now, on to the main function for reading each element of our XML file:&lt;br /&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;enum&lt;/span&gt; RecordStatus {BODY,NO_DATA,CLOSE_BODY_TAG,END_DOCUMENT}&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; RecordStatus getNextRecord(StringBuffer recordData) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; XMLStreamException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!headerRead) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; RuntimeException(&lt;span style="color: rgb(0, 96, 128);"&gt;"need to read header line before calling this function"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     RecordStatus rc = RecordStatus.NO_DATA;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     String recordName = null;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; finishedReadingElement = false;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; startOfRecord = false;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (reader.hasNext() &amp;amp;&amp;amp; !finishedReadingElement) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         XMLEvent e = reader.nextEvent();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isStartElement()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!startOfRecord) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;                 startOfRecord = true;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;                 recordName = e.asStartElement().getName().getLocalPart();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         } &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isEndElement()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             EndElement endElement = e.asEndElement();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (endElement.getName().getLocalPart().equals(recordName)) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;                 finishedReadingElement = true;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;                 rc = RecordStatus.BODY;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;             }  &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!startOfRecord) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;                 &lt;span style="color: rgb(0, 128, 0);"&gt;//todo  we could make this better by e adding validation here to save the START_BODY_TAG&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;                 rc = RecordStatus.CLOSE_BODY_TAG;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;                 finishedReadingElement = true;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         } &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isEndDocument()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             rc = RecordStatus.END_DOCUMENT;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;//skip whitespace before element&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (startOfRecord || rc == RecordStatus.CLOSE_BODY_TAG) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.isCharacters())&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;                 &lt;span style="color: rgb(0, 128, 0);"&gt;//need to re-escape characters so SAX parser wont choke on it&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;                 recordData.append(StringEscapeUtils.escapeXml(e.toString()));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;                 recordData.append(e.toString());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; rc;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;We use an enum to give us maximal information about what was read while return the actual raw data in a StringBuffer that is allocated outside our function.&lt;br /&gt;&lt;p&gt;Of course, you could do ALL the parsing in your StAX implementation as well, as described &lt;a href="http://javaboutique.internet.com/tutorials/stax/index3.html"&gt;here&lt;/a&gt; and other places, but this code allows us to continue to use the more elegant DOM for our actual work.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-5468734726109291925?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/5468734726109291925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/04/using-stax-to-extract-records-from-xml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5468734726109291925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5468734726109291925'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/04/using-stax-to-extract-records-from-xml.html' title='Using StAX to extract records from an XML file'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-3109234554251293371</id><published>2011-02-14T04:04:00.000-08:00</published><updated>2011-02-14T04:09:01.361-08:00</updated><title type='text'>Java in Hollywood -- Using the Actor Model in Java</title><content type='html'>We have all been hearing how the programming paradigm has started to change, in that Moore’s law will no longer bail us out to speed up our applications and instead we we need to program better to use our multiple processors. Many have been pushing the &lt;a href="http://en.wikipedia.org/wiki/Actor_model"&gt;Actor Model&lt;/a&gt; as the simplest way to get to solid multithreading without locks, etc. And for that reason, we are getting pushed to use Scala and other languages instead of Java. But you can also use these frameworks in your existing Java application so i figured i would give it a spin using &lt;a href="http://akka.io/"&gt;Akka&lt;/a&gt;, unfortunately postponing yet again my first application in Scala.&lt;br /&gt;For a  starter, my app just needs to run a job asynchronously with no response, but this would be enough to familiarize myself with Akka and see how to use it.&lt;br /&gt;&lt;p&gt;So, after downloading Akka, the following dependencies are needed to get started:&lt;br /&gt;&lt;/p&gt;&lt;a href="http://4.bp.blogspot.com/-gOfdxeW6hTQ/TVkajTVTc5I/AAAAAAAAEoI/Yk9kklwdC4U/s1600/akka.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 182px;" src="http://4.bp.blogspot.com/-gOfdxeW6hTQ/TVkajTVTc5I/AAAAAAAAEoI/Yk9kklwdC4U/s320/akka.JPG" alt="" id="BLOGGER_PHOTO_ID_5573515207635071890" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Now, we can write a small class. Here is the code to send asynchronous messages and not get a response back.&lt;br /&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; MyActor1 &lt;span style="color: rgb(0, 0, 255);"&gt;extends&lt;/span&gt; UntypedActor {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; onReceive(Object message) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         Integer numMessage = (Integer) message;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tincoming message "&lt;/span&gt; + numMessage);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;1000000000;i++) {           &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tFinished Message "&lt;/span&gt; + numMessage);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tStopping on thread "&lt;/span&gt; + numMessage);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         getContext().stop();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; InterruptedException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;50;i++) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;             Actors.actorOf(MyActor1.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;).start().sendOneWay(i);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;        Thread.sleep(50000);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Line 16 shows the code to launch the thread as we “start’ the class and then send the message. In this case we sendOneWay but other methods include  sendRequestReply, and sendRequestReplyFuture, as you can see in the &lt;a href="http://doc.akka.io/untyped-actors-java"&gt;documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;When you run this application you will see that it launched 16 threads and uses them for the 50 jobs. I found it nice that it was expressive – sendOneWay, as well as to access the context to end the activity of this object.&lt;br /&gt;&lt;p&gt;The next step was learning how to customize the behavior of my thread pool, which led to this change to the application:&lt;br /&gt;&lt;/p&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; MyActor &lt;span style="color: rgb(0, 0, 255);"&gt;extends&lt;/span&gt; UntypedActor {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MyActor(MessageDispatcher dispatcher) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         getContext().setDispatcher(dispatcher);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; onReceive(Object message) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         Integer numMessage = (Integer) message;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tincoming message "&lt;/span&gt; + numMessage);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;1000000000;i++) {           &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tFinished Message "&lt;/span&gt; + numMessage);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         System.out.println(Thread.currentThread().getName() + &lt;span style="color: rgb(0, 96, 128);"&gt;"\tStopping on thread "&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         getContext().stop();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; InterruptedException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;final&lt;/span&gt; MessageDispatcher d = Dispatchers.newExecutorBasedEventDrivenDispatcher(&lt;span style="color: rgb(0, 96, 128);"&gt;"dispatcher"&lt;/span&gt;).withNewThreadPoolWithLinkedBlockingQueueWithCapacity(50)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;       .setCorePoolSize(5)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;       .setMaxPoolSize(6)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;       .setKeepAliveTimeInMillis(60000)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;       .setRejectionPolicy(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ThreadPoolExecutor.CallerRunsPolicy())&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;       .build();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;50;i++) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;             ActorRef actor = Actors.actorOf(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; UntypedActorFactory() {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; UntypedActor create() {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MyActor(d);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             });&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;             actor.start().sendOneWay(i);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;        Thread.sleep(50000);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;As you see, on line 18 we create the ThreadPool, in Akka terminology called a MessageDispatcher. There are a few different kinds as mentioned &lt;a href="http://doc.akka.io/dispatchers-java"&gt;here&lt;/a&gt;. But this change means that we now need a constructor to receive this dispatcher for use. (Don’t worry &lt;a href="http://doc.akka.io/spring-integration"&gt;Spring integration&lt;/a&gt; is not a problem to use DI for the actors).&lt;br /&gt;&lt;p&gt;And voila, we see in the printouts that indeed this is running in multiple threads. Of course, for the need of one way with no reply, there really is no need to use Akka since the code is pretty straightforward using plain old Spring + Java as follows, where we define our ThreadPool bean in the application context:&lt;/p&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;bean id=&lt;span style="color: rgb(0, 96, 128);"&gt;"taskExecutor"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;=&lt;span style="color: rgb(0, 96, 128);"&gt;"org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&lt;/span&gt; destroy-method=&lt;span style="color: rgb(0, 96, 128);"&gt;"destroy"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;         &amp;lt;property name=&lt;span style="color: rgb(0, 96, 128);"&gt;"corePoolSize"&lt;/span&gt; value=&lt;span style="color: rgb(0, 96, 128);"&gt;"5"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;         &amp;lt;property name=&lt;span style="color: rgb(0, 96, 128);"&gt;"maxPoolSize"&lt;/span&gt; value=&lt;span style="color: rgb(0, 96, 128);"&gt;"10"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         &amp;lt;property name=&lt;span style="color: rgb(0, 96, 128);"&gt;"queueCapacity"&lt;/span&gt; value=&lt;span style="color: rgb(0, 96, 128);"&gt;"25"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &amp;lt;/bean&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Once we have this, use of the code to do the same things just involves: taskExecutor.execute(bean). So, in this specific instance, the overhead of adding the scala and akka jars would not be justified, but clearly for more significant multithreaded needs, this could be a powerful tool to simplify code and make it very readable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-3109234554251293371?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/3109234554251293371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/02/java-in-hollywood-using-actor-model-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/3109234554251293371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/3109234554251293371'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2011/02/java-in-hollywood-using-actor-model-in.html' title='Java in Hollywood -- Using the Actor Model in Java'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-gOfdxeW6hTQ/TVkajTVTc5I/AAAAAAAAEoI/Yk9kklwdC4U/s72-c/akka.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-8946011314086562230</id><published>2010-12-27T08:17:00.000-08:00</published><updated>2011-05-09T03:57:47.965-07:00</updated><title type='text'>Attachments in Axis 1.4</title><content type='html'>&lt;p&gt;In our "legacy" application, we have a series of classes implemented to connect to a certain 3rd party web service implementation. As this was implemented a number of years ago, it was done using axis 1.4. There are many web service calls, but the differences in their implementation is not that great, as all have core fields that are in common. Thus, the implementation we used was of the template method pattern. The use of this pattern was to encapsulate ALL the connectivity and security issues (client certificates) of using the web services in our base class. Each new web service is a trivial amount of work. All we need to do is to run wsdl2java to generate the classes, inherit our new implementation from the template base class, which then forces us to implement a number of abstract methods that include the URL of the service, as well as functions to return the request and response classes of the web service call. The template method also requests each service to add its unique data specific to that request.&lt;br /&gt;&lt;/p&gt;So, even after our knowledgeable web services implementer moved on, this did not impede our ability to add new services, since all that plumbing was untouched code that need not be thought about. All that changed recently when we had a new web service call to add that uses attachments to send XML as an attachment. (This is third party software but I think i understand the logic of why this was done). Suddenly, the work was not as simple as it was before, and we had no axis 1.4 expert anymore and little place to turn anymore, as the world has moved forward past axis 1.4. But with such an elegant implementation it seemed worth trying to make this work within axis 1.4 and after much Googling (and even "Bing"ing), and finally some trial and error of coding, we came to an elegant solution to keep our template method pattern intact and yet still add this functionality. The main (only?) documentation i found about using attachments in axis 1.4 was &lt;a href="http://jcs.mobile-utopia.com/jcs/19599_EchoAttachment.java"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here is the code added to the template base class:&lt;br /&gt;&lt;/p&gt;&lt;div style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;div style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;&lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; DataHandler attachment = getAttachment();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (attachment == null) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     response = call.invoke(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Object[]{request});&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; } &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     AttachmentPart ap= &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; AttachmentPart(attachment);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     QName qn = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; QName(namespace, &lt;span style="color: rgb(0, 96, 128);"&gt;"DataHandler"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     call.registerTypeMapping(attachment.getClass(), &lt;span style="color: rgb(0, 128, 0);"&gt;//Add serializer for attachment.&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;             qn, JAFDataHandlerSerializerFactory.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;, JAFDataHandlerDeserializerFactory.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     call.addAttachmentPart(ap);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     call.addParameter(&lt;span style="color: rgb(0, 96, 128);"&gt;"source"&lt;/span&gt;, qn, ParameterMode.IN);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     response = call.invoke(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Object[]{request,attachment});&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;The first line calls a new method getAttachment which is not abstract (or final). This means that we can add this functionality without having to  implement it in all the implementing classes. The default implementation of the base class returns null and the new class we have will obviously override this and return the attachment of type javax.activation.DataHandler.&lt;/p&gt;If we have an attachment, the steps we need to take are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;On Line 5 we wrap this attachment in an Axis class AttachmentPart&lt;br /&gt;&lt;/li&gt;&lt;li&gt;On Line 7-8, we need to register this attachments using the serializer/serializer JAFDataHandler that will handle the serializing and deserializing of the attachment. Note that the name “DataHandler” is just what i made up.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Line 9 adds the attachment to the call&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Line 11 adds the attachment as a parameter to the call&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Line 12 includes our request class and the attachment in the actual call.&lt;/li&gt;&lt;/ul&gt;One other change we needed to make was that since until now we always had only one parameter, we did not need to register the first parameter, but now this became necessary in order to add the second.&lt;br /&gt;&lt;br /&gt;And in these few lines since our use of the template method pattern enabled us to keep our complex implementation intact and still accomodate this new functionality.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-8946011314086562230?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/8946011314086562230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/12/in-our-legacy-application-we-have.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/8946011314086562230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/8946011314086562230'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/12/in-our-legacy-application-we-have.html' title='Attachments in Axis 1.4'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-3957295208360442466</id><published>2010-08-25T04:41:00.001-07:00</published><updated>2010-08-25T04:41:35.368-07:00</updated><title type='text'>Beware of Static Initializers (even in 3rd party code!)</title><content type='html'>&lt;p&gt;As i was just releasing a small patch to our application that uses &lt;a href="http://poi.apache.org/"&gt;POI&lt;/a&gt;, i noticed a bunch of errors at startup. Of course, I immediately thought i changed more than I thought and began combing thru the code to see why i was getting this error. The stack trace was pointing to an error in the code of &lt;a href="http://poi.apache.org/"&gt;POI&lt;/a&gt;, which had a index out of range on something that clearly was not related to anything i had changed in our code in a LONG time. But why was this error happening and why now?&lt;/p&gt;  &lt;p&gt;After searching the web and coming up empty on this error, I began looking more carefully and realized that the data structure at hand is one that is statically initialized on demand. What that means is that it is one of those static functions that when called, checks to see if the given data structure is built and if not, builds it then. Well, that’s nice but in our multithreaded application, we had two threads simultaneously trying to build an Excel spreadsheet so one of them got thrown out due to this static initialization that was probably in progress.&lt;/p&gt;  &lt;p&gt;The code looks as follows:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;public static List getBuiltinFormats()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ( builtinFormats == null )      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; populateBuiltinFormats();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return builtinFormats;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font color="#666666"&gt;So we have a static function using the builtInFormats. The actual function populateBuiltinFormats is synchronized but that just means that it cannot be invoked simultaneously, but if is partially populated then the second thread will think it is complete!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#666666"&gt;Since this is third party code, the simplest solution is at startup of my main to force the initialization of this static data structure, so i invoke HSSFDataFormat.getBuiltinFormats(); and voila, the issue has been solved.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;As a Spring evangelist, I would point out that if you use Spring for functionality like this, and then in an init function that Spring uses, you will have the data populated. You could also just have it statically created and not conditionally. Otherwise, you would need to build the internal data structure to a temporary variable and only assign it when complete. Of course, that will mean a second check in the function populateBuiltinFormats to see that if by the time you got in, the data is already built, or maybe only allow this function to run once.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-3957295208360442466?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/3957295208360442466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/08/beware-of-static-initializers-even-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/3957295208360442466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/3957295208360442466'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/08/beware-of-static-initializers-even-in.html' title='Beware of Static Initializers (even in 3rd party code!)'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-4627817258840777281</id><published>2010-08-17T04:10:00.001-07:00</published><updated>2010-08-17T04:10:02.965-07:00</updated><title type='text'>Tips For Maintainable Code</title><content type='html'>&lt;p&gt;Due to a need of late to maintain a lot of code (where of course not all of it has been written by me), I have been able to give a lot of thought to which tips I have read about in the past that strike me as the most important to have maintainable code. In many scenarios, companies simply rewrite their applications every few years and thus this issue may not be relevant but in my case where the lack of manpower makes this impossible, (and the application works so well there is no business justification for it), it has led me to think carefully how to set up a project and practices to have in place so that an application is maintainable and customizable in a reasonable way. Much of what i will be listing is based on the book Clean Code which I already blogged about previously &lt;a href="http://groovyjavathoughts.blogspot.com/2009/06/clean-code-programmers-are-authors.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;1. Keep functions short and simple – and if you need to add in more functionality, refactor it into a new function that clearly defines in its name what it does. In the book Clean Code, the insistence is that all functions do exactly one thing.&lt;/p&gt;  &lt;p&gt;2. Building on number 1, use small functions as a way to comment “funny” things you need to do. Sometimes, we have small things we needed to do – set some parameter to some funny value or the like and the person who makes this change may or may not comment this, since at the time it was so obvious and it may not even make the comment for the check in, since many files were checked in simultaneously, but if you get in the habit of creating a small function, such “nullOutParameterSoThatRequestHandlesCorrectly”, this comment is forever part of the code and will not get lost. It also means that when someone comes along later and sees it he can be sure it is there on purpose and not something wonder – it seems to me that removing this line is ok but i am not sure…&lt;/p&gt;  &lt;p&gt;3. Comprehensive Unit Tests. This is a great way to document your code since we can see the kind of input you expect to receive for a given function and how you expect to handle it. As has been written about extensively on the ‘net, when we see these unit tests, we have greater confidence to make changes since we have a baseline to evaluate our changes. One other advantage of the unit tests, is that if you added a new class with dependencies, and you are using Dependency Injection, like Spring, even if the code never made it to production we have a working example to build off for later use. This actually happened to me, where code was written and not released, but lacking an example of how to set up this class in my Spring application context led to my lack of confidence in using this class.&lt;/p&gt;  &lt;p&gt;4. Regression Tests. While Unit Tests are imperative, So are regression Tests. These are automated end to end tests so that we have a baseline of how the application works, in dailsychaining multiple functions together, what data was passed from beginning to end and what was received. I have used TestNG to make up regression tests due to the amazing features of paramterized testing, enabling to set up use cases that run multiple times with different inputs. (I hope to write more about this in an upcoming blog)&lt;/p&gt;  &lt;p&gt;5. use the Source Control and DONT save pruned code. Remove it. Don’t worry about it since you can get it from the source control. It just creates confusion.&lt;/p&gt;  &lt;p&gt;Remember, that YOU may be the one left to maintain the code so its in your best interest to get it right when developing it…&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-4627817258840777281?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/4627817258840777281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/08/tips-for-maintainable-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4627817258840777281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4627817258840777281'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/08/tips-for-maintainable-code.html' title='Tips For Maintainable Code'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-7548396779344537028</id><published>2010-06-07T04:41:00.000-07:00</published><updated>2010-06-14T04:27:30.824-07:00</updated><title type='text'>Testable Code Vs. OO code</title><content type='html'>Can we ever have a situation where the desire to have testable code is not 100% compatible with our Object Oriented Design? As i was working on some new code, i came across this issue and was happy to find that this is not a new issue as we see &lt;a href="http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx"&gt;here&lt;/a&gt;.  Even if you are not willing to accept the entire thesis, at the very least, we may want to use the thought of testing our code to drive some of our design decisions, since a robust, easy to run test suite is so important in software development, especially as projects grow in size and length and we can hardly remember what our code does anymore. An example of this in my project was my decision to implement the template method pattern where the template methods implemented by the child classes provide data back the parent class rather than invoke helper methods and provide greater functionality. This means that it is easier to test each new implementation and is less time consuming.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;An additional aspect of this issue can be seen based on the book Clean Code, discussed &lt;a href="http://groovyjavathoughts.blogspot.com/2009/06/clean-code-programmers-are-authors.html"&gt;in a previous post&lt;/a&gt;. While the focus there was on readability of the code, testability seems to overlap quite a bit with readability. The simpler we make our classes and our functions, the simpler for testing and finding the problems when test fail. Another aspect discussed at length there is the issue of parameters to function (or better yet, not having them).  It is recommended instead to have members the contain the necessary data rather than pass it from function to function. (Beware, as this means your classes will not be thread-safe and will require a new instance for each use).  From what i recall (not having access to this book right now), the main issue was readability, but here too, another fringe benefit is testability, especially if you are using TestNG (or JUnit 4). The reason for this, you create this class and populate the member data correctly and then can run tests repeatedly with little typing other than the method names. Writing and running the tests is now easier since you need not figure out all the parameters of a given function. Also, running multiple tests with different data (using TestNG DataProvider) is easier to provide.&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There are two other ways that testability impacts design in my current project:&lt;/div&gt;&lt;div&gt;The first is in using interfaces even when i have no plans to implement another implementation of a member class. It is much easier to mock behavior and isolate a test if we use interfaces and then plug in a simpler implementation of our interface for test purposes. Of course, use of Spring here and the Spring application context makes this trivial&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;The second aspect is in determining the scope of functions in order to enable testing of private functions as discussed &lt;a href="http://weblogs.java.net/blog/crazybob/archive/2005/07/package_scoping.html"&gt;here&lt;/a&gt;. I agree wholeheartedly with Bob Lee in his post that your code will be better if private functions are tested individually and you do not leave all your testing to the public API.&lt;br /&gt;&lt;br /&gt;I realize that much of what i write here is well known but i see that many of my peers are still not recognizing how important repeatable tests are. It is hard to see down the line when you are creating a new project from scratch. But, there are two ultra important reasons that we need to have a repeatable test suite. The first is documentation. As written about in Clean Code, Javadocs are not reliable. It happens too often in projects that programmers do not make sure to update javadocs as things change, and this is true for comments as well. The best documentation in addition to well written code with good naming (as discussed in my previous post about the book Clean Code), is the tests of the API, that show exactly how a function was meant to be used by the original author. It enables us to also what results it was meant to return and all error cases. The more tests on a function the more information provided. The second reason is maintainability. As our software has gotten larger/bloated, while staff has been pared down, a rewrite of our software is not truly possible. The confidence to make changes stems from good, repeatable tests.&lt;br /&gt;&lt;br /&gt;A second part of the confidence to make changes in a larger project comes from a good regression suite, which i hope to discuss in an upcoming post.&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://debasishg.blogspot.com/2009/10/are-orms-really-thing-of-past.html"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-7548396779344537028?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/7548396779344537028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/06/testable-code-vs-oo-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/7548396779344537028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/7548396779344537028'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/06/testable-code-vs-oo-code.html' title='Testable Code Vs. OO code'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-2543848144075812846</id><published>2010-04-14T04:20:00.000-07:00</published><updated>2010-04-14T04:22:00.938-07:00</updated><title type='text'>Using a non default Calendar in the Google API</title><content type='html'>All the examples in the Google Calendar API documentation involve using a default calendar. But i was looking at a project where i would have a shared calendar among users and this calendar would not be the default one. The simple code below demonstrates how to do this in Java. There are three parameter you will need to inject into this class (in my case via Spring) -- the username, password, and calendarname. Using these three you have what you need to work with the non default calendar.&lt;br /&gt;&lt;div   style="border: 1px solid silver; text-align: left; padding: 4px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 20px 0px 10px; width: 97.5%; direction: ltr; max-height: 200px; overflow: auto; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt; &lt;div    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; CalendarUtil {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;final&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; Logger logger = Logger.getLogger(CalendarUtil.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;.getName());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; String username;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; String password;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;   String calendarName;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; URL calendarUrl;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; CalendarService service;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;   &lt;span style="color: rgb(0, 128, 0);"&gt;// The base URL for a user's calendar metafeed (needs a username appended).&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;final&lt;/span&gt; String METAFEED_URL_BASE =&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;           &lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.google.com/calendar/feeds/"&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;final&lt;/span&gt; String CALENDAR_URL_SUFFIX = &lt;span style="color: rgb(0, 96, 128);"&gt;"/private/full"&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; init() {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     service = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; CalendarService(&lt;span style="color: rgb(0, 96, 128);"&gt;"DR-Appt-App-1"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;       service.setUserCredentials(username, password);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (AuthenticationException e) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; RuntimeException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Could not authenticate to Google Calendar with username: "&lt;/span&gt; + username, e);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     String calendarId = null;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;       calendarId = getCalendarId();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;     } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (IOException e) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; RuntimeException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Error caught trying to connect to calendar: "&lt;/span&gt;, e);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;     } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (ServiceException e) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; RuntimeException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Error caught trying to connect to calendar: "&lt;/span&gt;, e);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;       calendarUrl = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; URL(METAFEED_URL_BASE + calendarId + CALENDAR_URL_SUFFIX);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;     } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (MalformedURLException e) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; RuntimeException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Bad URL: "&lt;/span&gt; + calendarUrl.toString(), e);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (logger.isDebugEnabled()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;       logger.debug(&lt;span style="color: rgb(0, 96, 128);"&gt;"Url is "&lt;/span&gt; + calendarUrl.toString());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt;   &lt;span style="color: rgb(0, 128, 0);"&gt;//get id of correct calendar&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum43"&gt;  43:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; String getCalendarId() &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; IOException, ServiceException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum44"&gt;  44:&lt;/span&gt;     String calendarId = null;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum45"&gt;  45:&lt;/span&gt;     URL metafeedUrl = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; URL(METAFEED_URL_BASE + username);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum46"&gt;  46:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (logger.isDebugEnabled()) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum47"&gt;  47:&lt;/span&gt;       logger.debug(&lt;span style="color: rgb(0, 96, 128);"&gt;"Url is "&lt;/span&gt; + metafeedUrl.toString());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum48"&gt;  48:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum49"&gt;  49:&lt;/span&gt;     CalendarFeed resultFeed = service.getFeed(metafeedUrl, CalendarFeed.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum50"&gt;  50:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i = 0; i &amp;lt; resultFeed.getEntries().size(); i++) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum51"&gt;  51:&lt;/span&gt;       CalendarEntry entry = resultFeed.getEntries().get(i);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum52"&gt;  52:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (calendarName.equalsIgnoreCase(entry.getTitle().getPlainText())) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum53"&gt;  53:&lt;/span&gt;         calendarId = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; File(entry.getId()).getName();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum54"&gt;  54:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;break&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum55"&gt;  55:&lt;/span&gt;       }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum56"&gt;  56:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum57"&gt;  57:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; calendarId;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum58"&gt;  58:&lt;/span&gt;   }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; text-align: left; padding: 0px; line-height: 3pt; background-color: rgb(244, 244, 244); margin: 0em; width: 100%; direction: ltr; overflow: visible;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum59"&gt;  59:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;I have left out of the above the getters and setters to make it more concise.&lt;br /&gt;Using the above class, you now can access the non primary calendar simply using the syntax:&lt;br /&gt; &lt;blockquote&gt;&lt;span style="font-size:85%;color:#333333;"&gt;calendarUtil.getService().insert(…)&lt;/span&gt;&lt;span style="font-size:85%;color:#333333;"&gt;&lt;br /&gt;or any other service function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-2543848144075812846?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/2543848144075812846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/04/using-non-default-calendar-in-google.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2543848144075812846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2543848144075812846'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/04/using-non-default-calendar-in-google.html' title='Using a non default Calendar in the Google API'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-4489926307545769006</id><published>2010-02-22T04:12:00.001-08:00</published><updated>2010-02-22T04:12:16.610-08:00</updated><title type='text'>Not a Maven yet….</title><content type='html'>&lt;p&gt;Notwithstanding &lt;a href="http://groovyjavathoughts.blogspot.com/2009/11/gradle-my-new-build-tool.html"&gt;my post about using Gradle as a build tool&lt;/a&gt;, when i needed to start a new project i decided to use maven due to its amazing integration with an IDE (in my case Intellij), as well as its unbiquitousness.&lt;/p&gt;  &lt;p&gt;So, &lt;a href="http://groovyjavathoughts.blogspot.com/2009/10/time-to-become-maven.html"&gt;as i have written previously&lt;/a&gt;, it is really nice to use Maven as you get started, since with no writing of any config files you have the build process working for you. You have a clean, compile, jar, etc with no work and no opening of an XML file. But that is all theoretical. As i attempted to get going with my project i encountered two really serious issues that took a while to figure out, as well as one issue that needs better resolution.&lt;/p&gt;  &lt;p&gt;I will start with the more minor issue. When we use standard libraries that we need to add to our project, then things are pretty straightforward, in fact even better than not using maven. All you need to do is go to &lt;a title="http://mvnrepository.com" href="http://mvnrepository.com"&gt;http://mvnrepository.com&lt;/a&gt; and find the item you want and then it gives you the lines to add to your pom, and voila, you have added your dependency to your project. Of course, in one case, this was not so simple. I wanted to use log4j, so i said, ok, I will just use the latest version. That turned out to be a mistake since all of sudden the compile was failing with libraries i had never heard of unable to be downloaded and installed. As it turns out, after a bit of &lt;a href="http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/"&gt;googling&lt;/a&gt;, i learned that i needed to stay away from this latest version. But that is not even the issue i was referring to above. The issue i ran into was when i needed to use non standard libraries that are not in the mvnrepository site. This became difficult as i did not have an easy time figuring out what repository to use and what to add to my POM. In my case, i wanted to use Spring 3 and as far as i can tell, there is no browser for the Spring 3 release repository and thus no instructions for what my artifact ids would look like. (Hint to SpringSource – mention in the javadocs which jar is needed for a package). I wound up guessing based on one item i found somewhere and since i had downloaded the spring 3 distribution i was able to guess how the others would look and solved that issue. The second set of non standard artifacts were the google calendar ones. Here, i had to manually install them in my repository to get it going. Since it was a lot of jars, it was tedious, thought &lt;a href="http://www.techbits.de/2009/08/06/adding-googles-gdata-java-api-to-your-maven-repository/"&gt;here is a nice link to make it easier&lt;/a&gt;, just be sure to use version 2 and not 1 for those things are now in version 2.&lt;/p&gt;  &lt;p&gt;Now on the two major issues that i encountered. The first one was that my project would not compile successfully even though there was very little code in it other than use of the Google Calendar API. Finally after not getting anywhere for a while, i realized the issue must be Maven since it &lt;strong&gt;did&lt;/strong&gt; compile in my IDE. As it turned, it was a &lt;a href="http://jira.codehaus.org/browse/MCOMPILER-80"&gt;documented Jira issue&lt;/a&gt;, but as the guys in the comments wrote there, who would have thought that default of maven today would not be java 5 at least?&lt;/p&gt;  &lt;p&gt;The second one related to testing. Even though my most recent work has been using TestNG, i thought maybe i would give JUnit a try. When my JUnit tests were not being recognized, i figured out that this is because, once again, the default is junit 1.3. After a bit of searching i found what i need to do to add Junit4 to be the test runner. But, since i found the documentation of JUnit 4 lacking, i had decided to switch back but figured i would leave both dependencies in the POM. Well, that turned out to be a mistake too, as i eventually found &lt;a href="http://jira.codehaus.org/browse/SUREFIRE-377"&gt;here&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;But with these problems behind us, we trudge forward assuming that all should now be smooth sailing, until we need some other complex library….&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-4489926307545769006?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/4489926307545769006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/02/not-maven-yet.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4489926307545769006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4489926307545769006'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/02/not-maven-yet.html' title='Not a Maven yet….'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-283531957385549269</id><published>2010-01-27T02:36:00.000-08:00</published><updated>2010-01-27T02:44:14.464-08:00</updated><title type='text'>Asynchronous Groovy</title><content type='html'>&lt;p&gt;In my &lt;a href="http://groovyjavathoughts.blogspot.com/2010/01/asynchronous-code-with-spring-3-simple.html"&gt;previous post,&lt;/a&gt; i showed how simple asynchronous code in Spring 3 is. I wanted to see what it takes to write the same code in Groovy. Well, it is quite straightforward, using the &lt;a href="http://gpars.codehaus.org/"&gt;GPARS&lt;/a&gt; library. The docs there show it to be quite powerful, but to be loyal to our simple example, here is the code:&lt;br /&gt;&lt;/p&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; Asynchronizer.withAsynchronizer(4) {ExecutorService service -&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;       (0..9).each { num-&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;         service.submit({&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         Thread.sleep(2000);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         println(&lt;span style="color: rgb(0, 96, 128);"&gt;"Running for ${num} thread ${Thread.currentThread()}"&lt;/span&gt;)}as Runnable)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;       }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;See how you specify the number of threads in the parameter to the closure withAsynchronizer.&lt;br /&gt;There are lots more examples at the GPARS site.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-283531957385549269?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/283531957385549269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/01/asynchronous-groovy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/283531957385549269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/283531957385549269'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/01/asynchronous-groovy.html' title='Asynchronous Groovy'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-1924977950669930414</id><published>2010-01-13T06:09:00.000-08:00</published><updated>2010-01-13T06:12:53.636-08:00</updated><title type='text'>Asynchronous Code with Spring 3 – Simple as an annotation</title><content type='html'>&lt;p&gt;After reviewing some of the features of Spring 3, i decided to test out the asychronous features via annotation. And below is all the code i needed in order to have a function executed asynchronously in my application:&lt;/p&gt;&lt;div class="csharpcode"&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Asyncher {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;     @Async&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; myMethod(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;             Thread.sleep(2000);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (InterruptedException e) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;             e.printStackTrace();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         System.out.println(&lt;span style="color: rgb(0, 96, 128);"&gt;"Running for "&lt;/span&gt; + i);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; InterruptedException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         ApplicationContext ctx = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ClassPathXmlApplicationContext(&lt;span style="color: rgb(0, 96, 128);"&gt;"appContext.xml"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         Asyncher a = ctx.getBean(&lt;span style="color: rgb(0, 96, 128);"&gt;"asyncher"&lt;/span&gt;, Asyncher.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i=0; i&amp;lt;10;i++) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;                 a.myMethod(i);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         }      &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         ThreadPoolTaskExecutor t = ctx.getBean(&lt;span style="color: rgb(0, 96, 128);"&gt;"myExecutor"&lt;/span&gt;,ThreadPoolTaskExecutor.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (t.getActiveCount() &amp;gt; 0) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             System.out.println(&lt;span style="color: rgb(0, 96, 128);"&gt;"Number of tasks left: "&lt;/span&gt; + t.getActiveCount());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;             Thread.sleep(2000);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         t.shutdown();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Hard to believe, but all i needed to do was add the Async annotation on line 2 to my function and it works. of course we need a few lines in our application Context to make this work, but here they are:&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1.0"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="UTF-8"&lt;/span&gt;?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;beans&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.springframework.org/schema/beans"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;        &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:xsi&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:task&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.springframework.org/schema/task"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;        &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:context&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.springframework.org/schema/context"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;        &lt;span style="color: rgb(255, 0, 0);"&gt;xsi:schemaLocation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;task:annotation-driven&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;executor&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="myExecutor"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;task:executor&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="myExecutor"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;pool-size&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="2"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bean&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="asyncher"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Asyncher"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;beans&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;This same method can be used to create scheduled jobs as well, by changing or adding on line 7 the scheduler attribute and then adding in a scheduler bean&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;task:scheduler id="myScheduler" pool-size="10"/&amp;gt;&lt;/p&gt;You can read about it in the docs &lt;a href="http://static.springsource.org/spring/docs/3.0.x/reference/html/scheduling.html#scheduling-annotation-support"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-1924977950669930414?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/1924977950669930414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/01/asynchronous-code-with-spring-3-simple.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1924977950669930414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1924977950669930414'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2010/01/asynchronous-code-with-spring-3-simple.html' title='Asynchronous Code with Spring 3 – Simple as an annotation'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-5291683841288376126</id><published>2009-12-28T06:44:00.000-08:00</published><updated>2009-12-28T06:49:48.285-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ZipOutputStream'/><title type='text'>Creating a Zip file from a Stream</title><content type='html'>&lt;p&gt;Given an InputStream generated for me, i wanted to zip it up and email it. From the &lt;a href="http://www.exampledepot.com/egs/java.util.zip/CreateZip.html"&gt;java almanac&lt;/a&gt; i saw that i could easily do this if i write the stream to disk first. But this seemed like an unnecesary step for me. All i needed to do was to attach this outputstream to my email code and get it done. So, after a bit of playing, I got it working. Here is the code:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 2px; overflow: auto; text-align: left; line-height: 1pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; private byte[] createZipFile(InputStream in, String fileName) throws IOException {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;         ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;         ZipOutputStream zippedFile = new ZipOutputStream(zipOutputStream);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         byte[] buf = new byte[1024];&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         zippedFile.putNextEntry(new ZipEntry(myFileName));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         // Transfer bytes from the file to the ZIP file&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         int len;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         BufferedInputStream bs = new BufferedInputStream(bds[0].getInputStream());&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         while ((len = bs.read(buf)) &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt; 0) {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             zippedFile.write(buf, 0, len);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         zippedFile.closeEntry();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         bs.close();        &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         zippedFile.close();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         return zipOutputStream.toByteArray();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 3pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt; } &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;By wrapping the ZipOutputStream around a ByteArrayOutputStream, i am able to access the byte array and use that to attach to my email and send out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-5291683841288376126?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/5291683841288376126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/12/creating-zip-file-from-stream.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5291683841288376126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5291683841288376126'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/12/creating-zip-file-from-stream.html' title='Creating a Zip file from a Stream'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-6115887328503652566</id><published>2009-11-30T00:39:00.001-08:00</published><updated>2009-11-30T00:39:28.121-08:00</updated><title type='text'>Gradle, my new build tool?</title><content type='html'>&lt;p&gt;Last week, i had the pleasure of attending &lt;a href="http://www.javaedge.com/web/guest/javaedge-2009/about"&gt;the JavaEdge conference&lt;/a&gt;. The keynote speaker was Ted Neward, and you could read his thoughts about the conference &lt;a href="http://blogs.tedneward.com/"&gt;here&lt;/a&gt;. I enjoyed his lecture very much whose theme was that new programming languages in the VM is the future and we should all get used to it and get comfortable with it.&lt;/p&gt;  &lt;p&gt;One of the sessions that i attended was “Your Next Successful Build”, given by &lt;a href="http://www.javaedge.com/web/guest/javaedge-2009/speakers/#Baruch%20Sadogursky"&gt;Baruch Sadogursky&lt;/a&gt;, who used a slick tool instead of Powerpoint for his presentation, though it was a bit dizzying. I was happy that for the first time, i heard someone say some of my &lt;a href="http://groovyjavathoughts.blogspot.com/2009/10/time-to-become-maven.html"&gt;heretical thoughts&lt;/a&gt; – that while Maven has a lot of positive, it has many warts, mostly for the reasons of lack of documentation as well as dependency management. As a side note, i&amp;#160; was amazed to see that statistics show that 44% of companies are using Maven, which probably means they are spending countless hours debugging build issues!&amp;#160; It was also refreshing to hear him mention the pros of Ant as well as something he wants to be able to continue to use in his new build environment. But the most exciting part was to hear from Baruch that there is a tool out there that answers the call and it is &lt;a href="http://www.gradle.org/"&gt;Gradle&lt;/a&gt;. On the one hand, we like the standardization of the file layout of maven, but Gradle adds in &lt;a href="http://www.gradle.org/userguide.html"&gt;better documentation&lt;/a&gt; (200 pages!!!), and the ability to use a scripting language, Groovy, which also means you automatically have full access to Ant via Groovy. And of course, he says that dependency management has been fixed as compared to Maven 2. I am hoping to try it out in my next project.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-6115887328503652566?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/6115887328503652566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/gradle-my-new-build-tool.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6115887328503652566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6115887328503652566'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/gradle-my-new-build-tool.html' title='Gradle, my new build tool?'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-441273528346425817</id><published>2009-11-23T05:57:00.001-08:00</published><updated>2009-11-23T05:58:39.938-08:00</updated><title type='text'>Why did Hibernate do that?!</title><content type='html'>&lt;p&gt;As i have &lt;a href="http://groovyjavathoughts.blogspot.com/2009/08/grails-and-domain-model-or-why-i-prefer.html"&gt;mentioned in the past&lt;/a&gt;, i am not a fan of Hibernate and other ORM tools that generate the SQL for me. This week i have yet another reason for not being willing to consider changing my opinion.&lt;/p&gt;  &lt;p&gt;Unbeknownst to me, in our Hibernate application when we were using an “update” to update the one or two columns we change during the regular running of our application, we discovered that actually the update was updating all fields as well as cascading to additional tables joined to this object, which included a CLOB that was getting and update called on it and causing a lot of overhead.&lt;/p&gt;  &lt;p&gt;After being warned by our DBA’s to fix ASAP, our next step was to reproduce the problem in our environment so we quickly turned on the “hibernate.show_sql” property to see our SQL. And before we even got to the issue we were looking to solve, we discovered another perplexing Hibernate-ism. We found that when we were doing an initial load or find by id, we were seeing an update happening to the record at the same time as the find/load!&lt;/p&gt;  &lt;p&gt;After some fishing around the internet, we understood why this was happening. It was because one of out getters was changing the value from null to something more meaningful, as we see &lt;a href="https://forum.hibernate.org/viewtopic.php?t=979630&amp;amp;start=0&amp;amp;postdays=0&amp;amp;postorder=asc&amp;amp;highlight="&gt;here.&lt;/a&gt; When we altered the code to not have this happen, then that update was prevented. &lt;/p&gt;  &lt;p&gt;Now onto the problem we were meant to deal with (isn’t always the case that this happens!). After not seeing the results we were hoping for through setting some of the parameters mentioned in various forums (dynamic-update and select-before-update) in an attempt to have our Hibernate “update” not cascade unnecessarily through all the objects and update them all, we settled on a very iBatis like solution. We created the update ourselves so that we know what we are updating, i.e:&lt;/p&gt;  &lt;p&gt;String hql = "update myTable set field1 = :field1  where id = :id";  &lt;br /&gt;Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);   &lt;br /&gt;query = session.createQuery(hql);   &lt;br /&gt;query.setString("field1", myObj.getField1());   &lt;br /&gt;query.setLong("id",myObj.getId());   &lt;br /&gt;query.executeUpdate();&lt;/p&gt;  &lt;p&gt;Of course, once you are doing this, you have lost the “advantage” of Hibernate.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-441273528346425817?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/441273528346425817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/why-did-hibernate-do-that.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/441273528346425817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/441273528346425817'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/why-did-hibernate-do-that.html' title='Why did Hibernate do that?!'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-2535949160282786590</id><published>2009-11-16T03:26:00.000-08:00</published><updated>2009-11-16T03:31:58.971-08:00</updated><title type='text'>Java Web Start – putting my application out there</title><content type='html'>&lt;p&gt;I recently decided to write a small Java Web Start application using Groovy and Swingbuilder (and HttpBuilder). As i had no experience with Java Web Start, there was a bit of a learning curve. I knew that i would need signed jars in order for my application to be able to write to the local file system. However, a true signing certificate can be very expensive so i realized i would best serve my needs with a self signed certificate that i would keep renewing every 6 months. Using Ant, i have been able to have my app easily deployed with new signed jars.&lt;/p&gt;It is important to mention that there is one simple solution that I did not use for my application, which is to use &lt;a href="http://griffon.codehaus.org/"&gt;Griffon&lt;/a&gt;, as it takes care of all this stuff behind the scenes for you. However, since I had a simple application and had begun before i knew about it, I decided not to go this route and do it myself, which also ensures i have a better understanding of what is going on. Griffon will still be useful to you for reference. I especially found it useful to look over a sample &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html"&gt;jnlp file&lt;/a&gt;, the file used to list dependencies and configuration information&lt;br /&gt;&lt;br /&gt;For signing the jars, i created a self signed certificate. However, every 6 months, i need to renew this certificate, which is pretty straightforward:&lt;br /&gt;&lt;blockquote&gt;keytool -selfcert -keystore keystore -alias myAlias&lt;br /&gt;&lt;/blockquote&gt;After re-creating the certificate, i use ANT to sign and deploy. As Ant has a built in task for this, it is trivial:&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;target&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="signJars"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;description&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="sign the jars"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;depends&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="makeJar"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;mkdir&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="signed"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;mkdir&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="signed/lib"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;        &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;signjar&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;destDir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="signed"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;                  &lt;span style="color: rgb(255, 0, 0);"&gt;alias&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mastertorah"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;keystore&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="keystore"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;                  &lt;span style="color: rgb(255, 0, 0);"&gt;storepass&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="changeit"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;                  &lt;span style="color: rgb(255, 0, 0);"&gt;keypass&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mastertorah"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;                  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;path&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;fileset&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="dist"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;includes&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="**/*.jar"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;path&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;            &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;signjar&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;signjar&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;destDir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="signed"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;                          &lt;span style="color: rgb(255, 0, 0);"&gt;alias&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mastertorah"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;keystore&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="keystore"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;                          &lt;span style="color: rgb(255, 0, 0);"&gt;storepass&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="changeit"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;                          &lt;span style="color: rgb(255, 0, 0);"&gt;keypass&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mastertorah"&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;                          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;path&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;fileset&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="dist"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;includes&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="**/*.jar"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;path&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;            &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21" style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;signjar&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 3pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum22" style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;target&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;In case you are wondering, line 3 above creates a second folder since my signed dependency jars sit separately from the main code; i just left this repeated signing command out of the snippet above.&lt;br /&gt;&lt;br /&gt;As you see, line 4 uses the built in ant task signjar and it references my keystore. So, now i have a simple build process to easily redeploy my application.&lt;br /&gt;&lt;br /&gt;For users reporting problems after deployment, one thing i have found helpful is to tell them to enable debugging, which is set in the control panel on Windows machines (in the java option there). This way they can send you a log of what went wrong.&lt;br /&gt;&lt;br /&gt;I am left with one question. Why should i use SwingBuilder when i can drag and drop widgets using an IDE and get the format of my layout more simply.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-2535949160282786590?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/2535949160282786590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/java-web-start-putting-my-application_16.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2535949160282786590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2535949160282786590'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/11/java-web-start-putting-my-application_16.html' title='Java Web Start – putting my application out there'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-2711874130004217021</id><published>2009-10-28T06:07:00.001-07:00</published><updated>2009-10-28T06:21:57.460-07:00</updated><title type='text'>Setting Version in your manifest using ANT</title><content type='html'>&lt;p&gt;While the &lt;a href="http://gant.codehaus.org/"&gt;Gant&lt;/a&gt; folks will tell you that is not natural to use XML for your makefile as it is nicer to use a real scripting language (and perhaps today’s post will enforce this for you!), it is doable and in my opinion readable. The below is an excerpt of our ant buildfile that we use for upping the manifest version in an interactive way with the the person doing the build.&lt;/p&gt;  &lt;p&gt;We added the &lt;a href="http://ant-contrib.sourceforge.net/tasks/tasks/index.html"&gt;ant-contrib&lt;/a&gt; task in order to enable us to have “if” statements in the XML, so we define the task as follows:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &amp;lt;taskdef resource=&lt;span style="color: rgb(0, 96, 128);"&gt;"net/sf/antcontrib/antlib.xml"&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;    &amp;lt;classpath&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;       &amp;lt;pathelement location=&lt;span style="color: rgb(0, 96, 128);"&gt;"${3rdParty.home}/ant-contrib/ant-contrib-1.0b3.jar"&lt;/span&gt; /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;    &amp;lt;/classpath&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &amp;lt;/taskdef&amp;gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;This will be used below to drive the logic if the user wants to keep the same version of the manifest or change it.&lt;br /&gt;&lt;p&gt;There are two macros that we have defined, loadmanifest – which reads and parses the manifest and createmanifest – which invokes loadmanifest and then interactively decides whether to write a new manifest or not.&lt;br /&gt;&lt;/p&gt;Here is loadmanifest:&lt;br /&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="loadManifest"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="manifest"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;echo&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="about to load file: @{manifest}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;loadfile&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;property&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{manifest}.build.version"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;srcFile&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{manifest}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;filterchain&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;filterreader&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;classname&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="org.apache.tools.ant.filters.LineContains"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;param&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="contains"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Implementation-Version:"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;filterreader&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tokenfilter&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;replacestring&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;from&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Implementation-Version: "&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;to&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=""&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tokenfilter&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;striplinebreaks&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;           &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;filterchain&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;           &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;loadfile&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;On line 5 we use the &lt;a href="http://ant.apache.org/manual/CoreTasks/loadfile.html"&gt;loadfile&lt;/a&gt; task to read the version number into a property that we will display to the user. We then use the very powerful filterchain to get to the correct line and the correct section of the line with the version number. For lack of a better way, we strip away the text part of the line (Implementation-Version:) on line 11,  and are left with just the version number to be stored in the loadfile property @{manifest}.build.version.&lt;br /&gt;&lt;br /&gt;Using this property we can now query the user to determine if the version number suits him or not, and then if necessary put out a new manifest file. This is the macro below:&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;  &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="createManifest"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="manifest"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="jarDescription"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;loadManifest&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;manifest&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{manifest}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;echo&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Current Version: ${@{manifest}.build.version}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Enter new version?"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;validargs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="y,n"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;addproperty&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{jarDescription}.do.newversion"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;equals&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;arg1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="${@{jarDescription}.do.newversion}"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;arg2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="y"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;then&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Please enter new version number"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;addproperty&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{jarDescription}.new.build.version"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;manifest&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;file&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{manifest}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;section&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="${@{jarDescription}.jar.description}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;                             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Implementation-Title"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="${@{jarDescription}.jar.description}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;                             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Implementation-Version"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="${@{jarDescription}.new.build.version}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;section&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;manifest&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;then&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;property&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="@{jarDescription}.new.build.version"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="${@{manifest}.build.version}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21" style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum22" style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum23" style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 5pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum24" style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Other than “if”, the rest are all standard ant tasks that you can look up in the &lt;a href="http://ant.apache.org/manual/coretasklist.html"&gt;manual on the ant site&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The correct thing to do at this point would be to create a parallel GANT site. Unfortunately, i dont have one ready at the moment so this will have to wait until i begin to play with GANT&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-2711874130004217021?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/2711874130004217021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/setting-version-in-your-manifest-using_28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2711874130004217021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2711874130004217021'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/setting-version-in-your-manifest-using_28.html' title='Setting Version in your manifest using ANT'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-5570396317266042501</id><published>2009-10-19T03:13:00.001-07:00</published><updated>2009-10-19T03:22:21.184-07:00</updated><title type='text'>SVN Build automation with ant</title><content type='html'>&lt;p&gt;As i indicated in my last post, we use Ant to create our new scripts. In response to some requests, i am sharing here our “commonbuild.xml” file that shows how we do the key parts of this build in a reusable way. Before you get started you will need to make sure you have late version of ant (1.7 please) and you will need to add some libraries to your ant lib folder. These are the subclipse libraries as well as commons-net if you want to send emails at the end of your build.&lt;/p&gt;  &lt;p&gt;Here is is a snapshot of all new libraries added:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_5g9D1kurEoI/Stw7twIr2HI/AAAAAAAADLM/5lb9Qxo7jEE/s1600-h/antlibs6.jpg"&gt;&lt;img title="antlibs" style="border-width: 0px; display: inline;" alt="antlibs" src="http://lh4.ggpht.com/_5g9D1kurEoI/Stw7vIMjU0I/AAAAAAAADLQ/EyRO4XJrF0A/antlibs_thumb2.jpg?imgmax=800" border="0" height="134" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The first 4 are needed for mail functions and the last 4 are added from svn. I am using svn 1.5 due to the fact that i have not yet updated my Intellij past version 7 so only 1.5 is supported.&lt;/p&gt;  &lt;p&gt;In addition you need to install &lt;a href="http://www.open.collab.net/downloads/subversion.html"&gt;collabnet subversion&lt;/a&gt; client (windows) for this to work.&lt;/p&gt;  &lt;p&gt;For Svn Purposes, we have set up the following task:&lt;/p&gt;  &lt;pre style="border: 1px solid rgb(206, 206, 206); padding: 5px; overflow: auto; min-height: 40px; width: 650px; background-color: rgb(251, 251, 251);"&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  1: &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;taskdef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;resource&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"org/tigris/subversion/svnant/svnantlib.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  2:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;classpath&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  3:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;fileset&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${3rdParty.home}/svnant-1.2.0-RC1/lib"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;includes&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"**/*.jar"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  4:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;classpath&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  5: &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;taskdef&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Using it is pretty straightforward. Below is a macro that we use for commit and tag:&lt;/p&gt;&lt;div class="csharpcode"&gt;&lt;pre style="border: 1px solid rgb(206, 206, 206); padding: 5px; overflow: auto; min-height: 40px; width: 650px; background-color: rgb(251, 251, 251);"&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  1: &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"commitAndTag"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  2:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"commitMessage"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  3:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;attribute&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"tagName"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  4:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  5:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;echo&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"checking in dist folder and manifest versions"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  6:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;svn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  7:                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;commit&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"@{commitMessage}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  8:                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;fileset&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;dir&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${trunk.dir}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  9:                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;include&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"dist/**"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 10:                         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;include&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"**/build/**.txt"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 11:                     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;fileset&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 12:                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;commit&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 13:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;svn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 14:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;svn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 15:                 &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;copy&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;srcUrl&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${svnUrl}/${svn.projectName}/trunk"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;destUrl&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${svnUrl}/${svn.projectName}tags/@{tagName}"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;message&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"@{tagName} tag"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 16:             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;svn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 17:         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;sequential&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(251, 251, 251);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt; 18:     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;macrodef&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And to invoke this macro is simple:&lt;/p&gt;&lt;pre&gt;&lt;pre   style="margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,'Courier New',courier,monospace;font-size:11px;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;commitAndTag&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;commitMessage&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${release.version}"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;tagName&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"${release.version}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;In the next post I hope to show the macro used for editing the manifest file and upping the version number.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-5570396317266042501?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/5570396317266042501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/svn-build-automation-with-ant.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5570396317266042501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5570396317266042501'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/svn-build-automation-with-ant.html' title='SVN Build automation with ant'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_5g9D1kurEoI/Stw7vIMjU0I/AAAAAAAADLQ/EyRO4XJrF0A/s72-c/antlibs_thumb2.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-5790010904054362358</id><published>2009-10-15T02:14:00.001-07:00</published><updated>2009-10-15T02:14:41.812-07:00</updated><title type='text'>Time to become a Maven?</title><content type='html'>&lt;p&gt;I was afraid to post about the fact that we have not moved over all my builds to maven, but i saw that the iBatis team only recently moved. And anyway, last year at a Java conference, the presenter about Maven talked about how only recently had the Maven folks gotten their act together to the point where he was not pulling out his hair over new jars that appeared and changed dependencies happening without his knowing. (I really hate things that happen without my knowing!)&lt;/p&gt;  &lt;p&gt;I will start by saying that all our current projects are happily using Ant. We have built some pretty nice scripts to create a full build that include using svn (&lt;a href="http://subclipse.tigris.org/"&gt;subclipse&lt;/a&gt;) to get the latest version of our code, up the version in the manifest, commit, create a tag, and copy the file to the distribution location. Additionally, the start of a project by our small teams have usually been through a project started in an IDE, (Intellij), and after we have something running, we then take our project and create an ant build, using our existing scripts. So, using maven does not easily fit this model since at this point we already have an existing structure. But everybody is doing it nowadays, so we cant easily dismiss it.&lt;/p&gt;  &lt;p&gt;So, we have done a few projects starting with Maven. And of course, it meant we had to break our methodology described above. We used Maven to create the original infrastructure for the project as well as the project file for Intellij. And, as the project would progress and added more dependencies, it seems that the simplest way to move forward was not to add the dependencies to the project in Intellij, but to fix the POM and then have maven regenerate the project file. I believe this is fixed in the latest version of Intellij where it knows how to sync with the POM.&lt;/p&gt;  &lt;p&gt;So, what are my conclusions?&lt;/p&gt;  &lt;p&gt;First of all, the documentation needs improvement! But, notwithstanding that, I think it makes sense to use Maven to create new projects and this will mean that you will have a simple structure where it is obvious where to put all your additional resources, config files. The alternative would be that we need to keep worrying about these “copy” lines in my ant file.&lt;/p&gt;  &lt;p&gt;But the power of ant to do what you want, and use legacy processes (like our use of JWSDP 1.6) would mean that we still want ant in our build process. Luckily this is possible, as I saw &lt;a href="http://maven.apache.org/guides/mini/guide-using-ant.html"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Of course, Ant will remain a key tool for us as i use it to run apps and more easily build classpaths and pass params to it than alternatives that I know of. And as a big believer in “If it ain’t broke don’t fix it”, i dont see us moving our old applications to Maven.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-5790010904054362358?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/5790010904054362358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/time-to-become-maven.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5790010904054362358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5790010904054362358'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/10/time-to-become-maven.html' title='Time to become a Maven?'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-866513764121298869</id><published>2009-09-09T03:50:00.001-07:00</published><updated>2010-01-27T02:29:27.365-08:00</updated><title type='text'>Test Driving IBATIS 3 (and Spring3)</title><content type='html'>As a big fan and heavy user of &lt;a href="http://ibatis.apache.org/java.cgi"&gt;iBATIS SqlMaps&lt;/a&gt;, i have wanted to give iBATIS version 3 a look for some time, but due to lack of time and limited documentation, I had not gotten around to it. But the beta version is now here, and with it a very detailed and well written &lt;a href="http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/trunk/doc/en/iBATIS-3-User-Guide.pdf"&gt;document&lt;/a&gt;, and I finally had some time between projects, so I figured i could delay no longer. I immediately headed to check the latest version of Spring (3.0M4 as of this post) but i see that there is no built in support for it yet, though there is some JIRA activity on the iBATIS and Spring side trying to make this happen.  &lt;p&gt;The goal of my first encounter with iBATIS 3 was to get a small project up and running, where the iBATIS session would be provided to me by the Spring container. This would give me the datasource and transactions power of Spring even though i would not have the full DataAccessException hierarchy and Runtime Exception changes.  &lt;/p&gt;  &lt;p&gt;As the iBATIS folks recommended, i am using maven to create the project (a tool i have a lot of reservations about), and am followiing their folder structure. In order to do this with Spring 3 M4, i needed to add the following repository to my pom.xml&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &amp;lt;repository&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     &amp;lt;id&amp;gt;spring-releases&amp;lt;/id&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &amp;lt;name&amp;gt;Spring Maven RELEASE Repository&amp;lt;/name&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     &amp;lt;url&amp;gt;http:&lt;span style="color: rgb(0, 128, 0);"&gt;//s3.amazonaws.com/maven.springframework.org/release&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &amp;lt;/repository&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The end result is that my project looks like this:&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_5g9D1kurEoI/S2AVH9wJ9wI/AAAAAAAADkY/4wu6py2hVlw/s1600-h/ibatis.JPG"&gt;&lt;img style="cursor: pointer; width: 296px; height: 320px;" src="http://3.bp.blogspot.com/_5g9D1kurEoI/S2AVH9wJ9wI/AAAAAAAADkY/4wu6py2hVlw/s320/ibatis.JPG" alt="" id="BLOGGER_PHOTO_ID_5431364377188628226" border="0" /&gt;&lt;/a&gt;&lt;p&gt;As recommended in the documentation, I added a new folder within my package structure called “data” where all my configuration files will be stored. These files, are my Spring Application Context (applicationContext.xml), the SqlMapConfig file for Ibatis configuration (minus datasource information), and the Mapper XML file. There is one new file there, an interface with the same name as the SqlMap file. This is a new feature of iBATIS3 that enables type safety. Each mapping will have a function defined in this interface. I may also choose to implement this interface for my dao functions, so the interface could be useful.&lt;/p&gt;&lt;p&gt;Let’s start with the application Context. It seems to me that Spring has come a long way to solve the length of our application context, by enabling the use of annotation in our java code, as well as the shorthand notation in our XML file. So, here is my very simple application Context that contains 2 beans, the datasource and a call to a static method used by iBATIS to read the SqlMapConfig.xml. This file still contains the mapping files as well as global settings, but obviously no datasource settings. Of course, since i will be using JavaConfig, i need to configure the annotation configuration as well. So, here it is&lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &amp;lt;?xml version=&lt;span style="color: rgb(0, 96, 128);"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="color: rgb(0, 96, 128);"&gt;"UTF-8"&lt;/span&gt;?&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &amp;lt;beans xmlns=&lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.springframework.org/schema/beans"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;        xmlns:xsi=&lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;        xmlns:context=&lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.springframework.org/schema/context"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;        xmlns:aop=&lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.springframework.org/schema/aop"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         xmlns:p=&lt;span style="color: rgb(0, 96, 128);"&gt;"http://www.springframework.org/schema/p"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;        xsi:schemaLocation=&lt;span style="color: rgb(0, 96, 128);"&gt;"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;     &amp;lt;context:property-placeholder location=&lt;span style="color: rgb(0, 96, 128);"&gt;"classpath:properties/config.properties"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     &amp;lt;context:annotation-config/&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;     &amp;lt;context:component-scan base-&lt;span style="color: rgb(0, 0, 255);"&gt;package&lt;/span&gt;=&lt;span style="color: rgb(0, 96, 128);"&gt;"com.dr.ibatis3app"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;     &amp;lt;bean id=&lt;span style="color: rgb(0, 96, 128);"&gt;"dataSource"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;           &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;=&lt;span style="color: rgb(0, 96, 128);"&gt;"org.springframework.jdbc.datasource.DriverManagerDataSource"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;                 p:driverClassName=&lt;span style="color: rgb(0, 96, 128);"&gt;"${jdbc.driver}"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;                 p:url=&lt;span style="color: rgb(0, 96, 128);"&gt;"${jdbc.url}"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21" style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;                 p:username=&lt;span style="color: rgb(0, 96, 128);"&gt;"${jdbc.username}"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum22" style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;                 p:password=&lt;span style="color: rgb(0, 96, 128);"&gt;"${jdbc.password}"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum23" style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum24" style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum25" style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;     &amp;lt;bean id=&lt;span style="color: rgb(0, 96, 128);"&gt;"ibatisResourceReader"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;=&lt;span style="color: rgb(0, 96, 128);"&gt;"org.apache.ibatis.io.Resources"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum26" style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt;           factory-method=&lt;span style="color: rgb(0, 96, 128);"&gt;"getResourceAsReader"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum27" style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt;             &amp;lt;constructor-arg value=&lt;span style="color: rgb(0, 96, 128);"&gt;"com/dr/ibatis3app/data/SqlMapConfig.xml"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum28" style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt;     &amp;lt;/bean&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum29" style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum30" style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt; &amp;lt;/beans&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The rest of the beans needed for my project are defined below in the JavaConfig file. The reason is obvious when you see the code: &lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; @Configuration&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; AppConfig {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     @Resource&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     DataSource dataSource;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     @Resource(name=&lt;span style="color: rgb(0, 96, 128);"&gt;"ibatisResourceReader"&lt;/span&gt;)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     Reader sqlMapConfigReader;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     @Bean&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SqlSessionFactory sqlSessionFactoryBuilder() &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; IOException {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         System.out.println(&lt;span style="color: rgb(0, 96, 128);"&gt;"Calling SqlSessionFactoryBuilder build method"&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         SqlSessionFactoryBuilder builder = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SqlSessionFactoryBuilder();&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; builder.build(sqlMapConfigReader);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;     @Bean&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;     @Scope(&lt;span style="color: rgb(0, 96, 128);"&gt;"prototype"&lt;/span&gt;)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SqlSession sqlSession() &lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; DataAccessException {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; sqlSessionFactoryBuilder().openSession(dataSource.getConnection());&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21" style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;         } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (SQLException e) {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum22" style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DataSourceLookupFailureException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Unable to open session"&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum23" style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;         } &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt; (IOException e) {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum24" style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DataSourceLookupFailureException(&lt;span style="color: rgb(0, 96, 128);"&gt;"Error opening sqlconfig"&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum25" style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;         }&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum26" style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum27" style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Rather than using messy method calls in the XML file, i can have a few simple lines of Java that handle the instantiation of the SqlSession, yet the resource file name is injected from the XML file so this is easily changed. The SqlSession is defined as scope prototype as it is not thread safe.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The mapper file is straightforward, with the main change being the required namespace to match the exact location of the interface and XML files. &lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;package&lt;/span&gt; com.dr.ibatis3app.data;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; CardMapper {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; String getPrimAcctNum(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; acctId);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//XML file is below&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; &amp;lt;?xml version=&lt;span style="color: rgb(0, 96, 128);"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="color: rgb(0, 96, 128);"&gt;"UTF-8"&lt;/span&gt; ?&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; &amp;lt;!DOCTYPE mapper&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         PUBLIC &lt;span style="color: rgb(0, 96, 128);"&gt;"-//ibatis.apache.org//DTD Mapper 3.0//EN"&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 96, 128);"&gt;"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; &amp;lt;mapper namespace=&lt;span style="color: rgb(0, 96, 128);"&gt;"com.dr.ibatis3app.data.CardMapper"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     &amp;lt;select id=&lt;span style="color: rgb(0, 96, 128);"&gt;"getPrimAcctNum"&lt;/span&gt; parameterType=&lt;span style="color: rgb(0, 96, 128);"&gt;"int"&lt;/span&gt; resultType=&lt;span style="color: rgb(0, 96, 128);"&gt;"String"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         SELECT prim_acct_num FROM acct WHERE acct_id = #{id}&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     &amp;lt;/select&amp;gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; &amp;lt;/mapper&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;And now we use the code:&lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     ClassPathXmlApplicationContext ctx = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ClassPathXmlApplicationContext(&lt;span style="color: rgb(0, 96, 128);"&gt;"com/dr/ibatis3app/data/applicationContext.xml"&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     SqlSession session = ctx.getBean(&lt;span style="color: rgb(0, 96, 128);"&gt;"sqlSession"&lt;/span&gt;, SqlSession.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         CardMapper mapper = session.getMapper(CardMapper.&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         String  cardNum = mapper.getPrimAcctNum(4185576);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         System.out.println(&lt;span style="color: rgb(0, 96, 128);"&gt;"CARDNUM IS "&lt;/span&gt; + cardNum);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     } &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt; {&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         session.close();&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;And that’s it. We have a working application, and can start to kick the tires a bit.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-866513764121298869?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/866513764121298869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/09/test-driving-ibatis-3-and-spring3.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/866513764121298869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/866513764121298869'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/09/test-driving-ibatis-3-and-spring3.html' title='Test Driving IBATIS 3 (and Spring3)'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_5g9D1kurEoI/S2AVH9wJ9wI/AAAAAAAADkY/4wu6py2hVlw/s72-c/ibatis.JPG' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-1865796153406409357</id><published>2009-08-19T01:32:00.001-07:00</published><updated>2009-08-19T01:32:33.173-07:00</updated><title type='text'>Grails and the Domain Model, or why I prefer IBatis</title><content type='html'>&lt;p&gt;I have spent many hours playing with Grails, to see how much effort it would be to take one of our existing apps and port it to Grails, since, as i have written previously, i prefer not to have to deal too much with GUI, so if Grails gives me a lot automatically, then I would be very happy using it.&lt;/p&gt;  &lt;p&gt;At the same time, i have been using Grails to write a customized version of Quicken for my own personal budgetary needs (unfortunately, it has not progressed as well as i would want due to lack of time).&lt;/p&gt;  &lt;p&gt;I will start with the second project first. As advertised, Grails is an absolutely amazing framework to take an idea and make it functional really fast. Just set up your domain classes and you automatically get a whole web site up and running, from which you can customize the columns and edits. And in the case of my personal app, the domain model is a few tables without any complex joins.&lt;/p&gt;  &lt;p&gt;However, when trying to set up a Grails application on an existing database, this creates a lot of problems. I will start by saying that I am not a big fan of Hibernate either for a similar reason. In most reasonably sized companies, you have a pretty complex database (or set of databases) and in my opinion, it is easier to write queries than to try to “teach” the entire schema to your application. There are solutions like creating views, but then inserts will still be a problem. With Hibernate though, i found it possible with some effort to get around most of the issues. But in Grails, if i want the advantages of the framework, i cannot veer too far from the default domain model. After a lot of frustration trying to make the domain model work with our database, i found the best way to work was to keep tweaking it using the HSQLDB and seeing the scripts generated until they matched. In the end, i opened two&amp;#160; issues that prevented us from moving forward, and both have been addressed, &lt;a href="http://jira.codehaus.org/browse/GRAILS-3616"&gt;3616&lt;/a&gt;, and &lt;a href="http://jira.codehaus.org/browse/GRAILS-4158"&gt;4158.&lt;/a&gt; So, I guess now i am ready to resume. &lt;/p&gt;  &lt;p&gt;But in the end, i still believe that the model IBatis provides is more appropriate for a company application. It means that the developers wears two hats – one of the SQL developer, writing and tweaking queries until they are just what you want and then putting on the programmer hat to use those queries that are mapped within an XML file. I see that IBatis version 3 is out, though every time i have checked i did not see too much documentation about what is different. If you are new to IBatis, I can tell that in version 2, the documentation is great, and it definitely is easy to get up and running with it, especially if you use Spring together with IBatis. And there are many nice advanced features that can take you quite far.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b1271ca8-11ed-4a3d-aeb9-1fe8fc2e4a52" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Grails" rel="tag"&gt;Grails&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IBatis" rel="tag"&gt;IBatis&lt;/a&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-1865796153406409357?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/1865796153406409357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/08/grails-and-domain-model-or-why-i-prefer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1865796153406409357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1865796153406409357'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/08/grails-and-domain-model-or-why-i-prefer.html' title='Grails and the Domain Model, or why I prefer IBatis'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-2084961974393198952</id><published>2009-06-30T06:32:00.001-07:00</published><updated>2009-06-30T06:32:31.111-07:00</updated><title type='text'>Clean Code – Programmers are Authors!</title><content type='html'>&lt;p&gt;I recently read the book &lt;a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882"&gt;Clean Code&lt;/a&gt;, by Robert C, Martin, but I waited to comment on it until i saw how it fundamentally changed how I write code. I see there are quite a few blogs discussing it but i wanted to give &lt;strong&gt;my &lt;/strong&gt;take on it, and specifically, in the short term, as I hope that other aspects will affect me more in the long run as well. (like improving my unit testing!)&lt;/p&gt;  &lt;p&gt;The first powerful principle, laid down at the beginning is that “We are authors” and he develops this point two key ways that I thought i would share:&lt;/p&gt;  &lt;p&gt;1. We read a lot of code.&lt;/p&gt;  &lt;p&gt;Yes, its true. Whether like me, you are now reading others’ code as you have inherited their code, or you need to re-read your own code that you wrote 6 months ago and cannot remember, we are always reading our code. When we write complex code, long functions, etc, even our code takes way too long to remember what it does&lt;/p&gt;  &lt;p&gt;2. Our code is our only reliable way to know what the code does. Comments are unreliable. Yes, its true – i see it in our application. I see that someone from our team changed code and left the now irrelevant comment in place. So, what does that mean? That the only effective and reliable way to document code is to write it in a way that it is readable. (yes, there are needs for comments on a class, but on specific lines of code, no) &lt;/p&gt;  &lt;p&gt;So, how do we do that? Well, go ahead and read the book! But i will start and say – keep the functions short, keep the names of the functions descriptive so that the name of the function itself makes it clear what you will do in the function (and of course, don’t do too much in the function)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-2084961974393198952?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/2084961974393198952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/clean-code-programmers-are-authors.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2084961974393198952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/2084961974393198952'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/clean-code-programmers-are-authors.html' title='Clean Code – Programmers are Authors!'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-1895588066303151441</id><published>2009-06-16T03:39:00.001-07:00</published><updated>2009-06-16T03:44:03.490-07:00</updated><title type='text'>Irregular Expressions</title><content type='html'>&lt;p&gt;A friend sent me the following code that did not work as he expected&lt;br /&gt;&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) {    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;      &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     String str = &lt;span style="color: rgb(0, 96, 128);"&gt;" status=\"The word deleted is in this sentence and no carriage return"&lt;/span&gt;;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     String str1 = &lt;span style="color: rgb(0, 96, 128);"&gt;" status=\"The word deleted is in this sentence and carriage return\n"&lt;/span&gt;;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;      &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; str.matches(&lt;span style="color: rgb(0, 96, 128);"&gt;".*deleted.*"&lt;/span&gt;);    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; str1.matches(&lt;span style="color: rgb(0, 96, 128);"&gt;".*deleted.*"&lt;/span&gt;) : &lt;span style="color: rgb(0, 96, 128);"&gt;"carriage return threw off the regex"&lt;/span&gt;;&lt;!--CRLF--&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;If you run this code you will see that carriage return is not considered “.*” by default. Of course, a little looking around helped us realize that this was documented,&lt;br /&gt; &lt;blockquote&gt;&lt;p&gt;The regular expression &lt;tt&gt;.&lt;/tt&gt; matches any character except a line terminator unless the &lt;a href="http://www.blogger.com/jdk150/api/java/util/regex/Pattern.html#DOTALL"&gt;&lt;code&gt;DOTALL&lt;/code&gt;&lt;/a&gt; flag is specified&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In other words, we need to use the ugly Pattern class in order to make this work, as follows:&lt;br /&gt;&lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; main(String[] args) {    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;      &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;         String str = &lt;span style="color: rgb(0, 96, 128);"&gt;"The word deleted is in this sentence and no carriage return"&lt;/span&gt;;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;         String str1 = &lt;span style="color: rgb(0, 96, 128);"&gt;"The word deleted is in this sentence and carriage return\n"&lt;/span&gt;;&lt;!--CRLF--&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;      &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         Pattern p = Pattern.compile(&lt;span style="color: rgb(0, 96, 128);"&gt;".*deleted.*"&lt;/span&gt;, Pattern.DOTALL);    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         Matcher m = p.matcher(str);    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; m.matches();    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         m = p.matcher(str1);    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; m.matches();    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;      &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;The key to making this work is the parameter Pattern.DOTALL used in the compile.&lt;br /&gt;&lt;p&gt;And how about in Groovy? It works of course!&lt;br /&gt;&lt;/p&gt;&lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; String str = &lt;span style="color: rgb(0, 96, 128);"&gt;" status=\"The word deleted is in this sentence and no carriage return"&lt;/span&gt;;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; String str1 = &lt;span style="color: rgb(0, 96, 128);"&gt;" status=\"The word deleted is in this sentence and carriage return\n"&lt;/span&gt;;&lt;!--CRLF--&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; str =~ /.*deleted.*/    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;assert&lt;/span&gt; str1 =~ /.*deleted.*/&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;As written about extensively, one of the really well done features of Groovy is definitely the regular expression syntax but here we see that the implementation was also improved.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-1895588066303151441?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/1895588066303151441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/irregular-expressions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1895588066303151441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/1895588066303151441'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/irregular-expressions.html' title='Irregular Expressions'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-6843351142628648629</id><published>2009-06-16T03:05:00.001-07:00</published><updated>2009-06-16T03:08:55.967-07:00</updated><title type='text'>Batch loading to the database – Part 2 – SimpleJdbcInsert</title><content type='html'>&lt;p&gt;As mentioned in my &lt;a href="http://groovyjavathoughts.blogspot.com/2009/06/batch-loading-to-database-part-1.html"&gt;last post&lt;/a&gt;, we will now have a a method foe insertion of a delimited file into a database that does not involve our DBA’s.&lt;/p&gt;  &lt;p&gt;In Spring 2.5, the &lt;a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/simple/SimpleJdbcInsert.html"&gt;SimpleJdbcInsert&lt;/a&gt; class was added making this task especially easy, and the added bonus here is we see the elegance of Groovy when combined with this class. &lt;/p&gt;  &lt;p&gt;Here is the code.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; DBInsert {&lt;!--CRLF--&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; DataSource ds;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; SimpleJdbcInsert jdbcInserter;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; numRowsPerBatchInsert = 500;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; numRowsProcessed = 0;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; List fieldNames = [&lt;span style="color: rgb(0, 96, 128);"&gt;'Column1'&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'Column2'&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'Column3'&lt;/span&gt;]   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; List&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; rowsToInsert = [];   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; java.sql.Date today;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;final&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; String SchemaName = &lt;span style="color: rgb(0, 96, 128);"&gt;"myschema"&lt;/span&gt;;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; init() {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;   jdbcInserter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SimpleJdbcInsert(ds).withSchemaName(SchemaName).withTableName(&lt;span style="color: rgb(0, 96, 128);"&gt;"myTable"&lt;/span&gt;);   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;   today = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; java.sql.Date(cal.getTimeInMillis())   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/**&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt; * We assume that the row is delimited by commas.&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt; * This can be refactored to take some other delimiter as second parameter&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt; */&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21" style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; insertRow(String s) {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum22" style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (numRowsProcessed++ &amp;gt; 0) {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum23" style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;     def rowAsList = s.split(&lt;span style="color: rgb(0, 96, 128);"&gt;","&lt;/span&gt;)   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum24" style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum25" style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;     def iterator = rowAsList.iterator()   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum26" style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt;     Map&amp;lt;String, Object&amp;gt; insertMap = [&lt;span style="color: rgb(0, 96, 128);"&gt;'eff_dte'&lt;/span&gt;: today]   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum27" style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt;     fieldNames.collect {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum28" style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt;       insertMap[it] = iterator.next().trim()   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum29" style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt;     }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum30" style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt;     rowsToInsert += insertMap;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum31" style="color: rgb(96, 96, 96);"&gt;  31:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (numRowsProcessed % numRowsPerBatchInsert == 0) {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum32" style="color: rgb(96, 96, 96);"&gt;  32:&lt;/span&gt;       completeInsert();   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum33" style="color: rgb(96, 96, 96);"&gt;  33:&lt;/span&gt;     }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum34" style="color: rgb(96, 96, 96);"&gt;  34:&lt;/span&gt;   }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum35" style="color: rgb(96, 96, 96);"&gt;  35:&lt;/span&gt; }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum36" style="color: rgb(96, 96, 96);"&gt;  36:&lt;/span&gt;     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum37" style="color: rgb(96, 96, 96);"&gt;  37:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; completeInsert() {   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum38" style="color: rgb(96, 96, 96);"&gt;  38:&lt;/span&gt;   jdbcInserter.executeBatch((Map&amp;lt;String, Object&amp;gt;[]) rowsToInsert.toArray());   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum39" style="color: rgb(96, 96, 96);"&gt;  39:&lt;/span&gt;   rowsToInsert.clear();   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum40" style="color: rgb(96, 96, 96);"&gt;  40:&lt;/span&gt; }   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum41" style="color: rgb(96, 96, 96);"&gt;  41:&lt;/span&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Right off the bat, one nice thing we have in groovy is the removal of the need for getters and setters, automatically making the file smaller. But beside that, lines 26-29 have the concise, yet very readable Groovy closure that takes the column names and creates a map between them and values of the specific line. And this little class gives us what we need with barely any parsing and &lt;em&gt;NO&lt;/em&gt; sql.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-6843351142628648629?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/6843351142628648629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/batch-loading-to-database-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6843351142628648629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6843351142628648629'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/batch-loading-to-database-part-2.html' title='Batch loading to the database – Part 2 – SimpleJdbcInsert'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-6121361870803437108</id><published>2009-06-08T01:35:00.001-07:00</published><updated>2009-06-08T01:56:37.042-07:00</updated><title type='text'>Batch loading to the database – Part 1 – External Tables</title><content type='html'>&lt;p&gt;At our company, we have a large amount of data that we load each day to our database. Some of this data can be a few million lines. Since our database is Oracle (11g), there are two very elegant and efficient ways to get this done. The first is via Oracle &lt;a href="http://www.orafaq.com/wiki/SQL*Loader_FAQ"&gt;sqlloader&lt;/a&gt; application, which has many options and configurations to optimize the load. However, we have seen that unless you relax indices on the tables you are loading to, the process can still be quite taxing on the database. &lt;/p&gt;  &lt;p&gt;Another quite elegant method I recently learned about (new as of 10g), is the use of external tables. The data sits as a file on the disk of the Oracle database but is accessible using normal SQL. You can then manipulate and transform this data using an “insert select” to put the data in the correct table which is especially nice if the data requires some transformation before it is in it final format. The simplest example of this is using a CSV file as you see in &lt;a href="http://www.orafaq.com/node/848"&gt;this&lt;/a&gt; example. However, it gets better. You can even user a pure XML File, which may even have headers and footers that you choose to ignore (as we had), all easily set in the CREATE TABLE DML. &lt;/p&gt;  &lt;p&gt;The following example shows how we did this.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div id="codeSnippet"   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum1" style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; CREATE TABLE titan.external_table1&lt;!--CRLF--&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum2" style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     (field1                        VARCHAR2(20),&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum3" style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     field2                         VARCHAR2(20),&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum4" style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     field3                         VARCHAR2(20),&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum5" style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     field4                         VARCHAR2(1),&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum6" style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     description                    VARCHAR2(2000))&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum7" style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;   ORGANIZATION EXTERNAL (&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum8" style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;    DEFAULT DIRECTORY  EXT_TAB_DIR&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum9" style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     ACCESS PARAMETERS(records delimited by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/XMLBEGINTAG&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum10" style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; badfile EXT_TAB_DIR:&lt;span style="color: rgb(0, 96, 128);"&gt;'EXCEPTION.bad'&lt;/span&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum11" style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; logfile EXT_TAB_DIR:&lt;span style="color: rgb(0, 96, 128);"&gt;'EXCEPTION.log'&lt;/span&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum12" style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; fields&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum13" style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; (&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum14" style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; filler &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(2000) terminated by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;XMLBEGINTAG&amp;gt;"&lt;/span&gt;,&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum15" style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; field1 &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(20) enclosed by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;FIELD1&amp;gt;"&lt;/span&gt; and &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/FIELD1&amp;gt;"&lt;/span&gt;,&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum16" style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; field2 &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(20) enclosed by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;FIELD2&amp;gt;"&lt;/span&gt; and &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/FIELD2&amp;gt;"&lt;/span&gt;,&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum17" style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; field3 &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(20) enclosed by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;FIELD3&amp;gt;"&lt;/span&gt; AND &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/FIELD3&amp;gt;"&lt;/span&gt;,&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum18" style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; field4 &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(1) enclosed by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;FIELD4&amp;gt;"&lt;/span&gt; AND &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/FIELD4&amp;gt;"&lt;/span&gt;,&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum19" style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; description &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(2000) enclosed by &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;DESCRIPTION&amp;gt;"&lt;/span&gt; AND &lt;span style="color: rgb(0, 96, 128);"&gt;"&amp;lt;/DESCRIPTION&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum20" style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; )&lt;br /&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span id="lnum21"&gt;  21:&lt;/span&gt; )&lt;br /&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;The syntax you see on Line 7 is what informs Oracle that this is going to be an external table line 8 indicates the name of the oracle directory (see the link above for more about that). Line 14 tells us that everything before the first tag in the file (an XML header) should be considered filler and ignored. And then we define the begin and end tag of each field.&lt;br /&gt;&lt;p&gt;As i started work on another project (not at work, and thus not using Oracle), i saw that the external table feature is even in HSQLDB (the default Grails database). Using this feature, i was able find a simple way to load an encoded CSV file to my database and have all the text appear correctly in my grails application when displaying the data.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The syntax is straightforward and &lt;a href="http://hsqldb.org/doc/guide/ch06.html"&gt;well documented&lt;/a&gt;, and here it is for my example:&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;set TABLE CC_TRANSACTION SOURCE "src/outFile.txt;fs=|;ignore_first=true;encoding=Windows-1255&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span&gt;The line above indicates where the file is, what the delimiter is (|) and the encoding. This table now appears as a regular table in the schema and be used to join or manipulate data for insert elsewhere.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style="color: rgb(0, 0, 0);"&gt;&lt;span&gt;Not all companies are likely to allow access to the Oracle Server filesystem. So, in the next post I hope to discuss an alternative that would work with any database. It also shows the beauty of the groovy syntax together with the ease of use of Spring.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-6121361870803437108?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/6121361870803437108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/batch-loading-to-database-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6121361870803437108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/6121361870803437108'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/batch-loading-to-database-part-1.html' title='Batch loading to the database – Part 1 – External Tables'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-4995531661441404945</id><published>2009-06-02T01:18:00.001-07:00</published><updated>2009-06-02T01:29:45.050-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Commons FtpClient'/><title type='text'>FtpClient – the advantage of open source code</title><content type='html'>&lt;p&gt;Yesterday, it was brought to my attention that one of our apps, whose job is to retrieve files via ftp and process them has not been processing files over the past few days (ok, a bit longer and i should have NOT ignored those emails). A look at the stack trace showed the problem was not in our code (even though we HAD just released new code around the time the problem started, whew!).&lt;/p&gt;  &lt;p&gt;After investigation, we found the problem is that our customer seems to have changed their configuration of their ftp server. If you ever manually ftp somewhere, you see a line that usually looks something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;230 User anonymous logged in.    &lt;br /&gt;Remote system type is &lt;span style="color: rgb(0, 0, 255);"&gt;UNIX&lt;/span&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Well, unfortunately, when we logged in to this customer, the message was a bit different:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;230 User anonymous logged in.    &lt;br /&gt;Remote system type is &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;strong&gt;XXXXXXXXXXXX.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;As it turns out, this line about the remote system type is very important to our ftp library – &lt;a href="http://commons.apache.org/net/"&gt;Jakarta Commons Net’s FtpClient&lt;/a&gt;. A look at the source code based on what the stack trace showed that this string determines the parser to be used and if no matches are found, then it throws a ParserInitializationException. The exact error is:&lt;/p&gt;&lt;p&gt;               &lt;span style="font-style: italic;"&gt;ParserInitializationException: Unknown parser type:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This seems to be the intent of the designer, even though in my opinion if a regular ftp client can access the site, the FtpClient should be able to as well. A bit of looking around on the net did not help, so we set upon a simple and elegant solution.&lt;/p&gt;  &lt;p&gt;We subclassed this class, the DefaultFTPFileEntryParserFactory class and added the following code:&lt;!--CRLF--&gt;&lt;/p&gt;  &lt;div id="codeSnippetWrapper"   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;pre id="codeSnippet"   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; direction: ltr; line-height: 12pt; background-color: rgb(244, 244, 244); text-align: left;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; MyFTPFileEntryParserFactory &lt;span style="color: rgb(0, 0, 255);"&gt;extends&lt;/span&gt; DefaultFTPFileEntryParserFactory&lt;br /&gt;{&lt;br /&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; FTPFileEntryParser createFileEntryParser(String key)&lt;br /&gt;  {&lt;br /&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (key.equals(&lt;span style="color: rgb(0, 96, 128);"&gt;"XXXXXXXXXXXX"&lt;/span&gt;)) {&lt;br /&gt;          key = FTPClientConfig.SYST_UNIX;&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;super&lt;/span&gt;.createFileEntryParser(key);&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;Now, the only issue left was to tell the application to use our parser instead. There are two ways to do this. One is to use listFiles and pass the parser, or in our case it was easier when creating the FtpClient (in Spring of course), to add the setter for the ParserFactory to use our class.&lt;br /&gt;&lt;p&gt;This is a great example of the convenience of using Spring here. All that happens is that you add your new class to the class path and update the application Context!&lt;/p&gt;I will add that this is not the first time we have been bitten by this library. Last February 29 we were hit by &lt;a href="http://issues.apache.org/jira/browse/NET-190"&gt;this&lt;/a&gt; issue.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-4995531661441404945?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/4995531661441404945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/ftpclient-advantage-of-open-source-code.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4995531661441404945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4995531661441404945'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/06/ftpclient-advantage-of-open-source-code.html' title='FtpClient – the advantage of open source code'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-4912532401539550086</id><published>2009-05-20T06:39:00.001-07:00</published><updated>2009-05-20T07:32:46.593-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Observer closure Groovy'/><title type='text'>Observer Pattern using Closures</title><content type='html'>I have been working on a small Swing application. Its purpose is a batch download of various items that you select in the GUI. I only discovered &lt;a href="http://docs.codehaus.org/display/GROOVY/Griffon"&gt;Griffon&lt;/a&gt; after i had already begun and since it is just one screen, i decided to stay away from it for now. So, once i had the UI built (quite painful as it was a first foray into Swing for me, but that is Java's fault and not Groovy. Perhaps more on that in a separate post) and it was time to launch a thread and get updates from the thread to put in the text box in my application. In Java 6 there is a new class, &lt;a href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html#publish%28V...%29"&gt;SwingWorker&lt;/a&gt; to deal with this in an elegant way (see &lt;a href="http://java.sun.com/docs/books/tutorial/uiswing/concurrency/interim.html"&gt;here&lt;/a&gt; for a demo of how to use it). However, with no inner classes in Groovy, this did not seem like it would work. But, in essence the closure has the power of the inner class since it has access to all the members of the class, so this seemed like way to go. And here it is&lt;br /&gt;&lt;br /&gt;So, my worker class has the following:&lt;br /&gt;&lt;br /&gt;private List&lt;closure&gt; closureList = []&lt;br /&gt;&lt;br /&gt;public void addObserver(Closure c) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;    closureList += c&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void removeObserver(Closure c) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;closureList -= c;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void notifyObservers(String fileName, DownloadStatus status) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;for (c in closureList) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;c.call(itemName status)&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;and the GUI class has following closure defined.&lt;br /&gt;&lt;br /&gt;def guiUpdater = {String filename, DownloadStatus status -&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;    swing.edt {&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;              if (status == DownloadStatus.COMPLETE) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;resultsTextArea.append("Download of ${filename} completed\n")&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;                 }&lt;br /&gt;&amp;nbsp; &amp;nbsp;         }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Notice how in my closure i still need to use the swing event dispatch closure for the updates.&lt;br /&gt;&lt;/closure&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-4912532401539550086?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/4912532401539550086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/05/groovy-observer-pattern-using-closures.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4912532401539550086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/4912532401539550086'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/05/groovy-observer-pattern-using-closures.html' title='Observer Pattern using Closures'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3449578868254929667.post-5054015541732258087</id><published>2009-05-19T00:50:00.000-07:00</published><updated>2009-05-19T07:38:30.453-07:00</updated><title type='text'>Let's get started</title><content type='html'>Even though I put a little blurb about the blog on the side, I figured I would still get started with a blog  introduction. As a java programmer over the past few years, I have started dabbling with Groovy (and Grails as well, though less due to my lesser focus on GUI) and have looked for any possible reason to write tools in groovy. That is the reason I added it to the name of the blog as I figure at this point in time, my posts will probably gravitate more to the groovy world, so why not use the double meaning in the name.&lt;br /&gt;&lt;br /&gt;A colleague of mine has commented that documentation of groovy is lacking. I think the problem is that many of the examples are simplistic, and for us java programmers what we are looking to learn is "what is the groovy way of doing things" and the ideas are not easily expanded to a more complex problem. This is further exacerbated by it being a scripting language, so the code complete will usually not provide the answers. Instead you will be looking around to try to figure out "what are the parameters i get in this closure?" or similar issues.&lt;br /&gt;&lt;br /&gt;I find that i actually burn a lot of time on this, so developing in groovy has been slow, as my goal not to see Java code with a .groovy extension. In the end, i am usually quite satisfied with the results and am impressed with the readibility of this more concise code. And of course the next time i need to something it goes MUCH faster and it quite elegant!&lt;br /&gt;&lt;br /&gt;So, i figured i would try to give back and help out with some of what i have done, providing the perspective of a relative newcomer to Groovy.&lt;br /&gt;&lt;br /&gt;Hope you enjoy.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3449578868254929667-5054015541732258087?l=groovyjavathoughts.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://groovyjavathoughts.blogspot.com/feeds/5054015541732258087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/05/lets-get-started.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5054015541732258087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3449578868254929667/posts/default/5054015541732258087'/><link rel='alternate' type='text/html' href='http://groovyjavathoughts.blogspot.com/2009/05/lets-get-started.html' title='Let&apos;s get started'/><author><name>David R</name><uri>http://www.blogger.com/profile/12920751952850890325</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
