<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Along Came Betty</title>
	
	<link>http://blog.darevay.com</link>
	<description>You know, software and some other stuff like maybe guitar or something</description>
	<lastBuildDate>Tue, 31 Aug 2010 03:15:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/darevay" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="darevay" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Scripting JSoar</title>
		<link>http://blog.darevay.com/2010/08/scripting-jsoar/</link>
		<comments>http://blog.darevay.com/2010/08/scripting-jsoar/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 03:15:22 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[soar]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsoar]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=243</guid>
		<description><![CDATA[In simpler times (say 2001) Soar was just Tcl. That is to say, Soar was a module, dynamically loaded into a Tcl interpreter at run-time. When loaded, Soar added a bunch of useful commands to the interpreter. Like run, matches, preferences, and probably most importantly, the sp command. When you &#8220;sourced&#8221; a Soar file, the [...]]]></description>
			<content:encoded><![CDATA[<p>In simpler times (say 2001) Soar was just <a href="http://en.wikipedia.org/wiki/Tcl">Tcl</a>. That is to say, Soar was a module, dynamically loaded into a Tcl interpreter at run-time. When loaded, Soar added a bunch of useful commands to the interpreter. Like <strong>run</strong>, <strong>matches</strong>, <strong>preferences</strong>, and probably most importantly, the <strong>sp</strong> command. When you &#8220;sourced&#8221; a Soar file, the Tcl interpreter just executed commands, loading rules, setting watch levels, etc.</p>
<p>The main drawback to this whole situation was that Tcl didn&#8217;t always lend itself to friendly embedding in other programs. It had funny rules about threads and, if Tk was involved, demanded to have its message queue pumped. And, of course, very few people get to know Tcl enough to like it :)</p>
<p>On the other hand, you could create macros for repetitive Soar structures, define new RHS functions, manipulate I/O. In short, you had the power of a full programming language mixed in with your Soar code.</p>
<p>With Soar 8.6 Soar&#8217;s tight integration with Tcl was broken, replaced by SML and a stricter command interpreter. It still looked like Tcl commands, but there were no Tcl control structures, variables, etc. Way it goes. When I initially started work on JSoar, I needed to quickly bootstrap a command interpreter so I could load existing code into the kernel. I turned to Tcl, in the form of <a href="http://wiki.tcl.tk/1637">Jacl</a>, a Java implementation of Tcl. It saved a lot of time and, since Soar&#8217;s syntax was still basically Tcl, no one would really notice.</p>
<p>Of course, as I mentioned, no one wants Tcl, so over the last couple weeks, I&#8217;ve added a new scripting layer to JSoar. This time, I&#8217;m taking advantage of the <a href="https://scripting.dev.java.net/">Java Scripting API, JSR-223</a>. This allows any scripting language with a JSR-223 implementation to be pretty seamlessly accessed from Java (and vice versa). With this new capability, it&#8217;s now possible to automate Soar agents, implement simple agent environments, and extend SoarUnit testing to include I/O, all from within a Soar source file. All with a variety of languages including Ruby, JavaScript, Python, Clojure, Groovy, etc.</p>
<p>A scripting engine (a language implementation) is invoked with the <strong>script</strong> command:</p>
<pre>script javascript {
   soar.onInput(function(e) {
      soar.wmes.add("my-input", "hello");
   });
   soar.onOutputCommand("say", function(e) {
      soar.print("The agent says: " + e.greeting);
   });
}
</pre>
<p>This little bit of code sets up an input phase callback and creates a WME on the agen&#8217;ts input-link. It also handles an output command called &#8220;say&#8221;. The equivalent Java code would be &#8230; more ceremonious. Not to mention setting up a new project, compiling, etc, etc is a major hassle.</p>
<p>As an example, I&#8217;ve implemented a simple <a href="http://www.binding-time.co.uk/water_jugs.html">waterjugs </a>environment in <a href="http://code.google.com/p/jsoar/source/browse/jsoar-demos/demos/scripting/waterjugs-js.soar">JavaScript</a>, <a href="http://code.google.com/p/jsoar/source/browse/jsoar-demos/demos/scripting/waterjugs-rb.soar">Ruby</a>, and <a href="http://code.google.com/p/jsoar/source/browse/jsoar-demos/demos/scripting/waterjugs-py.soar">Python</a>. Here are some things you can do:</p>
<ul>
<li>Generate input</li>
<li>Handle output commands</li>
<li>Auto-convert hashes (JavaScript objects, Python dicts, or Ruby hashes) to input structures</li>
<li>Install new RHS functions</li>
<li>Add new commands</li>
<li>and on and on</li>
</ul>
<p>Also, with maybe a little more work, I might have a pretty good story for dealing with I/O in <a href="http://blog.darevay.com/2010/08/introducing-soarunit/">SoarUnit tests</a>. Stay tuned.</p>
<p>More detailed info on JSoar scripting support can be found on the <a href="http://code.google.com/p/jsoar/wiki/JSoarScripting">JSoar wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2010/08/scripting-jsoar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing SoarUnit</title>
		<link>http://blog.darevay.com/2010/08/introducing-soarunit/</link>
		<comments>http://blog.darevay.com/2010/08/introducing-soarunit/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 03:01:08 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[soar]]></category>
		<category><![CDATA[99 problems]]></category>
		<category><![CDATA[jsoar]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=228</guid>
		<description><![CDATA[The history of testing in Soar is short and not very happy. This is especially true for automated testing, where the tools have generally been ad hoc, proprietary, and hard to use. I am personally responsible for some of these tools. Despite all this, I&#8217;m foolishly taking another foray into the land of Soar unit [...]]]></description>
			<content:encoded><![CDATA[<p>The history of testing in <a href="http://code.google.com/p/soar/">Soar</a> is short and not very happy. This is especially true for automated testing, where the tools have generally been ad hoc, proprietary, and hard to use. I am personally responsible for some of these tools. Despite all this, I&#8217;m foolishly taking another foray into the land of Soar unit testing. This new effort is called <a href="http://code.google.com/p/jsoar/wiki/SoarUnit">SoarUnit</a> and is part of the <a href="http://code.google.com/p/jsoar/">JSoar</a> suite. However, since the JSoar community is even tinier than the overall Soar community, <strong>I&#8217;ve made sure that SoarUnit is compatible with both Soar implementations</strong>.</p>
<p>(For more complete docs and examples, see the <a href="http://code.google.com/p/jsoar/wiki/SoarUnit">SoarUnit wiki page</a>, and the <a href="http://github.com/daveray/bebot">Bebot source code</a>. There&#8217;s a snapshot (20100801) of JSoar with the latest SoarUnit on the <a href="http://code.google.com/p/jsoar/downloads/list">JSoar downloads page</a>.)</p>
<div id="attachment_236" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.darevay.com/wp-content/uploads/2010/08/soarunit-pass.png"><img class="size-medium wp-image-236" title="soarunit-pass" src="http://blog.darevay.com/wp-content/uploads/2010/08/soarunit-pass-300x262.png" alt="" width="300" height="262" /></a><p class="wp-caption-text">SoarUnit UI</p></div>
<p>The one advantage that this effort may have over previous Soar testing attempts is that I developed it at the same time that I was actively working on Soar code. When I first started working on <a href="http://github.com/daveray/soar99">Soar99</a> and <a href="http://github.com/daveray/bebot">Bebot</a>, my testing strategy was very ad hoc. I had a big Soar file that looks something like this:</p>
<pre>   source "test1.soar"
   run
   excise --all

   source "test2.soar"
   run
   excise --all

   ... and so on ...
</pre>
<p>To run my tests, I&#8217;d just source the file and eyeball the trace for errors, which, if you&#8217;re familiar with Soar, you&#8217;ll know are usually pretty easy to spot. Of course, there were some drawbacks to this approach:</p>
<ul>
<li>Manually checking for success/failure is painful. The <a href="http://www.c2.com/cgi/wiki?GreenBar">&#8220;green bar&#8221;</a> is so much nicer.</li>
<li>To add a single new test, I had to add another three lines to  my &#8220;master test&#8221; file.</li>
<li>There was no way to put more than one test in a file, necessitating either a bunch of duplicate code, or some confusing trickery with the source command.</li>
<li>When a test failed, I had to manually source it to debug.</li>
</ul>
<p>Basically, all the same problems you get when manually testing code in any other language.</p>
<p>So, with 30 or so ad hoc tests already built, I started working on SoarUnit. Here&#8217;s the basic structure of a testcase file:</p>
<pre>setup {
   ... Code run before every test. Here you can source code under test,
       setup test data, propose initialization opreators, etc ...
}

test "name of test" {
   ... Code for an individual test. Here you put any code
       you need for the test. When the test's success condition's
       have been detected, a rule should call the <strong>(pass)</strong> RHS function.
       Similarly, there's a <strong>(fail)</strong> RHS function for detecting failures ...
}

... More tests ...
</pre>
<p>Nice and simple.</p>
<p>I think the existing tests were key to how well development has gone. Every previous attempt I&#8217;ve made for testing Soar code has been based on imagining how someone might use such a framework, without any real-world requirements to build from. Although I&#8217;ve only been working on it a little more than a week, SoarUnit already has:</p>
<ul>
<li>Test case discovery by file name pattern</li>
<li>Multiple tests per file</li>
<li>Setup blocks to handle code shared by multiple tests</li>
<li>A graphical interface similar to Eclipse&#8217;s JUnit view (see below)</li>
<li>Single-click debugging from the user interface</li>
<li>Support for both <a href="http://code.google.com/p/jsoar/">JSoar</a> and <a href="http://code.google.com/p/soar/">CSoar 9.3.0</a> (CSoar requires that a SOAR_HOME environment variable be set so it can find native libraries and stuff)</li>
<li>Basic code coverage reporting</li>
</ul>
<p>Best of all, I&#8217;ve used it <strong>a lot</strong> on <a href="http://github.com/daveray/bebot">Bebot</a> and <a href="http://github.com/daveray/soar99">Soar99</a> and it&#8217;s honestly really nice. I did a major refactoring, basically renaming all of the major data structures and operators in the library, and it was a breeze. I guess that&#8217;s the point of having tests&#8230;</p>
<h2>What&#8217;s Next?</h2>
<p>I&#8217;m going to keep working on SoarUnit to support my own Soar development. There are still some obvious holes and open questions.</p>
<p>One area that&#8217;s always plagued talk of testing Soar code is I/O. How do you test an agent independent of the environment it will run in. I&#8217;m currently of the mind that, like unit testing in every other language, this is where mocking comes in. With a few rules, an agent can easily simulate static structures on the input-link to driver tests. If things get too complicated, one option is simple integration with <a href="http://soar.googlecode.com/svn-history/r11619/trunk/SoarSuite/Soar2Soar/readme.txt">soar2soar</a>, where for each test, a helper agent would be created to simulate the environment. There are other options as well (plugins, external processes, etc), but none of them maintains the simplicity I want for SoarUnit. For every configuration parameter, you lose a user and with Soar there aren&#8217;t that many to start with.</p>
<p>The other open question is whether SoarUnit is effective for testing idiomatic Soar code. Soar has very little encapsulation or modularity which can make it difficult to isolate code for testing. The problems I&#8217;m solving with Bebot are very procedural, so they&#8217;re easy to test, but I&#8217;m not sure that&#8217;s true for most Soar code. I&#8217;d like to work through creating tests for some of the <a href="http://sitemaker.umich.edu/soar/getting_started">Soar tutorial</a> problems and see how it goes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2010/08/introducing-soarunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can anything I write here help open source?</title>
		<link>http://blog.darevay.com/2009/11/can-anything-i-write-here-help-open-source/</link>
		<comments>http://blog.darevay.com/2009/11/can-anything-i-write-here-help-open-source/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 03:21:41 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=223</guid>
		<description><![CDATA[I spend a lot of my time working with open source software and I like to think that I&#8217;ve picked up a number of the tricks, gotchas, and other secrets of these systems.  So, whenever I think of posting to this blog, it usually along the lines of &#8220;man, I just spent a day figuring [...]]]></description>
			<content:encoded><![CDATA[<p>I spend a lot of my time working with open source software and I like to think that I&#8217;ve picked up a number of the tricks, gotchas, and other secrets of these systems.  So, whenever I think of posting to this blog, it usually along the lines of &#8220;man, I just spent a day figuring out X. I should document that for the next poor sap that comes along.&#8221; Invariably, I don&#8217;t. Occasionally this is due to time constraints, but more often it&#8217;s because there&#8217;s already a wiki or something for whatever I&#8217;m dealing with and I believe that keeping related information in one place is a good idea. So, I don&#8217;t write it here, or there.</p>
<p>Unfortunately, writing open source documentation isn&#8217;t as fun as coding or as gratifying as blog traffic* so there&#8217;s a pretty good chance the open source knowledge diaspora will continue. Important, headache preventing, technical information will remain in change logs, mailing lists, and random blog posts while user guides and other documentation will be ignored or buried**.</p>
<p><a href="http://stackoverflow.com">Stack Overflow</a> is helping a bit, but it would be nice if some of the best answers there were pulled back into (or at least linked to from) the how-tos and getting started guides of the projects they concern.</p>
<p>I, for my part, am going to start writing this stuff down. Where it belongs.</p>
<p>* yes, I recognize the irony here.<br />
** many open source projects could do a hell of a lot better job at making documentation easier to find.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/11/can-anything-i-write-here-help-open-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using rails.vim with JRuby</title>
		<link>http://blog.darevay.com/2009/07/using-rails-vim-with-jruby/</link>
		<comments>http://blog.darevay.com/2009/07/using-rails-vim-with-jruby/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 02:45:15 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=220</guid>
		<description><![CDATA[I spent this evening fiddling around with rails.vim and JRuby.  I have some Java code that I&#8217;d like to use with Rails, so I&#8217;m using JRuby (also, JRuby seems to hate Windows slightly less than MRI).  Anyway, this is really about using vim to edit Rails code. I installed rails.vim and found that it was [...]]]></description>
			<content:encoded><![CDATA[<p>I spent this evening fiddling around with <a href="http://www.vim.org/scripts/script.php?script_id=1567">rails.vim</a> and <a href="http://jruby.org">JRuby</a>.  I have some <a href="http://jsoar.googlecode.com">Java code</a> that I&#8217;d like to use with Rails, so I&#8217;m using JRuby (also, JRuby seems to hate Windows slightly less than MRI).  Anyway, this is really about using vim to edit Rails code. I installed rails.vim and found that it was hard-coded to use plain old Ruby. Assuming that <strong>jruby.bat</strong> (or jruby, I guess) is on your system path, all you need to do is modify the <strong>app_ruby_shell_command </strong>in <strong>autoload/rails.vim</strong> like this:</p>
<pre>function! s:app_ruby_shell_command(cmd) dict abort
  if self.path() =~ '://'
    return "jruby.bat ".a:cmd
  else
    return "jruby.bat -C ".s:rquote(self.path())." -S ".a:cmd
  endif
endfunction</pre>
<p>Basically, just change &#8220;ruby&#8221; to &#8220;jruby.bat&#8221; and add the <strong>-S</strong> parameter.</p>
<p>The <strong>-S</strong> flag is important. Otherwise, it seems JRuby&#8217;s implementation of the <strong>-C</strong> flag is a <a href="http://jira.codehaus.org/browse/JRUBY-3621">little buggy</a>. For example, almost any <strong>script/</strong> command will fail:</p>
<pre>&gt;jruby -C c:\path\to\rails\app script/generate
C:/Program Files/jruby-1.3.1/bin/../lib/ruby/1.8/pathname.rb:711:in `relative_path_from':
        different prefix: "C:/" and "C:\\path/to/rails/app" (ArgumentError)
        from C:/Program Files/jruby-1.3.1/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/rails_generator/lookup.rb:110:in
        `use_component_sources!'</pre>
<p>Everything seems to be working well now. Yay.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">app_ruby_shell_command</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/07/using-rails-vim-with-jruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>99 Prolog Problems in Ruby</title>
		<link>http://blog.darevay.com/2009/04/99-prolog-problems-in-ruby/</link>
		<comments>http://blog.darevay.com/2009/04/99-prolog-problems-in-ruby/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 01:24:54 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[99 problems]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=215</guid>
		<description><![CDATA[I spent the weekend on the shores of Lake Huron. During the kids&#8217; naps, I worked through the first 28 problems of P-99: Ninety-Nine Prolog Problems in Ruby. Many have done it before me (in many languages and variations). Many will do it after.
So far P27 gave me the most trouble because I refused to [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the weekend on the shores of Lake Huron. During the kids&#8217; naps, I worked through the first 28 problems of <a href="https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/">P-99: Ninety-Nine Prolog Problems</a> in Ruby. Many have done it before me (in many languages and variations). Many will do it after.</p>
<p>So far P27 gave me the most trouble because I refused to use my brain. Figured it out on a nice long walk with the family. P28 was a pain because I was figuring out how Ruby blocks/procs work. <a href="http://github.com/daveray/ruby99/tree/master">Here&#8217;s</a> the code.</p>
<p>p.s. an immutable list,<a href="http://www.scala-lang.org/docu/files/api/scala/List.html"> like in Scala</a> (or Lisp, etc, etc), with pattern matching of course, would be handy in Ruby. I wonder if one exists&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/04/99-prolog-problems-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ten Little Soul Crushing Features of Java</title>
		<link>http://blog.darevay.com/2009/04/ten-little-soul-crushing-features-of-java/</link>
		<comments>http://blog.darevay.com/2009/04/ten-little-soul-crushing-features-of-java/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 03:04:23 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=205</guid>
		<description><![CDATA[There are a lot of big things (lack of closures, type inference, etc, etc) to dislike about Java. This is a list, in no particular order of little things that make day to day Java development just that much more irritating. Most of these are just convenience methods whose omission is unforgivable. Libraries exist to [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of big things (lack of closures, type inference, etc, etc) to dislike about Java. This is a list, in no particular order of little things that make day to day Java development just that much more irritating. Most of these are just convenience methods whose omission is unforgivable. Libraries exist to address all of them, but that&#8217;s beside the point.</p>
<p><strong>1) No string join method</strong></p>
<p>How many times have I written this?</p>
<p><strong>2) No way to set additional JVM parameters in manifest of executable jar</strong></p>
<p>It&#8217;s really convenient to just double-click a jar &#8230; until you need to set your heap size or something and you have to go crawling back to a shell script.</p>
<p><strong>3) java.net.URL constructor throws checked MalformedURLException rather than unchecked IllegalArgumentException</strong></p>
<p>Seriously, what is so special about this exception?</p>
<p><strong>4) java.io.File has no getExtension() method</strong></p>
<p>Same as join() above.</p>
<p><strong>5) No immutable collections.  Collections.unmodifiableList() and friends don&#8217;t count</strong></p>
<p><strong>6) java.io.File.delete() silently does nothing if you try to delete a non-empty directory</strong></p>
<p>It&#8217;s even more irritating to write deleteFolder() than join() and getExtension().</p>
<p><strong>7) java.util.Random has a setSeed() method, but no getSeed() method</strong></p>
<p><strong>8) java.util.logging is built-in and incredibly lame</strong></p>
<p>They sucked every ounce of the joy out of log4j.</p>
<p><strong>9) JTree selection behavior gives me a headache every time I have to deal with it</strong></p>
<p><strong>10) No method to just read an entire InputStream or Reader into a byte array or string</strong></p>
<p>Same as join() above.</p>
<p><strong>Bonus) No method to copy a file!</strong></p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/04/ten-little-soul-crushing-features-of-java/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Importing Multiple WSDLs with Maven</title>
		<link>http://blog.darevay.com/2009/03/importing-multiple-wsdls-with-maven/</link>
		<comments>http://blog.darevay.com/2009/03/importing-multiple-wsdls-with-maven/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 01:40:14 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=198</guid>
		<description><![CDATA[The jax-ws-maven plugin for Maven includes  the handy wsimport goal. This goal will take a WSDL from a URL or file and generate Java bindings for the service described.  The generated code may not be beautiful, but it works. Anyway, today I spent more than an hour fiddling with wsimport. In my case I was [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="https://jax-ws-commons.dev.java.net/jaxws-maven-plugin/"><strong>jax-ws-maven</strong></a> plugin for <a href="http://maven.apache.org/">Maven </a>includes  the handy <strong>wsimport</strong> goal. This goal will take a WSDL from a URL or file and generate Java bindings for the service described.  The generated code may not be beautiful, but it works. Anyway, today I spent more than an hour fiddling with wsimport. In my case I was trying to import multiple WSDLs into my project with different target packages. I ran into several hurdles and figured that I&#8217;d document them here for future victims.</p>
<p>First, for better or worse, I&#8217;m working in <a href="http://www.netbeans.org/">NetBeans</a>.  The Maven support is passable, but out of the box, the error reporting leaves <strong>a lot</strong> to be desired. In particular, detailed error reporting must be enabled. Otherwise, when there&#8217;s an error in your pom.xml file, you&#8217;ll get a nice <strong>&lt;Badly formed Maven project&gt;</strong> error with no other explanation. To enable error reporting go to <strong>Tools-&gt;Options-&gt;Miscellaneous-&gt;Maven</strong>, and check &#8220;Produce Exception Error Messages&#8221;. That will make your life easier. Now, about wsimport&#8230;</p>
<p>The obvious way to import multiple WSDLs is to include multiple executions in the jaxws-maven-plugin section of pom.xml. In fact, this is even the right way to do it&#8230; but if you just take your single-WSDL example, stolen from <a href="http://java.sun.com/mailers/techtips/enterprise/2008/TechTips_Jan08.html">some tutorial </a>somewhere, and copy it, you&#8217;ll end up with a couple of problems. First, when multiple execution are present, they must each be given a unique id, using of all things, the &lt;id&gt; tag.  This wasn&#8217;t that tough to figure out once I turned on error reporting as described above.</p>
<p>The second issue was more problematic and, in my opinion, probably a bug in the plugin. Each execution includes a &#8220;staleFile&#8221; which is used to manage dependencies, i.e. correctly recompiling WSDL when it changes. However, it happens that when multiple executions are present they <strong>use the same staleFile</strong>.  This means that the import of the second WSDL always thinks it&#8217;s up to date and thus never runs.  After a bunch of googling, I managed to find a solution in this <a href="http://java.sun.com/mailers/techtips/enterprise/2008/TechTips_Jan08.html">bug report</a>. So, the solution is to manually set a staleFile for each WSDL. Here&#8217;s the resulting &lt;plugin&gt; block from pom.xml:</p>
<pre>&lt;plugin&gt;
   &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
   &lt;artifactId&gt;jaxws-maven-plugin&lt;/artifactId&gt;
   &lt;executions&gt;
      &lt;execution&gt;
         &lt;id&gt;FirstWsdl&lt;/id&gt;
         &lt;goals&gt;
            &lt;goal&gt;wsimport&lt;/goal&gt;
         &lt;/goals&gt;
         &lt;configuration&gt;
            &lt;wsdlLocation&gt;http://localhost:8080/FirstWsdl?wsdl&lt;/wsdlLocation&gt;
            &lt;wsdlFiles&gt;
            &lt;wsdlFile&gt;path/to/FirstWsdl.wsdl&lt;/wsdlFile&gt;
            &lt;/wsdlFiles&gt;
            &lt;packageName&gt;com.example.first&lt;/packageName&gt;
            &lt;!-- Without this, multiple WSDLs won't be processed :( --&gt;
            &lt;staleFile&gt;${project.build.directory}/jaxws/stale/wsdl.FirstWsdl.done&lt;/staleFile&gt;
         &lt;/configuration&gt;
      &lt;/execution&gt;
      &lt;execution&gt;
         &lt;id&gt;SecondWsdl&lt;/id&gt;
         &lt;goals&gt;
            &lt;goal&gt;wsimport&lt;/goal&gt;
         &lt;/goals&gt;
         &lt;configuration&gt;
            &lt;wsdlLocation&gt;http://localhost:8080/SecondWsdl?wsdl&lt;/wsdlLocation&gt;
            &lt;wsdlFiles&gt;
            &lt;wsdlFile&gt;path/to/SecondWsdl.wsdl&lt;/wsdlFile&gt;
            &lt;/wsdlFiles&gt;
            &lt;packageName&gt;com.example.second&lt;/packageName&gt;
            &lt;!-- Without this, multiple WSDLs won't be processed :( --&gt;
            &lt;staleFile&gt;${project.build.directory}/jaxws/stale/wsdl.SecondWsdl.done&lt;/staleFile&gt;
         &lt;/configuration&gt;
      &lt;/execution&gt;
   &lt;/executions&gt;
&lt;/plugin&gt;</pre>
<p>That&#8217;s it. Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/03/importing-multiple-wsdls-with-maven/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Ruby Way: Chapter 1 … bipolar</title>
		<link>http://blog.darevay.com/2009/01/the-ruby-way-chapter-1-bipolar/</link>
		<comments>http://blog.darevay.com/2009/01/the-ruby-way-chapter-1-bipolar/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 03:46:59 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=189</guid>
		<description><![CDATA[I just finished chapter 1 of &#8220;The Ruby Way&#8221; by Hal Fulton.  I feel a little torn because it is simultaneously one of the worst chapters I have read, and also one of my favorites.  I&#8217;ll start with the bad.
The editing is pretty bad. I came across a number of typos which make me wonder [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished chapter 1 of <a href="http://www.amazon.com/Ruby-Way-Second-Addison-Wesley-Professional/dp/0672328844">&#8220;The Ruby Way&#8221;</a> by Hal Fulton.  I feel a little torn because it is simultaneously one of the worst chapters I have read, and also one of my favorites.  I&#8217;ll start with the bad.</p>
<p>The editing is pretty bad. I came across a number of typos which make me wonder if anyone actually read it before going to print. On top of that, this is some seriously sloppy technical writing (kind of like this blog). New or alternative terms are introduced without note, examples are only explained by cryptic, embedded comments, and seemingly complex concepts are given no examples at all.</p>
<p>The one statement that stuck out for me was on page 5 where the author describes the <em>is-a</em> relationship:</p>
<blockquote><p>The relationship between a class and its superclass is interesting and important; it is usually described as the <em>is-a</em> relationship, because a Square &#8220;is a&#8221; Rectangle, and a Rectangle &#8220;is a&#8221; Polygon, and so on.</p></blockquote>
<p>Ummm, please tell me that your first example of a class hierarchy isn&#8217;t one that if not just wrong is at least <a href="http://groups.google.com/groups/search?hl=en&amp;ie=UTF-8&amp;q=is+a+square+a+rectangle+oop&amp;btnG=Search&amp;sitesearch=groups.google.com">highly controversial</a>.  You couldn&#8217;t have started with <a href="http://www.google.com/search?hl=en&amp;q=person+employee+oop&amp;btnG=Search">Person and Employee</a>?</p>
<p>Hal Fulton calls this chapter &#8220;our review of object-oriented programming and our whirlwind tour of the Ruby language&#8221; so besides the typos and sloppiness, I&#8217;ll give him a break. That&#8217;s really a lot to jam into one chapter of a book whose intended audience is assumed to basically know all that stuff.</p>
<p>It&#8217;s like a <a href="http://en.wikipedia.org/wiki/Man_page">man page</a>. It all makes perfect sense if you already know it.</p>
<p>So as my hesitation grew, I reached section 1.5, &#8220;Training Your Intuition: Things to Remember&#8221;. This is where, in my opinion, the author turns everything around. This is one of my favorite sections of a technical book I&#8217;ve read in a long time. It&#8217;s basically a somewhat random laundry list of Ruby idioms, gotchas, and nuggets of general wisdom. It reminds me of the best stuff you find in a FAQ when learning a new language. It reminds me of the lists I write for colleagues when I have to bring them up to speed on a new technology. It reminds me of how I felt the first time I read <a href="http://www.amazon.com/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0201924889">Effective C++</a> when I was too young and foolish to recognize that for the <a href="http://blog.oup.com/2009/01/oxymoron/">oxymoron</a> it was.  It&#8217;s all the stuff that you wish that a language manual would come out and tell you right away, but is completely missing or at least hidden between simplistic examples.</p>
<p>Great stuff. Anyway, at least he ended on a high note. Flipping through the rest of the recipe-style chapters of the book, I&#8217;m pretty confident I&#8217;ll find it invaluable specifically because it continues that laundry list style that for some reason appeals to me so much.</p>
<p>p.s. my <a href="http://blog.darevay.com/category/scala/">&#8220;learning scala&#8221;</a> project was a simple <a href="http://rooscaloo.googlecode.com">rules engine</a>. For Ruby, I&#8217;m planning on a <a href="http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm">tcl interpreter</a>. Hopefully, I can do it in less than <a href="http://antirez.com/page/picol.html">550 lines</a>. Combining the speed of Ruby with the speed and expressiveness of Tcl &#8230; good times.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/01/the-ruby-way-chapter-1-bipolar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remedial Scala: Interpreting Scala from Scala</title>
		<link>http://blog.darevay.com/2009/01/remedial-scala-interpreting-scala-from-scala/</link>
		<comments>http://blog.darevay.com/2009/01/remedial-scala-interpreting-scala-from-scala/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 16:17:56 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=183</guid>
		<description><![CDATA[For my &#8220;learning Scala&#8221; project, rooscaloo, I needed to dynamically generate and compile Scala code as rules are loaded into the engine. I had initially intended to do this as an internal DSL, but I honestly couldn&#8217;t think of a way to handle the fact that variables are bound at match time in the rete [...]]]></description>
			<content:encoded><![CDATA[<p>For my &#8220;learning Scala&#8221; project, <a href="http://rooscaloo.googlecode.com">rooscaloo</a>, I needed to dynamically generate and compile Scala code as rules are loaded into the engine. I had initially intended to do this as an<a href="http://debasishg.blogspot.com/2008/05/designing-internal-dsls-in-scala.html"> internal DSL</a>, but I honestly couldn&#8217;t think of a way to handle the fact that variables are bound at match time in the rete network. This is a learning project anyway, so I decided to just generate code and compile it.  Now, I could have sworn I had seen a Scala scripting example using <a href="http://jcp.org/en/jsr/detail?id=223">JSR-223</a> in a blog somewhere, but couldn&#8217;t find it again.  I only found one very basic example of how to do this, in the <a href="http://lampsvn.epfl.ch/trac/scala/ticket/874">Scala bug tracker</a>. So I figured I&#8217;d write down what I came up with.</p>
<p><em>Note that this code makes use of the <strong>scala.tools.nsc</strong> package which is not part of the standard Scala library. Thus, it may change in future versions of Scala. Also note that after the fact, I was able to track down two partial JSR-223 implementations <a href="http://ifcx.svn.sourceforge.net/viewvc/ifcx/thirdparty/scripting/engines/scala/src/org/ifcx/scripting/scala/ScalaScriptEngine.java?revision=91&amp;view=markup">here</a> and <a href="http://code.google.com/p/netgents/source/browse/trunk/scala-scripting/src/com/netgents/script/scala/ScalaScriptEngine.scala">here</a>. It&#8217;s comforting that I ended up in basically the same place.</em></p>
<p>The example given in the bug tracker works, but it&#8217;s very simple and there are two things it doesn&#8217;t do. First, it prints all its output to stdout, including error information. Second, it doesn&#8217;t show how to retrieve results from executing scripts. That is, code goes in, but nothing comes out. These are both solved pretty easily.  In the first case, we simply supply our own PrintWriter when instantiating the internal Scala interpreter:</p>
<pre>  private val writer = new java.io.StringWriter()
  private val interpreter = new ScalaInterpreter(new Settings(),
                                                 <strong>new PrintWriter(writer)</strong>);

  ...

  def exec(code : String) {
    // Clear the previous output buffer
    writer.getBuffer.setLength(0)

    // Execute the code and catch the result
    val ir = interpreter.interpret(code);

    // Return value or throw an exception based on result
    ir match {
      case Success =&gt; ()
      case Error =&gt; throw new ScriptException("error in: '" +
                                              code + "'\n" + writer toString)
      case Incomplete =&gt; throw new ScriptException("incomplete in :'" +
                                                   code + "'\n" + writer toString)
    }
  }</pre>
<p>For the second issue, returning results, I had to think a little longer, probably longer than necessary. <strong>scala.tools.nsc.Interpreter</strong> doesn&#8217;t return anything besides Success, Error, or Incomplete as seen above. But, you can pass objects in, so I ended up creating a container object to hold the result:</p>
<pre><strong>class ResultHolder(var value : Any)</strong>

  ...

  def eval(code : String) : Any = {
    // Clear the previous output buffer
    writer.getBuffer.setLength(0)

    // Create an object to hold the result and bind in the interpreter
    <strong>val holder = new ResultHolder(null)
    bind("$result__", holder);
</strong>
    // Execute the code and catch the result
    val ir = interpreter.interpret(<strong>"$result__.value = " + code</strong>);

    // Return value or throw an exception based on result
    ir match {
      case Success =&gt; <strong>holder.value</strong>
      case Error =&gt; throw new ScriptException("error in: '" +
                                              code + "'\n" + writer toString)
      case Incomplete =&gt; throw new ScriptException("incomplete in :'" +
                                                   code + "'\n" + writer toString)
    }
  }</pre>
<p>As you can see, I ended up with two separate routines. <strong>exec</strong> executes a Scala statement, ignoring its return value. This is useful for <strong>import</strong>s, class declarations, anything that does not evaluate to a value.  <strong>eval</strong> executes a Scala statement, catches the result and returns it.</p>
<p>Anyway, that&#8217;s about it. It seems that full JSR-223 support is in the plan for Scala. Until then, what I have here works for me and it was a good learning experience. <a href="http://code.google.com/p/rooscaloo/source/browse/trunk/rooscaloo/src/org/darevay/rooscaloo/Interpreter.scala">Here&#8217;s</a> the full source for my solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/01/remedial-scala-interpreting-scala-from-scala/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remedial Scala: XML</title>
		<link>http://blog.darevay.com/2009/01/remedial-scala-xml/</link>
		<comments>http://blog.darevay.com/2009/01/remedial-scala-xml/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 04:20:29 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.darevay.com/?p=175</guid>
		<description><![CDATA[Tonight I finally got to the XML chapter of Programming in Scala. I was excited because I had seen a few examples on the web and wanted to try something out that wasn&#8217;t jdom or jax-b or whatever. So, I read the chapter and it was &#8230; short. The authors even admit in the conclusion [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I finally got to the XML chapter of <a href="http://www.artima.com/shop/programming_in_scala">Programming in Scala</a>. I was excited because I had seen a few examples on the web and wanted to try something out that wasn&#8217;t jdom or jax-b or whatever. So, I read the chapter and it was &#8230; short. The authors even admit in the conclusion that it barely scratches the surface and I have to agree :)</p>
<p>Anyway, my exercise for Scala&#8217;s XML support was adding an XML encoding of rules to <a href="http://rooscaloo.googlecode.com">rooscaloo</a>. My plan is to eventually write a parser with parser combinators, but that&#8217;s not until chapter 31.</p>
<p>Overall, Scala&#8217;s XML support is a dream compared to anything I&#8217;ve done in Java before. I began by creating some case classes for my AST:</p>
<pre>  case class RuleAST(name : String,
                     fireCode : String, unfireCode : String,
                     conditions : ConditionAST*)

  case class ConditionAST

  case class ObjectConditionAST(typeName : String,
                                binding : String,
                                testCode : String) extends ConditionAST

  case class NotAST(children : ConditionAST*) extends ConditionAST</pre>
<p>really simple stuff.  Here&#8217;s what a rule looks like in XML:</p>
<pre>    &lt;rule name="bob-is-not-a-cat-lover"&gt;
      &lt;if&gt;
        &lt;object type="Person" binding="p"&gt; p.name == "bob" &lt;/object&gt;
        &lt;not&gt;
            &lt;object type="Cat" binding="c"&gt; c.owner == p &lt;/object&gt;
        &lt;/not&gt;
      &lt;/if&gt;
      &lt;then&gt;println("bob does not fancy cats")&lt;/then&gt;
      &lt;unfire&gt;Tprintln("bob now owns a cat!")&lt;/unfire&gt;
    &lt;/rule&gt;</pre>
<p><em>(I couldn&#8217;t think of a better name for rule retraction than unfire&#8230;)</em></p>
<p>and here&#8217;s the satisfyingly compact code to convert an XML node to a RuleAST object:</p>
<pre>  def parseRule(node: scala.xml.Node) : RuleAST =
    RuleAST(node \ "@name" text,
            node \ "then" text,
            node \ "unfire" text,
            parseConditionList(node \ "if" \ "_") : _*)

  def parseConditionList(xml : scala.xml.NodeSeq) : Seq[ConditionAST] =
    for(e &lt;- xml)
      yield e match {
        case &lt;object&gt;{ _* }&lt;/object&gt; =&gt; parseObjectCondition(e)
        case &lt;not&gt;{ _* }&lt;/not&gt; =&gt; parseNot(e)
      }

  def parseObjectCondition(xml : scala.xml.Node) : ObjectConditionAST =
    ObjectConditionAST(xml \ "@type" text, xml \ "@binding" text, xml.text)

  def parseNot(xml : scala.xml.Node) : NotAST =
    NotAST(parseConditionList(xml \ "_") : _*)</pre>
<p>This could actually be much more compact but I chose to break it up into methods so I could test each construct individually. Still, I&#8217;m fairly certain there&#8217;s an even better way to do this, but this represents 45 minutes of work including unit tests, so I&#8217;m still pretty happy. One thing I discovered that wasn&#8217;t covered in the book was the use of the <strong>&#8220;_&#8221;</strong> wildcard to get all sub-elements of a node. For example we can see above that I use:</p>
<pre>   node \ "if" \ "_"</pre>
<p>to get the list of all child elements of the <strong>&lt;if&gt;</strong> node.</p>
<p>The <strong>match</strong> statement in <strong>parseConditionList</strong> is a little irritating to me and I feel like there&#8217;s probably a better way to do that.</p>
<p>Just like the book, I&#8217;ve obviously only started to scratch the surface of  Scala&#8217;s XML support. Since I also just read the chapter on <a href="http://www.scala-lang.org/node/112">extractors</a>, it seems like it might be interesting to define extractors to automatically convert XML to an AST. Of course, there&#8217;s also XPath, transforms, etc.</p>
<p>Maybe tomorrow night. It&#8217;s time to sleep.</p>
<p>p.s. here are some more Scala XML resources I&#8217;ve found useful:</p>
<ul>
<li><a href="http://www.scala-lang.org/node/131">A Tour of Scala &#8230;</a></li>
<li><a href="http://www.ibm.com/developerworks/java/library/x-scalaxml/index.html">A nice introduction</a> by Michael Galpin</li>
<li>The Scala XML <a href="http://burak.emir.googlepages.com/scalaxbook.docbk.html">&#8220;book&#8221;</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.darevay.com/2009/01/remedial-scala-xml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
