<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>halfdecent.net &#187; java</title>
	<atom:link href="http://halfdecent.net/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://halfdecent.net</link>
	<description>some personal argumentation</description>
	<lastBuildDate>Thu, 22 Dec 2011 12:21:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Netbeans file type integration tutorial comments</title>
		<link>http://halfdecent.net/2011/11/30/netbeans-file-type-integration-tutorial-comments/</link>
		<comments>http://halfdecent.net/2011/11/30/netbeans-file-type-integration-tutorial-comments/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 15:43:58 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://halfdecent.net/?p=228</guid>
		<description><![CDATA[Netbeans 7.1rc1 has been released. When I went through the file type tutorial (which has been updated for 7.1) I found a couple of minor niggles which needed more than a couple of lines in a comment to express, hence &#8230; <a href="http://halfdecent.net/2011/11/30/netbeans-file-type-integration-tutorial-comments/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="http://platform.netbeans.org/images/articles/71/netbeans-stamp.png" alt="" width="112" height="115" />Netbeans 7.1rc1 has been released. When I went through the <a href="http://platform.netbeans.org/tutorials/nbm-filetype.html">file type tutorial</a> (which has been updated for 7.1) I found a couple of minor niggles which needed more than a couple of lines in a comment to express, hence this post.  In Summary, it&#8217;s a good tutorial, but there a few rough edges that could be ironed out:</p>
<ul>
<li>A design bug in the properties window section,</li>
<li>Missing the visual library api dependency,</li>
<li>Excessive overiding the default action on file context menu,</li>
</ul>
<p>and it would really benefit from some extensions, particularly:</p>
<ul>
<li>implementing a navigation window instead of a node tree under the file node,</li>
<li>real-time synchronisation across all views.</li>
</ul>
<p><span id="more-228"></span></p>
<p>Everything up until the &#8220;Creating features for Abc files&#8221; stage in the tutorial worked smoothly for me.  This section also works if you follow the instructions carefully (pay attention though folks, I forget to set the content type in the wizard when I did it). There are some misleading statements though, probably left over from earlier versions.  In the first paragraph the introduction says &#8220;we enable the file to open into a window, instead of into an editor&#8221; but this is not what the action does &#8211; it simply raises a modal dialogue window.  The next paragraph, &#8220;Adding a context-sensitive Action&#8221; then says that the wizard will register the newly generated class in the layer file, however in this version of Netbeans this no longer happens.  Another niggle I have is with the action that&#8217;s created. The tutorial suggests we make our action the default action, the action that&#8217;s used for a double-click.  This is annoying to me as the double-click action should be &#8220;open file in editor&#8221; so in my version of this I choose a different location in step 3.</p>
<p>&#8220;Creating additional Multiview windows&#8221; works just fine.  &#8220;Parsing the file&#8221; also works but it&#8217;s not an elegant solution.  Nodes are created when the file is first opened but then if the file is changed in the editor,  those nodes are not updated. Another niggle I have with this section is that I think it would be better if we saw the tree in a navigation window but I&#8217;m not sure how much code this involves.</p>
<p>The &#8220;Extending the Properties window&#8221; section has a design error in it.  The code provided attempts to preserve the existing file properties but fails because the new default properties set has the same default name.  I would suggest the following variation in the AbcNode class:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> SHEET_ABC_PROPERTIES <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abc properties&quot;</span><span style="color: #339933;">;</span>
&nbsp;
@Override
<span style="color: #000000; font-weight: bold;">protected</span> Sheet createSheet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Sheet sheet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">createSheet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sheet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Sheet.<span style="color: #006633;">PROPERTIES</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setDisplayName</span><span style="color: #009900;">&#40;</span>NbBundle.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span>AbcNode.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;LBL_Abc_PROPERTIES_File&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Sheet.<span style="color: #003399;">Set</span> set <span style="color: #339933;">=</span> Sheet.<span style="color: #006633;">createPropertiesSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  set.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span>SHEET_ABC_PROPERTIES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// default is Sheet.PROPERTIES</span>
  set.<span style="color: #006633;">setDisplayName</span><span style="color: #009900;">&#40;</span>NbBundle.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span>AbcNode.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;LBL_Abc_PROPERTIES_Abc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sheet.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>set<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  set.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LineCountProperty<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">return</span> sheet<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>with the addition of two new strings in the Bundle file:</p>
<pre>LBL_Abc_PROPERTIES_File=File Properties
LBL_Abc_PROPERTIES_Abc=Abc Properties</pre>
<p>The Final &#8220;Creating Synchronised views&#8221; misses the vital information that you need to add the &#8220;Visual Library API&#8221; library in order to compile, but this wasn&#8217;t too hard to work out.  It works fine but the two views are only synchronised when the file is saved and this isn&#8217;t what&#8217;s described in the text. This lack of real-time synchronisation is further exacerbated by the lack of any synchronisation with the node tree in the project explorer.</p>
<p>To conclude, aside from fixing the niggles I would really like to see a navigation window implementation and better synchronisation between the views, however I found the tutorial as it stands very useful.  And of course it could be that the amount of code needed for my suggestions exceeds the word limit for one of these tutorials.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfdecent.net/2011/11/30/netbeans-file-type-integration-tutorial-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting languages in Java &#8211; manipulating an EMF model</title>
		<link>http://halfdecent.net/2009/12/04/scripting-languages-in-java-manipulating-an-emf-model/</link>
		<comments>http://halfdecent.net/2009/12/04/scripting-languages-in-java-manipulating-an-emf-model/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 14:53:02 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://halfdecent.net/?p=72</guid>
		<description><![CDATA[I&#8217;m currently attempting to embed a scripting engine into a Java application. The Java Scripting API means this exercise should be quite straightforward (at least to get something up and running) and there is a huge choice of script languages &#8230; <a href="http://halfdecent.net/2009/12/04/scripting-languages-in-java-manipulating-an-emf-model/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="Groovy logo" src="http://media.xircles.codehaus.org/_projects/groovy/_logos/medium.png" alt="" width="203" height="100" />I&#8217;m currently attempting to embed a scripting engine into a Java application. The <a href="http://java.sun.com/javase/6/docs/technotes/guides/scripting/index.html">Java Scripting API</a> means this exercise should be quite straightforward (at least to get something up and running) and there is a huge choice of script languages to choose from so one of them ought to match my requirements, right?</p>
<p>I&#8217;m taking baby steps while I explore the space of possible options.  So far I&#8217;ve prototyped an expression evaluator that accepts data in the form of simple Java  framework objects and allows boolean expressions to be evaluated over them. In today&#8217;s baby step I thought I&#8217;d try and manipulate some non-framework Java objects built with an <a href="http://www.eclipse.org/modeling/emf/">EMF</a> model that I&#8217;m currently working on and two different scripting languages, <a href="http://groovy.codehaus.org/">Groovy</a> and <a href="http://www.mozilla.org/rhino/">Rhino</a>. Groovy is a scripting language that has grown out of the Java community in response to Python and Ruby.  Rhino is a Javascript engine implemented in Java from the Mozilla foundation that is bundled as the default scripting engine in the Java6 JDK.  I got somewhere with Groovy but got completely stumped with Rhino because I just couldn&#8217;t load my custom classes.</p>
<p><span id="more-72"></span></p>
<h2>Groovy</h2>
<p>First the success story.  I fired up the groovy shell (groovysh) in the directory that contains my classes and got started straight away:</p>
<p><code><span style="color:green">Groovy Shell</span> (, JVM: 1.6.0_15)<br />
Type 'help' or '\h' for help.<br />
-------------------------------------<br />
<strong>groovy:</strong>000&gt; dec = new argkit.decision.impl.DecisionImpl()<br />
<span style="color:red">ERROR</span> java.lang.NoClassDefFoundError: <span style="color:red">org/eclipse/emf/ecore/EObject</span><br />
<strong>at</strong> java_lang_Runnable$run.call (<strong>Unknown Source</strong>)</code></p>
<p>Oh, yeah, I needed to add the EMF classes to the classpath.  I could do that by restarting the shell with the EMF jars included in the classpath or add them in directly&#8230;</p>
<p><code><strong>groovy:</strong>000&gt; this.class.classLoader.rootLoader.addURL(new URL("file:///.../org.eclipse.emf.ecore_2.5.0.v200906151043.jar"))<br />
===&gt; null<br />
<strong>groovy:</strong>000&gt; this.class.classLoader.rootLoader.addURL(new URL("file:///.../org.eclipse.emf.common_2.5.0.v200906151043.jar"))<br />
===&gt; null<br />
<strong>groovy:</strong>000&gt; dec = new argkit.decision.impl.DecisionImpl()<br />
===&gt; argkit.decision.impl.DecisionImpl@5878d2 (name: decision0, caption: null)<br />
<strong>groovy:</strong>000&gt; cand = new argkit.decision.impl.CandidateImpl()<br />
===&gt; argkit.decision.impl.CandidateImpl@b9132a (name: candidate1, caption: null)<br />
<strong>groovy:</strong>000&gt; dec.candidates.add(cand)<br />
===&gt; true<br />
<strong>groovy:</strong>000&gt; cand.status<br />
===&gt; UNKNOWN<br />
<strong>groovy:</strong>000&gt; arg = new argkit.decision.impl.ArgumentImpl()<br />
===&gt; argkit.decision.impl.ArgumentImpl@ce796 (name: argument2, caption: null) (support: +)<br />
<strong>groovy:</strong>000&gt; cand.arguments.add(arg)<br />
===&gt; true<br />
<strong>groovy:</strong>000&gt; cand.status<br />
===&gt; RECOMMENDED<br />
<strong>groovy:</strong>:000&gt; arg.support = argkit.decision.Support.AGAINST<br />
===&gt; -<br />
<strong>groovy:</strong>:000&gt; cand.status<br />
===&gt; REJECTED<br />
<strong>groovy:</strong>:000&gt; exit<br />
</code></p>
<p>Having told Groovy about the EMF jars my code depends on, I create a decision object with one candidate and watch the recommended status of the candidate change with the addition of an argument and it&#8217;s subsequent manipulation.</p>
<h2>Rhino</h2>
<p>Then I fire up the equivalent for Rhino (jrunscript), this time remembering to include the EMF jars on the classpath, and start my shell:</p>
<p><code>js&gt; dec = argkit.decision.impl.DecisionImpl()<br />
script error: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "argkit" is not defined. (&lt;STDIN&gt;#1) in &lt;STDIN&gt; at line number 1<br />
</code><br />
Ah.  This was an unexpected issue as argkit is definitely on the classpath.  And there&#8217;s pretty much where I got to.  Some digging lead me to this <a href="http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=79c908a33f1af578ad9b9996ee1f?bug_id=6799015">bug report</a> for Java which suggests that the problem is with the non-standard top level domain name (TLDN) in my package and points the finger at Rhino.  Adjusting my model (by setting .org as the TLDN) for this perplexing issue got me a little further&#8230;</p>
<p><code>js&gt; dec = org.argkit.decision.impl.DecisionImpl()<br />
script error: sun.org.mozilla.javascript.internal.EcmaError: TypeError: [JavaPackage org.argkit.decision.impl.DecisionImpl] is not a function, it is sun.org.mozilla.javascript.internal.NativeJavaPackage. (#1) in  at line number 1</code></p>
<p>Ummm, it&#8217;s a what?</p>
<p><code>js&gt; org.argkit.decision.impl.DecisionImpl<br />
[JavaPackage org.argkit.decision.impl.DecisionImpl]</code></p>
<p>It&#8217;s certainly not a Java Package. It seems to me that Rhino was really not cut for this particular use case.</p>
<h2>Conclusions</h2>
<p>So to recap, I tried to use Groovy and Rhino to manipulate some non-framework objects, as the expressions in my scripting engine embedded app will need to range over custom state objects and Groovy beat Rhino hands down in terms of ease of integration with the custom code.  Now, if only I could get the <a href="http://groovy.codehaus.org/Eclipse+Plugin">Groovy plugin for Eclipse</a> to install, but that&#8217;s another story&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://halfdecent.net/2009/12/04/scripting-languages-in-java-manipulating-an-emf-model/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

