Prana enabled Cairngorm Store
ActionScript, Cairngorm, Flex, Inversion of Control, Prana 8 Comments »Following up on Douglas McCarroll's modified Cairngorm Store update, I thought I'd take this a step further and add a Prana application context to configure the business delegates and the service locator. This example has support for mock delegates that contain hardcoded local data and is also able to connect to php services using Remote Objects and AMFPHP.
This examples replaces the older Cairngorm Store example that was configured to work with AMF0 and Renaun Erickson's RemoteObjectAMF0. It now uses the latest beta version of AMFPHP and the AMF3 protocol. The services are hosted on this domain so you don't need to setup AMFPHP in order to see this in action.
The code is currently in svn and can be checked out at http://prana.svn.sourceforge.net/viewvc/prana/trunk/samples/PranaCairngormStore/. This sample will also be included in the next release.
Here's a snippet from the readme file:
***
The following files have been added/changed in order to add Prana configuration support for business delegates and service locator:
* Main.mxml: added application context loader and forced compilation of configured classes
package com.adobe.cairngorm.samples.store.business
* BaseBusinessDelegateMock.as: implements IResponderAware, removed responder constructor argument
* CreditCardDelegate.as: extends AbstractRemoteObjectDelegaten, implements ICreditCardDelegate
* CreditCardDelegateMock.as: implements ICreditCardDelegate
* ICreditCardDelegate.as: interface for credit card delegates
* IProductDelegate.as: interface for product delegates
* ProductDelegate.as: extends AbstractRemoteObjectDelegaten, implements IProductDelegate
* ProductDelegateMock.as: implements IProductDelegate
package com.adobe.cairngorm.samples.store.commands
* GetProductsCommand.as: added delegate lookup via ShopModelLocator
* ValidateCreditCardCommand.as: added delegate lookup via ShopModelLocator
package com.adobe.cairngorm.samples.store.model
* ShopModelLocator.as: added creditCardDelegate and productDelegate variables to configure business delegates
***
As a result, we can now lookup the implementation of our business delegates in the commands instead of instantiating new ones. The commands are completely unaware of the implementation of the business delegates. One note though: since we are not creating new delegate instances, we need to set the responder as a property of the delegate before calling its methods.
-
var delegate:IProductDelegate = ShopModelLocator.getInstance().productDelegate;
-
delegate.responder = this;
-
delegate.getProducts();
Here's how the application is configured in the application context to use the mock delegates:
-
<object id="shopModelLocator" class="com.adobe.cairngorm.samples.store.model.ShopModelLocator" factory-method="getInstance">
-
<property name="creditCardDelegate">
-
<object class="com.adobe.cairngorm.samples.store.business.CreditCardDelegateMock"/>
-
</property>
-
<property name="productDelegate">
-
<object class="com.adobe.cairngorm.samples.store.business.ProductDelegateMock"/>
-
</property>
-
</object>
And here's how the remote object delegates and the service locator are configured:
-
<object id="endPoint" class="String">
-
<constructor-arg value="http://www.herrodius.com/amfphp/gateway.php"/>
-
</object>
-
-
<object id="serviceLocator" class="org.pranaframework.cairngorm.CairngormServiceLocator" factory-method="getInstance">
-
<property name="productService">
-
<object class="mx.rpc.remoting.mxml.RemoteObject">
-
<property name="destination" value="GenericDestination"/>
-
<property name="endpoint">
-
<ref>endPoint</ref>
-
</property>
-
<property name="source" value="com.adobe.cairngorm.samples.store.business.ProductService"/>
-
</object>
-
</property>
-
<property name="creditCardService">
-
<object class="mx.rpc.remoting.mxml.RemoteObject">
-
<property name="destination" value="GenericDestination"/>
-
<property name="endpoint">
-
<ref>endPoint</ref>
-
</property>
-
<property name="source" value="com.adobe.cairngorm.samples.store.business.CreditCardService"/>
-
</object>
-
</property>
-
</object>
-
-
<object id="shopModelLocator" class="com.adobe.cairngorm.samples.store.model.ShopModelLocator" factory-method="getInstance">
-
<property name="creditCardDelegate">
-
<object class="com.adobe.cairngorm.samples.store.business.CreditCardDelegate"/>
-
</property>
-
<property name="productDelegate">
-
<object class="com.adobe.cairngorm.samples.store.business.ProductDelegate"/>
-
</property>
-
</object>
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
Christophe Herreman is a software developer living in Belgium. He's working on Flex based e-learning solutions at
Recent Comments