Oct 17
In case you haven’t read this, Tony Hillerson has posted an article on configuring a Business Delegate Factory for Cairngorm with Prana. This allows you to quickly switch between different implementations for testing or production purposes.
Read it at http://thillerson.blogspot.com/2007/10/delegate-factories-with-prana.html
It’s good to see that the community is picking up Prana and benefits from it. Keep on supporting the project guys, thx!
Add to Bloglines -
Digg This! -
del.icio.us -
Stumble It! -
Twit This! -
Technorati links -
Share on Facebook -
Feedburner
Oct 10
Once in a while, when adding event/command mappings in Cairngorm's frontcontroller, I mistakingly add an event instead of a command class to the addCommand() method. Here's an example:
Actionscript:
-
addCommand(UserEvent.LOAD, LoadUserEvent);
while it really should be:
Actionscript:
-
addCommand(UserEvent.LOAD, LoadUserCommand);
This is just a mistake when typing fast and with code completion but it can take a while until you find out what you did wrong. To prevent this, I decided to override addCommand() in Prana's CairngormFrontController and add in a check to see if the commandRef argument actually is an implementation of ICommand.
You can checkout this code from Prana's SVN if you like, or you can build a custom version of Cairngorm with the following code:
Actionscript:
-
public function addCommand(commandName:String, commandRef:Class, useWeakReference:Boolean = true ):void {
-
if (commands[ commandName ] != null )
-
throw new CairngormError( CairngormMessageCodes.COMMAND_ALREADY_REGISTERED, commandName );
-
-
if (null == commandRef) {
-
throw new Error("The commandRef argument cannot be null");
-
}
-
else {
-
var classDescription:XML = describeType(commandRef) as XML;
-
var implementsICommand:Boolean = (classDescription.factory.implementsInterface.(@type == getQualifiedClassName(ICommand)).length() != 0);
-
if (!implementsICommand)
-
throw new Error("The commandRef argument '" + commandRef + "' should implement the ICommand interface");
-
}
-
-
commands[ commandName ] = commandRef;
-
CairngormEventDispatcher.getInstance().addEventListener( commandName, executeCommand, false, 0, useWeakReference );
-
}
This should save you some time in the future.
On a side note, I have been working on an alternative approach to chaining events/commands in Cairngorm. The code is already in Prana's SVN but I haven't had the time to blog about this. Check it out if you're interested and mail me if you want a code example. In the meantime, I'll work a blogpost with an example on how to use it and will publish this by the end of the week.
Happy coding!
Add to Bloglines -
Digg This! -
del.icio.us -
Stumble It! -
Twit This! -
Technorati links -
Share on Facebook -
Feedburner
Apr 30
I just added a new example application to the Prana SVN Repository. The sample application lets you search for movies based on the name of a director you specify. It is based on the MovieLister example that Martin Fowler describes in his "Inversion of Control Containers and the Dependency Injection pattern" article. I figured this would be a far simpler example than the modified Cairngorm Store.
Read the rest of this entry »
Add to Bloglines -
Digg This! -
del.icio.us -
Stumble It! -
Twit This! -
Technorati links -
Share on Facebook -
Feedburner
Apr 17
The Prana Framework I mentioned last week (here and here), has now been added to SourceForge.
In short, Prana is an Inversion of Control (IoC) Container written in ActionScript 3. It is a non-intrusive API for configuring Flash/Flex/Apollo applications. The library also contains general utilities. Possible additions may include an AOP framework and Mock Objects support for FlexUnit.
Check it out at http://sourceforge.net/projects/prana/.
A user mailinglist is available at https://lists.sourceforge.net/lists/listinfo/prana-user
Developers interested in sharing ideas or joining in for development can contact me at info{at}herrodius.com.
Add to Bloglines -
Digg This! -
del.icio.us -
Stumble It! -
Twit This! -
Technorati links -
Share on Facebook -
Feedburner
Apr 10
Yesterday I introduced the Prana IoC framework for AS3 I'm working on. The example showed how to create an external configuration file that defines the remote services used in the sample application and configures the ServiceLocator. Today I wanted to go a step further and write a config section for the FrontController.
I introduced the CairngormFrontController class that extends Cairngorm's FrontController and lets you pass in commands to the constructor. It then calls the "addCommand()" method on every command found in the constructor argument which results in a configured FrontController instance.
The following object definition was added to the applicationContext.xml file:
XML:
-
<object id="shopController" class="be.indiegroup.prana.ioc.util.CairngormFrontController">
-
<constructor-arg>
-
<object>
-
<property name="getProducts" value="GetProductsCommand"/>
-
<property name="addProductToShoppingCart" value="AddProductToShoppingCartCommand"/>
-
<property name="deleteProductFromShoppingCart" value="DeleteProductFromShoppingCartCommand"/>
-
<property name="filterProducts" value="FilterProductsCommand"/>
-
<property name="sortProducts" value="SortProductsCommand"/>
-
<property name="validateOrder" value="ValidateOrderCommand"/>
-
<property name="validateCreditCard" value="ValidateCreditCardCommand"/>
-
<property name="completePurchase" value="CompletePurchaseCommand"/>
-
</object>
-
</constructor-arg>
-
<constructor-arg value="com.adobe.cairngorm.samples.store.command"/>
-
</object>
The first argument is the object that contains the mapping between the event names and the command classes. The second argument is optional and defines the package where the command classes reside. By specifying this argument, you don't need to define the fully qualified classnames of the commands.
We can now leave out the ShopController class, but beware: we need to make sure that the command classes get compiled in the swf of our application. We can do this by referencing them in our application. We'll also reference the CairngormFrontController class:
Actionscript:
-
private var _cairngormFrontController:CairngormFrontController;
-
private var _commands:Array = [GetProductsCommand, AddProductToShoppingCartCommand, DeleteProductFromShoppingCartCommand, FilterProductsCommand, SortProductsCommand, ValidateOrderCommand, ValidateCreditCardCommand, CompletePurchaseCommand];
We can also comment out the reference to the ShopController in the main application file:
XML:
-
<!-- the FrontController, containing Commands specific to this appliation -->
-
<!--<control:ShopController id="controller" />-->
We are now able to ignore certain view events by leaving out the mapping from the shopController definition. In this application it probably doesn't make much sense, but occasions may arise where this functionality is wanted.
Download Prana 0.1.1
Prana Framework 0.1.1
Prana Framework 0.1.1 with dependencies
Cairngorm Store Sample
- Download Prana on SourceForge: Prana SourceForge page
Add to Bloglines -
Digg This! -
del.icio.us -
Stumble It! -
Twit This! -
Technorati links -
Share on Facebook -
Feedburner
Recent Comments