Templates in Prana’s application context

ActionScript, Flex, Prana 10 Comments »

With the latest release of the Prana Framework came some great new features. One of them is support for templates in an application context. It came to our attention that when defining services, most of the application context was actually doing the same thing, namely defining let's say a remote object, but each time with a different service class.

Consider the following:

XML:
  1. <object id="serviceLocator" class="org.pranaframework.cairngorm.CairngormServiceLocator" factory-method="getInstance">
  2.   <property name="assetService">
  3.     <object class="mx.rpc.remoting.mxml.RemoteObject">
  4.       <property name="destination" value="GenericDestination"/>
  5.       <property name="endpoint" ref="remoteGateway"/>
  6.       <property name="source" value="ApplicationDomain.Services.AssetService"/>
  7.     </object>
  8.   </property>
  9.   <property name="packageService">
  10.     <object class="mx.rpc.remoting.mxml.RemoteObject">
  11.       <property name="destination" value="GenericDestination"/>
  12.       <property name="endpoint" ref="remoteGateway"/>
  13.       <property name="source" value="ApplicationDomainDomain.Services.PackageService"/>
  14.     </object>
  15.   </property>
  16.   <property name="userService">
  17.     <object class="mx.rpc.remoting.mxml.RemoteObject">
  18.       <property name="destination" value="GenericDestination"/>
  19.       <property name="endpoint" ref="remoteGateway"/>
  20.       <property name="source" value="ApplicationDomainDomain.Services.UserService"/>
  21.     </object>
  22.   </property>
  23. </object>

We're defining our ServiceLocator here with 3 services. You can quickly see that there is a lot of repetitive code in there, and we only have defined 3 services. Adding other services makes the application context really big and harder to read. (On a sidenote: notice the support for inner object/bean declarations).

The problem was solved by introducing template definitions. It allows you to create a template object and set some variables in it, using ant style parameters. You can then create a new object, tell the container that it must be based on a template and pass in the necessary parameters.

Here's an alternative application context to the previous one, but this time using a template for the remote object definition.

XML:
  1. <template id="remoteObject">
  2.   <object class="mx.rpc.remoting.mxml.RemoteObject">
  3.     <property name="destination" value="GenericDestination"/>
  4.     <property name="endpoint" ref="remoteGateway"/>
  5.     <property name="source" value="ApplicationDomain.Services.${serviceClass}"/>
  6.   </object>
  7. </template>
  8.  
  9. <object id="serviceLocator" class="org.pranaframework.cairngorm.CairngormServiceLocator" factory-method="getInstance">
  10.   <property name="assetService" template="remoteObject">
  11.     <param name="serviceClass" value="AssetService"/>
  12.   </property>
  13.   <property name="packageService" template="remoteObject">
  14.     <param name="serviceClass" value="PackageService"/>
  15.   </property>
  16.   <property name="userService" template="remoteObject">
  17.     <param name="serviceClass" value="UserService"/>
  18.   </property>
  19. </object>

So we create a new template using the "template" tag with inside of it the object definition. Notice that the object definition has a variable ${serviceClass} defined. This variables will be filled in by the container when instantiating objects from a template definition. In the service locator, we create our services and tell them that they are based on the "remoteObject" template. We pass in the correct parameter and off we go.

Of course with small application contexts that only define 1 or 2 services, it might not really be worth using templates, although it could improve readability.

Hope you find this a valuable addition to Prana. We are allows eager to find out about new ideas that could benefit us all. So if you have any, be sure to contact us.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Prana 0.3 released!

ActionScript, Cairngorm, Flex, Prana 1 Comment »

I'm proud to announce that Prana 0.3 has been released.

Some of the key features and updates:

  • major update to the core IoC container
  • support for templates in the application context (blog post)
  • support for initializing objects in the application context (Log example)
  • compliancy with Spring application contexts
  • event sequencing in Cairngorm (blog post)
  • several utilities

In the coming days, I'll post some more about the new features.

General info: http://www.pranaframework.org
Download: SourceForge Download Page

Changes in version 0.3 (24.11.2007)
-----------------------------------

General
* added Movie sample application based on article by Martin Fowler
* improved documentation
* moved Cairngorm related classes to org.pranaframework.cairngorm
* Cairngorm Store sample now has different configuration of service locator

Package org.pranaframework.cairngorm
* added support for event sequencing
* CairngormFrontController now checks for commands implementing the ICommands interface
* implementation of CairngormServiceLocator

Package org.pranaframework.errors
* added ClassNotFoundError for retrieving a class by name when class was not found

Package org.pranaframework.ioc
* added serializer to create an application context from an object
* added support for initializing object with IInitializingObject
* added support for templates in application context
* added support for <map> definitions, parsed to Dictionary
* added support for <list> definitions, parsed to ArrayList
* made container spring context compliant
* improved error handling when creating object from object definitions
* rewrote preprocessing of xml application context, now using chain of preprocessors
* fixed creation of object without id, id is now auto generated
* fixed order for object definitions so that they no longer need to be chronological

Package org.pranaframework.reflection
* added metadata introspection
* added "getFullName" method to Method class
* changed arguments in "invoke" method from ... to array

Package org.pranaframework.utils
* added "forName" method in ClassUtils for retrieving Class objects via class names
* added "getParentClass" method in ClassUtils that returns the parent class of a given class
* added "isSubclassOf" method in ClassUtils that returns if a class extends another class
* added StringUtils
* added DisplayObjectContainerUtils
* added MethodInvoker to support initializing objects from application context
* added "state" method to Assert class
* changed TypeConverter so that it can return Class objects


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

www.pranaframework.org

ActionScript, Flex, Prana No Comments »

Prana Framework

The Prana Framework now has a home at www.pranaframework.org!

Prana is an Inversion of Control (IoC) Container for ActionScript 3.0. It enables you to configure objects and components in a non-intrusive way by describing them in an external xml document and having them loaded at runtime.

At its core is a Spring-ish application context and IoC container. Though not a literal port of the Spring core, the xml dialect for the application context is aimed to be Spring compliant.

Further, the framework also contains utility classes for configuring and extending Cairngorm applications, a Reflection API and general utilities. In the future we’ll be looking into adding AOP support and Mock objects for FlexUnit, and we’re always open for suggestions.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Configuring mx.logging.Log with Prana

ActionScript, Flex, Prana 10 Comments »

The Logging API contained withing the Flex Framework allows you to control the messages logged in an application. By controlling, I mean filtering log messages by the package or class name they were logged from, and by their level (ALL, DEBUG, INFO, WARN, ERROR, FATAL).

Logging messages is done by calling one of the log methods on an ILogger instance, e.g. logger.debug("I'm a log message"), and replaces the need to call trace(). The Logging API offers standard support for logging to the console using the TraceTarget and you can also create your own log targets by implementing the ILoggingTarget interface.

Read the rest of this entry »


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

Tony Hillerson on Cairngorm Business Delegates with Prana

ActionScript, Cairngorm, Design Patterns, Flex, Prana 2 Comments »

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
 
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login