<?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>hugomonteiro.net &#187; java</title>
	<atom:link href="http://hugomonteiro.net/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://hugomonteiro.net</link>
	<description>&#34;When two men in business always agree, one of them is unnecessary.&#34; - William Wrigley Jr.</description>
	<lastBuildDate>Wed, 14 Dec 2011 00:12:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Deploying PlayFramework Apps in JBoss</title>
		<link>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/</link>
		<comments>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 17:19:57 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=352</guid>
		<description><![CDATA[After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify: play war myapp -o myapp.war Now to deploy on JBoss, you need to do some changes on your WAR file: Create a file called jboss-web.xml in the [...]]]></description>
			<content:encoded><![CDATA[<p>After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify:</p>
<pre>play war myapp -o myapp.war
</pre>
<p>Now to deploy on <a href="http://www.jboss.com/">JBoss</a>, you need to do some changes on your WAR file:</p>
<ul>
<li>Create a file called<strong><em> <strong>jboss</strong>-web.xml </em></strong>in the myapp.war/WEB-INF/ directory container the  following:</li>
</ul>
<pre class="brush: xml;" >
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;&nbsp;?&gt;
&lt;!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd"&gt;
<jboss-web>
<class-loading java2ClassLoadingCompliance="false">
<loader-repository>
com.example:archive=myapp.war
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</class-loading>
</jboss-web>
</pre>
<ul>
<li>Download hibernate-validator and hibernate annotation using the compatibility matrix (<a title="Hibernate Compatibility Matrix" href="http://74.125.77.132/search?q=cache:Q9VmeUcio1MJ:https://www.hibernate.org/6.html+https://www.hibernate.org/6.html%23A3&amp;cd=1&amp;hl=nl&amp;ct=clnk&amp;gl=nl&amp;client=safari">Hibernate Compatibility Matrix</a>).  Play is using hibernate core 3.3.2 GA. Once you are done, place the  relevant jars in the myapp.war/WEB-INF/lib directory. You should end up with:
<ul>
<li>hibernate-annotations.jar</li>
<li>hibernate-entitymanager.jar</li>
<li>hibernate-validator.jar</li>
<li>hibernate-commons-annotations.jar</li>
<li>hibernate-search-3.1.1.GA.jar</li>
<li>hibernate3.jar (Do not overwrite this library, as Play! has a modified version of it)</li>
</ul>
</li>
<li>Now that we&#8217;re prepared for WAR, you need to move your application to the deployment folder of JBoss. The default folder for it is: <em>jboss_home/server/default/deploy </em>(jboss_home == folder of jboss). There are some things you need to be aware of:<em><br />
</em></p>
<ol>
<li>Use a superior java version in JBoss to avoid class version errors</li>
<li>Verify that the WAR folder has the necessary permissions. In my case I needed to make a &#8220;<em>chown -R jboss myapp.war</em>&#8221; where jboss is the user that controls the jboss application server</li>
<li>Do a &#8220;<em>tail -f jboss_home/server/default/log/server.log</em>&#8221; to see if your application is being deployed. You&#8217;ve an Administration Console in <em>http://yourserverip:8080</em></li>
<li>Don&#8217;t change your routes file at runtime<em>. Stop the war, change routes and then start the war (in the administration console I said before)<br />
</em></li>
</ol>
</li>
<li>Now you should have your application working. You can access to your app at: <em>http://yourserverip:8080/myapp.war</em></li>
<li><strong>This tutorial was tested in JBoss 5.0.1</strong><em><br />
</em></li>
</ul>
<p>Thanks to <a href="http://www.twitter.com/nicolasleroux">Nicolas Leroux</a> from <a href="http://lunatech.com">lunatech.com</a> for helping me to create this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Play] Iterate over objects using jQuery</title>
		<link>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/</link>
		<comments>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:13:49 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[play]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=208</guid>
		<description><![CDATA[What if I want to navigate into each checkbox, radio of my html? You can do it pretty easily using jQuery.each function. In every checkbox element I want to send a post message to my Play Framework. ﻿﻿jQuery.each($(':checkbox'), function() { $﻿.post('@{myPlayMethod()}', { itemValue: $(this).val() }) });﻿ This code sends the html element value property to [...]]]></description>
			<content:encoded><![CDATA[<p>What if I want to navigate into each checkbox, radio of my html? You can do it pretty easily using <a href="http://docs.jquery.com/Utilities/jQuery.each">jQuery.each function</a>.</p>
<p>In every checkbox element I want to send a post message to my Play Framework.</p>
<pre>﻿﻿jQuery.each($(':checkbox'), function() {
    $﻿.post('@{myPlayMethod()}', { itemValue: $(this).val() })
});﻿</pre>
<p>This code sends the html element value property to method &#8220;<em>myPlayMethod(String itemValue)</em>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to divide your GUI from your processing code?</title>
		<link>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/</link>
		<comments>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:53:43 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=157</guid>
		<description><![CDATA[Many students don't know how to organize their code. Abstractions and Interfaces makes a difference when developing Java applications. What if your code was divided? For instance, if you have created a network application with a GUI (Graphical User Interface). The first approach is to put the code all together because it's easier from the beginning. That's wrong because it's harder to find an error and you have to read a lot of garbage code like <em>textBox.setValue</em>...]]></description>
			<content:encoded><![CDATA[<p>Many students don&#8217;t know how to organize their code. Abstractions and Interfaces make a difference when developing Java applications. What if your code was divided? For instance, if you built a network application with a GUI (Graphical User Interface). The first approach is to put the code all together because it&#8217;s easier from the beginning. That&#8217;s wrong because it&#8217;s harder to find an error, and you have to read a lot of garbage code like <em>textBox.setValue</em>&#8230;</p>
<p>What about dividing this network application in two layers? One layer, with all the network code and the top layer with only the GUI? How is this possible? Using Java interfaces and the notion of events.</p>
<p>We can start by creating our event interface that will be waken up, when for instance we are receiving a message from the network:</p>
<pre>public interface EventNetworkInterface {
	void receiveMessage(String msg);
}</pre>
<p>Now it&#8217;s time to build our simplified network layer:</p>
<pre>
public class NetworkLayer {
	EventNetworkInterface gui = null;

	public NetworkLayer(EventNetworkInterface gui) {
		this.gui = gui;
	}

	public void receiveMessageNetwork() {
		//simulates receiving a message from the network
                String msg_received = "Hello World!";
		//wake up event in the GUI
		gui.receiveMessage(msg_received);
	}
}
</pre>
<p>Now with the network layer created you have to create the GUI:</p>
<pre>
public class GUI implements EventNetworkInterface {

	public static void main(String[] args) {
		new GUI();
	}

	private NetworkLayer nl;

	public GUI() {
		nl = new NetworkLayer(this);
		//issue a receiveMessage event:
		nl.receiveMessageNetwork();
	}

	@Override
	public void receiveMessage(String msg) {
		System.out.println("I sent the message: " + msg);
	}

}
</pre>
<p>In the GUI constructor we are simulating a <em>receivedMessage</em> event after we build the network layer and send the GUI that implements the events that will be waken up when a <em>receiveMessage</em> (in this case) happens.</p>
<p>With this approach you can separate the design code, from the processing code and simplify when you are adding more features to the layers beneath you.</p>
<p>If you want to have multiple classes to execute the same events, see more about the <a href="http://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton Design Pattern problems?</title>
		<link>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/</link>
		<comments>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:46:23 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=123</guid>
		<description><![CDATA[The Singleton Pattern ensures a class has only one instance that provides a global point to access it. This design pattern is perfect for maintaining a set of configurations or other variables always available at run-time in your software. public static Singleton getInstance() { if (uniqueInstance == null) { uniqueInstance = new Singleton(); } return [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a> ensures a class has only one instance that provides a global point to access it. This design pattern is perfect for maintaining a set of configurations or other variables always available at run-time in your software.</p>
<pre>public static Singleton getInstance() {
    if (uniqueInstance == null) {
       uniqueInstance = new Singleton();
    }
    return uniqueInstance;
}</pre>
<p>In this code snippet, if you have a multithreaded application that executes the same class, some concurrency problems can occur. For instance if the two threads accesses to the condition at the same time, creates two different Singleton instances. How can you fix this problem? Newer virtual machines (like JVM 1.5) ensures this when you create the Singleton instance in a static variable outside of any method. The JVM guarantees that the instance will be created before any thread accesses the static uniqueInstance variable. The solution for this is:</p>
<pre>public class Singleton {
    private static Singleton uniqueInstance = new Singleton ();

    private Singleton() {}

    public static Singleton getInstance () {
       return uniqueInstance;
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

