<?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>Christophe Coenraets &#187; Spring</title>
	<atom:link href="http://coenraets.org/blog/category/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://coenraets.org/blog</link>
	<description>Rich Internet Applications, Flex, AIR, Java, Android</description>
	<lastBuildDate>Fri, 23 Jul 2010 14:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>New Update to the Spring BlazeDS Integration Test Drive</title>
		<link>http://coenraets.org/blog/2009/05/new-update-to-the-spring-blazeds-integration-test-drive/</link>
		<comments>http://coenraets.org/blog/2009/05/new-update-to-the-spring-blazeds-integration-test-drive/#comments</comments>
		<pubDate>Tue, 12 May 2009 19:33:32 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=119</guid>
		<description><![CDATA[I made some additional changes to the Spring BlazeDS Integration (RC1) Test Drive: The Test Drive now includes an annotation-based configuration sample (the Company Manager sample). Spring annotations such as @Service, @RemotingDestination, @Autowired, @RemotingInclude, and @RemotingExclude make it really easy to configure your beans and make them available through Remoting. As an example, here is [...]]]></description>
			<content:encoded><![CDATA[<p>I made some additional changes to the Spring BlazeDS Integration (RC1) Test Drive:</p>
<ul>
<li>The Test Drive now includes an annotation-based configuration sample (the Company Manager sample). Spring annotations such as @Service, @RemotingDestination, @Autowired, @RemotingInclude, and @RemotingExclude make it really easy to configure your beans and make them available through Remoting. As an example, here is the source code for the CompanyDAO class:
<p></p>
<pre class="brush: java;">
package flex.spring.samples.company;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingExclude;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

import flex.spring.samples.industry.IIndustryDAO;

@Service(&quot;companyService&quot;)
@RemotingDestination(channels={&quot;my-amf&quot;})
public class CompanyDAO implements ICompanyDAO {

	private final SimpleJdbcTemplate template;
	private final SimpleJdbcInsert insertCompany;

	private IIndustryDAO industryDAO;

	private final ParameterizedRowMapper&lt;Company&gt; rowMapper = new ParameterizedRowMapper&lt;Company&gt;(){
		public Company mapRow(ResultSet rs, int rowNum) throws SQLException {
			Company company = new Company();
			company.setId(rs.getInt(&quot;id&quot;));
			company.setName(rs.getString(&quot;name&quot;));
			company.setAddress(rs.getString(&quot;address&quot;));
			company.setCity(rs.getString(&quot;city&quot;));
			company.setState(rs.getString(&quot;state&quot;));
			company.setZip(rs.getString(&quot;zip&quot;));
			company.setPhone(rs.getString(&quot;phone&quot;));
			company.setIndustry(industryDAO.findById(rs.getInt(&quot;industry_id&quot;)));
			return company;
		}
	};

	@Autowired
	public CompanyDAO(DataSource dataSource, IIndustryDAO industryDAO) {
		template = new SimpleJdbcTemplate(dataSource);
		insertCompany = new SimpleJdbcInsert(dataSource).withTableName(&quot;COMPANY&quot;).usingGeneratedKeyColumns(&quot;ID&quot;);
		this.industryDAO = industryDAO;
	}

	@RemotingInclude
	public Company findById(int id) {
		return template.queryForObject(&quot;SELECT * FROM company WHERE id=?&quot;, rowMapper, id);
	}

	@RemotingInclude
	public List&lt;Company&gt; findAll() {
		return template.query(&quot;SELECT * FROM company ORDER BY name&quot;, rowMapper);
	}

	@RemotingInclude
	public List&lt;Company&gt; findByName(String name) {
		return template.query(&quot;SELECT * FROM company WHERE UPPER(name) LIKE ? ORDER BY name&quot;,
				rowMapper,
				&quot;%&quot; + name.toUpperCase() + &quot;%&quot;);
	}

	@RemotingInclude
	public Company create(Company company) {
		Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
        parameters.put(&quot;name&quot;, company.getName());
        parameters.put(&quot;address&quot;, company.getAddress());
        parameters.put(&quot;city&quot;, company.getCity());
        parameters.put(&quot;state&quot;, company.getState());
        parameters.put(&quot;zip&quot;, company.getZip());
        parameters.put(&quot;phone&quot;, company.getPhone());
        parameters.put(&quot;industry_id&quot;, company.getIndustry().getId());
        Number id = insertCompany.executeAndReturnKey(parameters);
		company.setId(id.intValue());
		return company;
	}

	@RemotingInclude
	public boolean update(Company company) {
        int count = template.update(&quot;UPDATE company SET name=?, address=?, city=?, state=?, zip=?, phone=?, industry_id=? WHERE id=?&quot;,
				company.getName(),
				company.getAddress(),
				company.getCity(),
				company.getState(),
				company.getZip(),
				company.getPhone(),
				company.getIndustry().getId(),
				company.getId());
		return (count == 1);
	}

	@RemotingExclude
	public boolean remove(Company company) {
		int count = template.update(&quot;DELETE FROM company WHERE id=?&quot;, company.getId());
		return (count == 1);
	}

}
</pre>
<p>
</li>
<li>The Test Drive is now using the M3 build of Spring 3 (as opposed to M2 in the previous builds of the Test Drive).</li>
<li>I modified the configuration of the long polling channel to support more persistent connections per domain based on the browser capabilities.</li>
<li>And of course compared to the M2 build, this version of the Test Drive includes a number of Messaging samples.
<p>Using the Messaging integration, setting up a destination can be as easy as:</p>
<pre class="brush: xml;">
&lt;flex:message-destination id=&quot;chat&quot; /&gt;
</pre>
<p>And here is how you configure a destination mapped to a JMS topic:</p>
<pre class="brush: xml;">
&lt;flex:jms-message-destination id=&quot;jms-chat&quot; jms-destination=&quot;chatTopic&quot; /&gt;
</pre>
</li>
</ul>
<h3>Installation Instructions:</h3>
<ol>
<li>Download the Spring / Flex TestDrive here: <a href="http://coenraets.org/downloads/spring-flex-testdrive-RC1v2.zip">http://coenraets.org/downloads/spring-flex-testdrive-RC1v2.zip</a></li>
<li>Unzip it in your root directory</li>
<li>Navigate to /spring-flex-testdrive/tomcat/bin and start Tomcat (for instance: catalina run)</li>
<li>Open a browser and access http://localhost:8080</li>
<li>Follow the instructions</li>
</ol>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/05/new-update-to-the-spring-blazeds-integration-test-drive/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Speaking at the New England Java User Group on Thursday (May 14th)</title>
		<link>http://coenraets.org/blog/2009/05/speaking-at-the-new-england-java-user-group-on-thursday-may-14th/</link>
		<comments>http://coenraets.org/blog/2009/05/speaking-at-the-new-england-java-user-group-on-thursday-may-14th/#comments</comments>
		<pubDate>Mon, 11 May 2009 18:47:18 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=118</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://coenraets.org/downloads/nejug.gif" alt="" </p>
<p>I will be joined by Mark Fisher from SpringSource and we will talk about Flex, Spring, BlazeDS and the integration of these technologies. <a href="http://www.springsource.org/spring-flex">Spring BlazeDS integration</a> RC1 was released last week. One of the key features in RC1 is the integration of the Message service, and Mark is the lead developer on that feature.</p>
<p>I hope to see you there if you live in the greater Boston area.</p>
<p>Thu, May 14 6:00pm<br />
Sun Microsystems &#8211; 1 Network Way, Burlington, MA<br />
<a href="http://www.nejug.org/events/show/93">NEJUG Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/05/speaking-at-the-new-england-java-user-group-on-thursday-may-14th/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New Test Drive for Spring BlazeDS Integration RC1</title>
		<link>http://coenraets.org/blog/2009/05/new-test-drive-for-spring-blazeds-integration-rc1/</link>
		<comments>http://coenraets.org/blog/2009/05/new-test-drive-for-spring-blazeds-integration-rc1/#comments</comments>
		<pubDate>Fri, 08 May 2009 20:34:55 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[LCDS]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=117</guid>
		<description><![CDATA[UPDATE: An updated version of this Test Drive is available here SpringSource just released the RC1 build for the Spring / BlazeDS integration project. The key new feature in RC1 is the integration of the BlazeDS Message Service. I updated my Spring BlazeDS Integration Test Drive to showcase the messaging integration. In addition to Remoting [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: An updated version of this Test Drive is available <a href="http://coenraets.org/blog/2009/05/new-update-to-the-spring-blazeds-integration-test-drive/">here</a></strong></p>
<p>SpringSource just released the RC1 build for the <a href="http://www.springsource.org/spring-flex">Spring / BlazeDS integration project</a>. The key new feature in RC1 is the integration of the BlazeDS Message Service.</p>
<p>I updated my Spring BlazeDS Integration Test Drive to showcase the messaging integration.</p>
<p>In addition to Remoting and Security samples, the Test Drive now includes the following Messaging samples:</p>
<ul>
<li><strong>Chat</strong>: Messaging basics</li>
<li><strong>Simple Data Push</strong>: A simple data push example</li>
<li><strong>Traderdesktop</strong>: A more sophisticated data push example showing how to use subtopics</li>
<li><strong>JMS Chat</strong>: A chat application using a JMS topic and exchanging messages with a Swing-based client</li>
<li><strong>Collaboration</strong>: An example showing how to use messaging to remotely drive another client&#8217;s application</li>
</ul>
<h3>Installation Instructions:</h3>
<ol>
<li>Download the Spring / Flex TestDrive here: <a href="http://coenraets.org/downloads/spring-flex-testdrive-RC1.zip">http://coenraets.org/downloads/spring-flex-testdrive-RC1.zip</a></li>
<li>Unzip it in your root directory</li>
<li>Navigate to /spring-flex-testdrive/tomcat/bin and start Tomcat (for instance: catalina run)</li>
<li>Open a browser and access http://localhost:8080</li>
<li>Follow the instructions</li>
</ol>
<p>As always, I&#8217;d love to hear your feedback and your ideas to improve this Test Drive.</p>
<p>I will probably have another version next week with a couple of additional samples and more documentation for the Message Service, but I already wanted to make this version available to allow you to experiment RC1 samples.</p>
<p>Christophe</p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/05/new-test-drive-for-spring-blazeds-integration-rc1/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>The &#8220;Spring ActionScript&#8221; Framework – Part 2: Autowiring</title>
		<link>http://coenraets.org/blog/2009/03/the-spring-actionscript-framework-%e2%80%93-part-2-autowiring/</link>
		<comments>http://coenraets.org/blog/2009/03/the-spring-actionscript-framework-%e2%80%93-part-2-autowiring/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 13:15:16 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=111</guid>
		<description><![CDATA[In the first part of this series, we looked at how the “Spring ActionScript” framework can help you externalize the configuration and the wiring of your components, and how you can easily obtain configured objects using applicationContext.getObject(). In this second part, we will discuss how you can make these objects available to the views of [...]]]></description>
			<content:encoded><![CDATA[<p>In the first part of this series, we looked at how the “Spring ActionScript” framework can help you externalize the configuration and the wiring of your components, and how you can easily obtain configured objects using applicationContext.getObject().</p>
<p>In this second part, we will discuss how you can make these objects available to the views of your application without tightly coupling these views to the framework, and without passing references around through potentially many levels of view containment.</p>
<p>We will build the &#8220;Spring ActionScript&#8221; version of the InSync contact management application I often use in this blog to explore new technologies. The application has two views: MainView and ContactForm. Both need a reference to a contact RemoteObject to work.</p>
<p>NOTE: This example is intentionally kept simple. In a more partitioned application, you may want to pass a more abstract controller around as opposed to a specific RemoteObject. We will use this approach in part 3.</p>
<p>The views could use applicationContext.getObject() to access their dependencies (in this case the contact RemoteObject), but this approach has a number of problems:</p>
<ol>
<li>With a dependency on applicationContext, the views would be tightly coupled to the framework.</li>
<li>We would still need to pass a reference to the applicationContext object to the views. This is often solved using the singleton approach which has its own set of problems.</li>
</ol>
<p>So, instead of the views instantiating or looking up their dependencies, a better approach would be to &#8220;inject&#8221; these dependencies into the views.</p>
<p>Unlike Swiz, &#8220;Spring ActionScript&#8221; doesn’t currently have built-in support for an [Autowire] annotation, but Christophe Herreman <a href="http://forum.springsource.org/showthread.php?t=67319">seems to imply</a> that this feature is coming, and in the meantime, he provides <a href="http://www.herrodius.com/blog/158">some sample code</a> to support  &#8220;Spring ActionScript&#8221;-powered autowiring in your application. Using this custom code, the inSync application looks like this:</p>
<p><span id="more-111"></span></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	applicationComplete=&quot;applicationCompleteHandler()&quot;&gt;

	&lt;mx:Script&gt;
	&lt;![CDATA[

	import insync.views.MainView;
	import mx.utils.DescribeTypeCacheRecord;
	import mx.utils.DescribeTypeCache;
	import as3reflect.ClassUtils;
	import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;

	private var applicationContext:FlexXMLApplicationContext;

	private function applicationCompleteHandler():void
	{
		applicationContext = new FlexXMLApplicationContext(&quot;applicationContext.xml&quot;);
		applicationContext.addEventListener(Event.COMPLETE, applicationContextComplete);
		applicationContext.load();
	}

	private function applicationContextComplete(event:Event):void
	{
		systemManager.addEventListener(Event.ADDED, addedEventHandler);
		var mainView:MainView = new MainView();
		addChild(mainView);
	}

	private function addedEventHandler(event:Event):void
	{
		var autowiredObject:Object = event.target;
		trace(&quot;Added to display list: &quot; + autowiredObject);
		var typeInfo:DescribeTypeCacheRecord = DescribeTypeCache.describeType(autowiredObject);
		for each (var metaDataNode:XML in typeInfo.typeDescription..metadata)
		{
			if (metaDataNode.attribute(&quot;name&quot;) == &quot;Autowired&quot;)
			{
				var propertyNode:XML = metaDataNode.parent();
				var property:String = propertyNode.@name.toString();
				trace(&quot;Found Autowired property: &quot; + property);
				var objectName:String = property;
				var autowireByType:Boolean = true;

				for each (var arg:XML in metaDataNode.arg)
				{
					if (arg.attribute(&quot;value&quot;) == &quot;byName&quot;)
					{
						autowireByType = false;
					}
				}

				if (autowireByType)
				{
					var clazz:Class = ClassUtils.forName(propertyNode.@type.toString());
					var objectNames:Array = applicationContext.getObjectNamesForType(clazz);
					if (objectNames.length == 1)
					{
						objectName = objectNames[0];
					}
				}
				trace(&quot;Autowiring: &quot; + property + &quot; in &quot; + autowiredObject);
				autowiredObject[property] = applicationContext.getObject(objectName);
			}
		}
	}

	]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Style source=&quot;styles.css&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
<p>To be able to inject properties annotated with Autowired, we register as a listener for the ADDED event on systemManager, and introspect each object added to the display list. If the object has [Autowired] properties, those properties are injected (by name or by type) using applicationContext.getObject(objectName).  This is also the approach taken by Swiz.</p>
<h3>Timing</h3>
<p>Before you inject objects into views, you need to make sure the applicationContext.xml file has been loaded and that the objects it defines have been instantiated. To that effect, the applicationContext dispatches an Event.COMPLETE event when it is ready. To make sure all the views of my application can be properly injected (if needed), the strategy I use in this application is to start instantiating the main view only after this event has been triggered. See addChild(mainView) in the applicationContextComplete handler.</p>
<h3>The Views</h3>
<p>With that infrastructure in place, the two views of the InSync application are easy to write. Their basic setup looks like this:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Canvas xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[

			import mx.rpc.remoting.mxml.RemoteObject;

			[Autowired]
			public var contactRemoteObject:RemoteObject;

		]]&gt;
	&lt;/mx:Script&gt;

&lt;/mx:Canvas&gt;
</pre>
<h3>Installation instructions</h3>
<p>NOTE: If you already installed <a href="http://coenraets.org/blog/2009/02/sample-application-using-the-swiz-framework-and-blazeds/">the Swiz version of inSync</a>, you can skip steps 1, 3, 4, 5 and 6.</p>
<ol>
<li>Install the <a href="http://opensource.adobe.com/blazeds">BlazeDS turnkey server</a>. (To be clear: you don’t have to use BlazeDS to use Spring ActionScript… That’s just what this sample is using.)</li>
<li>Download <a href="http://coenraets.org/downloads/insyncspringas/insyncspringas.zip">insyncspringas.zip</a>, and unzip it on your local file system.</li>
<li>Copy insyncspringas/java/classes/insync to blazeds/tomcat/webapps/samples/WEB-INF/classes/insync.</li>
<li>Add the following destination to blazeds/tomcat/webapps/samples/WEB-INF/flex/remoting-config.xml:</li>
<p><pre class="brush: xml;">
&lt;destination id=&quot;contacts&quot;&gt;
        &lt;properties&gt;
            &lt;source&gt;insync.dao.ContactDAO&lt;/source&gt;
            &lt;scope&gt;application&lt;/scope&gt;
        &lt;/properties&gt;
&lt;/destination&gt;
</pre>
</p>
<li>Copy insyncspringas/sampledb/insync to blazeds/sampledb/insync</li>
<li>Edit server.properties in blazeds/sampledb, and modify the file as follows to add the insync database to the startup procedure.
<p><pre class="brush: plain;">
server.database.0=file:flexdemodb/flexdemodb
server.dbname.0=flexdemodb
server.database.1=file:insync/insync
server.dbname.1=insync
server.port=9002
server.silent=true
server.trace=false
</pre>
</p>
</li>
<li>Start the database (startdb.bat or startdb.sh)</li>
<li>Start BlazeDS</li>
<li>In Flex Builder, create a new Flex project called insyncspringas. You don’t have to select any &#8220;Application server type&#8221;. </li>
<li>Copy spring-actionscript.swc and as3reflect.swc from insyncspringas/flex/lib to the lib directory of your project</li>
<li>Copy the files and folders from insyncspringas/flex/src to the src directory of your project</li>
<li>Open applicationContext.xml and make sure the remoteObject endpoint value matches your server setup.</li>
<li>Run the application</li>
</ol>
<h3>Note on Autowiring and Performance</h3>
<p>Annotation-based dependency injection is elegant and easy to work with. However, the current implementation that requires a describeType on every object added to the display list has a performance impact. This is maybe something that the Flex framework could help with in the future. For example, we could inject code at compile time to dispatch an AutowireEvent for each Autowired property when a class is instantiated. We would leave it up to the frameworks to provide a specific injection implementation. That would give these frameworks a better event to listen to, and they wouldn’t have to introspect all the objects added to the display list. An alternative would be to have a compiler hook to allow annotation-based code injection at compile time.</p>
<p>In the meantime, you’ll have to identify if the performance impact of the current approach is acceptable in the context of your application. If not, there are ways to improve the basic approach described above:</p>
<ul>
<li>Using Swiz, <a href="http://aralbalkan.com/1960">Aral Balkan uses an autowire property</a> on the views that require autowiring. In the autowiring code, he then uses the hasOwnPropety(&#8220;autowiring&#8221;) function to identify if the object needs to be autowired before using describeType. This approach still requires some level of introspection on each object added to the display list.</li>
<li>Swiz now makes sure it doesn’t perform describeType on classes in the mx packages. This approach could also be added to the code above.</li>
<li>Another approach would be for you to programmatically dispatch an AutowireEvent in the initialize event of the views that need to be autowired. This approach is maybe less elegant than a simple annotation, but wouldn’t have the performance impact of introspecting all the objects added to the display list. It would also work for any object in your application, not only the views.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/03/the-spring-actionscript-framework-%e2%80%93-part-2-autowiring/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>The “Spring ActionScript” Framework  – Part 1: The Basics</title>
		<link>http://coenraets.org/blog/2009/03/the-%e2%80%9cspring-actionscript%e2%80%9d-framework-%e2%80%93-part-1-the-basics/</link>
		<comments>http://coenraets.org/blog/2009/03/the-%e2%80%9cspring-actionscript%e2%80%9d-framework-%e2%80%93-part-1-the-basics/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 18:09:08 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=109</guid>
		<description><![CDATA[The “Spring ActionScript” framework (formerly known as Prana, and brainchild of Christophe Herreman) is being built as the ActionScript version of the Spring IoC framework hugely popular in the Java world. It is also part of a growing number of Flex frameworks that revolve around the Dependency Injection approach (the list also includes Swiz and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.pranaframework.org/">“Spring ActionScript” framework</a> (formerly known as Prana, and brainchild of <a href="http://www.herrodius.com/">Christophe Herreman</a>) is being built as the ActionScript version of the <a href="http://springsource.org">Spring IoC framework</a> hugely popular in the Java world. It is also part of a growing number of Flex frameworks that revolve around the Dependency Injection approach (the list also includes <a href="http://code.google.com/p/swizframework/">Swiz </a>and <a href="http://mate.asfusion.com/">Mate</a>). </p>
<p>I recently spent some time exploring “Spring ActionScript”. There aren’t a lot of resources available yet, so I figured I would contribute my own exploration.</p>
<p>Note: Also, to avoid confusion, this project is independent from the Spring/BlazeDS integration project I have been writing about a lot lately. These two projects could however complement each other nicely.</p>
<p>In this first post, I’ll cover the basics… Imagine you have an application that uses RemoteObject to access the back-end of your application. Unless your application is made of only a couple of components and will forever  communicate with the same server, there are two issues you’ll have to deal with early on:</p>
<ol>
<li>How to externalize the service configuration (channels, endpoints, etc) from your code</li>
<li>How to provide the different components of your application with a reference to that service </li>
</ol>
<p><span id="more-109"></span></p>
<p>Notes: </p>
<ol>
<li>This first example is intentionally kept very simple. In a more partitioned application, you may want to pass a more abstract controller around as opposed to a specific RemoteObject. This will be covered in part 3 of this series.</li>
<li>The Spring ActionScript framework is an inversion of control framework: You don’t have to use RemoteObject, any specific data access strategy, or even connect to a back-end to use it… This is just the test case I wanted to build.</li>
</ol>
<h3>Objects configuration and wiring</h3>
<p>Spring Actionscript uses an XML file to configure and wire its components. The advantage is that you can change the configuration and the wiring of your components, or even swap the implementation of a component without having to recompile. This leads to a great deal of flexibility during development, testing, and in your production environment.
<p>On the other hand, when you declare classes in an XML configuration file, the compiler is not aware of what you are doing: The configuration and wiring of your components is not checked at compile time, and more importantly, classes defined in the XML configuration file but not referenced directly in your code will not be linked in your SWF. This is however not a major issue as you can easily tell  the compiler to include these classes (see part 3 of this series).</p>
<p>In this first example, we will simply configure a RemoteObject…</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;objects&gt;

	&lt;object id=&quot;channelSet&quot; class=&quot;mx.messaging.ChannelSet&quot;&gt;
		&lt;method-invocation name=&quot;addChannel&quot;&gt;
			&lt;arg&gt;
				&lt;object id=&quot;amfChannel&quot; class=&quot;mx.messaging.channels.AMFChannel&quot;&gt;
					&lt;property name=&quot;url&quot; value=&quot;http://localhost:8400/lcds-samples/messagebroker/amf&quot;/&gt;
				&lt;/object&gt;
			&lt;/arg&gt;
		&lt;/method-invocation&gt;
	&lt;/object&gt;

	&lt;object id=&quot;contactRemoteObject&quot; class=&quot;mx.rpc.remoting.mxml.RemoteObject&quot;&gt;
		&lt;property name=&quot;channelSet&quot; ref=&quot;channelSet&quot; /&gt;
		&lt;property name=&quot;destination&quot; value=&quot;contacts&quot; /&gt;
		&lt;property name=&quot;showBusyCursor&quot; value=&quot;true&quot; /&gt;
	&lt;/object&gt;

&lt;/objects&gt;
</pre>
<p>Notice that we first configure a ChannelSet object.  In this case, we define a single AMF channel. We then configure our RemoteObject, and inject its channelSet property with the ChannelSet object we just configured.</p>
<p>Externalizing this configuration and the wiring between the RemoteObject and the ChannelSet from your code has many benefits…  Without recompiling, you could for example:</p>
<ol>
<li>Change the AMF channel URL, point to another server, another port, another endpoint.</li>
<li>Add more channels (fall back channels) to the ChannelSet.</li>
<li>Change the channel type. For example, switch from AMFChannel to RTMPChannel.</li>
<li>Change the target destination</li>
</ol>
<p>As a (simpler) alternative you could also configure your RemoteObject as follows:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;objects&gt;

	&lt;object id=&quot;remoteObject&quot; class=&quot;mx.rpc.remoting.mxml.RemoteObject&quot;	abstract=&quot;true&quot;&gt;
		&lt;property name=&quot;endpoint&quot; value=&quot;http://localhost:8400/lcds-samples/messagebroker/amf&quot; /&gt;
		&lt;property name=&quot;showBusyCursor&quot; value=&quot;true&quot; /&gt;
	&lt;/object&gt;

	&lt;object id=&quot;contactRemoteObject&quot; parent=&quot;remoteObject&quot;&gt;
		&lt;property name=&quot;destination&quot; value=&quot;contacts&quot; /&gt;
	&lt;/object&gt;

&lt;/objects&gt;
</pre>
<p>Note that to avoid repetition, you can configure an “abstract” object (in this case “remoteObject”) that includes configuration settings applicable to all the concrete versions of that object (in this case “contactRemoteObject”).</p>
<h3>Obtaining a configured object in the application.</h3>
<p>Now that the RemoteObject is configured, let&#8217;s build a simple application using the RemoteObject we just configured.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; xmlns:local=&quot;*&quot;
	initialize=&quot;applicationCompleteHandler()&quot;&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.rpc.AsyncResponder;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			import mx.rpc.AsyncToken;
			import mx.rpc.remoting.mxml.RemoteObject;

			import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;

			private var applicationContext:FlexXMLApplicationContext;

			private var remoteObject:RemoteObject;

			private function applicationCompleteHandler():void
			{
				applicationContext = new FlexXMLApplicationContext(&quot;applicationContext.xml&quot;);
				applicationContext.addEventListener(Event.COMPLETE, applicationContextLoaded);
				applicationContext.load();
			}

			private function applicationContextLoaded(event:Event):void
			{
				remoteObject = applicationContext.getObject(&quot;contactRemoteObject&quot;);
				var token:AsyncToken = remoteObject.getContacts();
				token.addResponder(new AsyncResponder(resultHandler, faultHandler, token));
			}

			private function resultHandler(event:ResultEvent, token:AsyncToken):void
			{
				dg.dataProvider = event.result;
			}

			private function faultHandler(event:FaultEvent, token:AsyncToken):void
			{
				Alert.show(event.fault.faultString);
			}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:DataGrid id=&quot;dg&quot; width=&quot;100%&quot; height=&quot;100%&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
<p>The first step when you build an application using the Spring ActionScript framework is to create an ApplicationContext object and use it to load your configuration. Once the configuration is loaded, you can obtain fully configured objects using the applicationContext’s getObject method, and from here it’s then business as usual.</p>
<h3>Next Steps</h3>
<p>In this first example, we looked at how the Spring ActionScript framework can help you externalize the configuration and the wiring of your components, and how you can easily get configured objects in your application using the applicationContext.</p>
<p>In part 2, “Autowiring”, we will discuss how you can make these objects available to the views of your application without tightly coupling these views to the framework, and without passing references around through potentially many levels of view containment.</p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/03/the-%e2%80%9cspring-actionscript%e2%80%9d-framework-%e2%80%93-part-1-the-basics/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Spring / BlazeDS Integration on Adobe TV</title>
		<link>http://coenraets.org/blog/2009/02/spring-blazeds-integration-on-adobe-tv/</link>
		<comments>http://coenraets.org/blog/2009/02/spring-blazeds-integration-on-adobe-tv/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 16:09:34 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=105</guid>
		<description><![CDATA[In this new Adobe TV episode, I demonstrate how to build Flex applications that connect to a Spring back-end using the new Spring / BlazeDS Integration project. If you are interested in this integration, make sure you check out the Spring / BlazeDS Integration page on the SpringSource web site and the new Spring / [...]]]></description>
			<content:encoded><![CDATA[<p>In this new Adobe TV episode, I demonstrate how to build Flex applications that connect to a Spring back-end using the new Spring / BlazeDS Integration project.</p>
<p>If you are interested in this integration, make sure you check out the <a href="http://www.springsource.org/spring-flex">Spring / BlazeDS Integration page</a> on the SpringSource web site and the <a href="http://coenraets.org/blog/2009/01/new-springblazeds-integration-test-drive/">new Spring / BlazeDS Integration Test Drive</a>.</p>
<p><embed src="http://tv.adobe.com/Embed.swf" quality="high" bgcolor="#000000" width="600" height="385" name="AdobeTVPlayer" play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" flashVars="v=~b64~aHR0cDovL2Fkb2JlLmVkZ2Vib3NzLm5ldC9mbGFzaC9hZG9iZS9hZG9iZXR2Mi9hZGNfcHJlc2VudHMvNjRfYWRjXzA5MC5mbHY/cnNzX2ZlZWRpZD0xNDcyJnhtbHZlcnM9Mg==&#038;w=600&#038;t=http://tv.adobe.com/#vi+f1472v1053&#038;h=385"></embed></p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/02/spring-blazeds-integration-on-adobe-tv/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>New Spring/BlazeDS Integration Test Drive</title>
		<link>http://coenraets.org/blog/2009/01/new-springblazeds-integration-test-drive/</link>
		<comments>http://coenraets.org/blog/2009/01/new-springblazeds-integration-test-drive/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 16:54:16 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Air]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=99</guid>
		<description><![CDATA[UPDATE: I posted a new version of the Test Drive for the M2 build of the Spring / BlazeDS integration project here. Please use that version. SpringSource recently announced the Spring / BlazeDS Integration project. You can read more about the project and download the bits at http://www.springsource.org/spring-flex. To help developers get started with the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: I posted a new version of the Test Drive for the M2 build of the Spring / BlazeDS integration project <a href="http://coenraets.org/blog/2009/03/springblazeds-integration-test-drive-m2-update-available/">here</a>. Please use that version.</strong></p>
<p>SpringSource recently announced the Spring / BlazeDS Integration project. You can read more about the project and download the bits at <a href="http://www.springsource.org/spring-flex">http://www.springsource.org/spring-flex</a>.</p>
<p>To help developers get started with the integration, I put together a new &#8220;Spring / BlazeDS Test Drive&#8221;. This Test Drive consists of a minimal version of Tomcat with BlazeDS and the “Spring / BlazeDS integration” preconfigured and ready to use. It also includes a series of samples running “out-of-the-box”  that should allow you to get up and running integrating Flex (and Adobe AIR) with Spring in  minutes. </p>
<h3>Installation Instructions:</h3>
<ol>
<li>Download the Spring / Flex TestDrive here: <a href="http://coenraets.org/downloads/spring-flex-testdrive.zip">http://coenraets.org/downloads/spring-flex-testdrive.zip</a></li>
<li>Unzip it in your root directory</li>
<li>Navigate to /spring-flex-testdrive/tomcat/bin and start Tomcat (for instance: catalina run)</li>
<li>Open a browser and access http://localhost:8080</li>
<li>Follow the instructions</li>
</ol>
<p>As always, I&#8217;d would love to hear your feedback and your ideas to improve this Test Drive.</p>
<p>Christophe</p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2009/01/new-springblazeds-integration-test-drive/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>Flex Test Drive Server for Java Developers (Tomcat-based)</title>
		<link>http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/</link>
		<comments>http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 17:53:48 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Collaboration]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[hibernate]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/</guid>
		<description><![CDATA[I have been working on a Tomcat-based “Flex Test Drive Server”. The Test Drive Server is a minimal and ready-to-use version of Tomcat (currently version 5.5.20) in which the Flex Data Services (version 2.0.1) WAR file has already been deployed and configured along with a variety of tutorials and sample applications. It allows you to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a Tomcat-based “Flex Test Drive Server”. The Test Drive Server is a minimal and ready-to-use version of Tomcat (currently version 5.5.20) in which the Flex Data Services (version 2.0.1) WAR file has already been deployed and configured along with a variety of tutorials and sample applications. It allows you to get up and running integrating Flex with Java back-ends in a matter of minutes. Download fds-tomcat.zip, expand the file, and run&#8230;</p>
<p>The Test Drive Server includes:</p>
<ol>
<li>An updated version of my 30 minutes Test drive for Java developers</li>
<li>A brand new Flex Data Management Services tutorial</li>
<li>Flex/Spring integration samples running &#8220;out-of-the-box&#8221;</li>
<li>Flex/Hibernate integration samples running &#8220;out-of-the-box&#8221;</li>
<li>Flex/JMS integration samples (JMS powered by ActiveMQ) running &#8220;out-of-the-box&#8221;</li>
<li>A new version of my Real Time Market Data application with advanced messaging features: Java API (no JMS in this version), subtopics, etc.</li>
<li>Collaboration Dashboard</li>
</ol>
<p><span id="more-19"></span></p>
<h5>Installation Instructions</h5>
<ol>
<li>Proceed to the Test Drive Server <a href="/download/fds-tomcat.zip">download page</a></li>
<li>Expand fds-tomcat.zip
<p>NOTE: The instructions in the documentation assume that you expand fds-tomcat in your root directory. You can expand fds-tomcat anywhere else. Just make sure you adjust the path in the samples and tutorial instructions accordingly.
</li>
<li>Open install.htm in the fds-tomcat directory for information on running the Test Drive Server.</li>
</ol>
<p>Disclaimer: The Test Drive Server is currently not an officially supported product. I’ll of course do my best to answer your questions, and your feedback is very much appreciated. It is intended to allow Java Developers to quickly evaluate or/and get started with Flex in a Java environment.</p>
<p>ERRATA: On page 4 in the tutorial PDF: “On the Java Settings page, specify fdms-tomcat/classes as the Default output folder, and click Finish”. The name of the folder is incorrect: it should read: Specify “fds-tomcat/classes” as the Default output folder (The screen shot is correct).</p>
<h5>More Info</h5>
<p>The Flex Test Drive Server includes the following products, frameworks, and libraries (All these products are configured to work together “out-of-the-box” when you install the Test Drive Server) :</p>
<ul>
<li><a href="http://tomcat.apache.org/">Tomcat</a> 5.5.20</li>
<li><a href="http://www.adobe.com/products/flex/dataservices/">Flex Data Services</a> (FDS 2.0.1)</li>
<li><a href="http://jotm.objectweb.org/">JOTM</a> (JTA implementation)
<p>The Flex Data Management Services leverage the Java Transaction API (JTA). Because<br />
      Tomcat doesn&rsquo;t provide a JTA implementation, the Test Drive Server includes JOTM (an open source implementation of the Java Transaction API).  You don&#8217;t need JOTM if your application server implements the full Java EE stack.</p>
</li>
<li><a href="http://www.activemq.org">ActiveMQ</a> (JMS implementation)
<p>The Flex Data Services integrate with JMS (see integration examples in the Test Drive Server). Because Tomcat doesn&#8217;t provide a JMS implementation, we use ActiveMQ (an open-source JMS provider) as part of this Test Drive Server. You don&#8217;t need ActiveMQ if your application server implements the full Java EE stack, or if your application doesn&#8217;t use JMS.</p>
</li>
<li><a href="http://www.springframework.org/">Spring</a> 2
<p>Flex integrates with the Spring framework through the Flex SpringFactory (see integration examples in the Test Drive Server). Spring 2 is part of the Flex Test Drive Server to demonstrate this Flex/Spring integration.</p>
</li>
<li><a href="http://www.hibernate.org/">Hibernate</a> 3.2
<p>Flex integrates with the Hibernate through the Flex HibernateAssembler(see integration examples in the Test Drive Server). Hibernate is part of the Flex Test Drive Server to demonstrate this Flex/Hibernate integration.</p>
</li>
<li><a href="http://hsqldb.org/">HSQLDB</a> 1.8
<p>To allow you to run the tutorial &ldquo;out-of-the-box&rdquo; without setting up a database, the Test Drive server<br />
      includes an HSQLDB database. HSQLDB is a lightweight Java RDBMS that is particularly well<br />
      suited to run samples. hsqldb.jar (in [tomcat_root]\webapps\ROOT\WEB-INF\lib) includes both<br />
      the RDBMS engine and the JDBC driver. The HSQLDB database server is automatically started as part of the Tomcat startup process.</p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/feed/</wfw:commentRss>
		<slash:comments>156</slash:comments>
		</item>
		<item>
		<title>Using Flex with Spring</title>
		<link>http://coenraets.org/blog/2006/10/using-flex-with-spring/</link>
		<comments>http://coenraets.org/blog/2006/10/using-flex-with-spring/#comments</comments>
		<pubDate>Tue, 17 Oct 2006 19:47:00 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/2006/10/using-flex-with-spring/</guid>
		<description><![CDATA[Many people in the Java community have recently been asking how to use Flex with the Spring framework, and more specifically, how to remotely invoke Spring beans methods from Flex applications. Spring is one of the most popular Java frameworks. It is based on a lightweight component container that implements the Inversion of Control (IoC) [...]]]></description>
			<content:encoded><![CDATA[<p>Many people in the Java community have recently been asking how to use Flex with the Spring framework, and more specifically, how to remotely invoke Spring beans methods from Flex applications. </p>
<p>Spring is one of the most popular Java frameworks. It is based on a lightweight component container that implements the Inversion of Control (IoC) pattern. Using an IoC container, components don’t instantiate or even look up their dependencies (the objects they work with). The container is responsible for injecting those dependencies when it creates the components (hence the term “Dependency Injection” also used to describe this pattern). The result is looser coupling between components. The Spring IoC container has proven to be a solid foundation for building robust enterprise applications.</p>
<p>The Flex and Spring integration process is actually very straightforward. Based on the interest in combining these technologies, I wrote a document providing background information, configuration information, and three examples with source code.</p>
<p>You can read the “Using Flex with Spring” document <a href="http://coenraets.org/flex-spring">here</a>.</p>
<p>UPDATE (1/12/2007): I put together a Tomcat-based Test Drive Server that includes these samples running out-of-the box. Read <a href="http://coenraets.org/blog/2007/01/flex-test-drive-server-for-java-developers-tomcat-based/">this post</a> for more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2006/10/using-flex-with-spring/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
