Speaking at the Flex on Java eXchange in London

ActionScript, Air, Conferences, Flex, Spring ActionScript, Talks No Comments »

I’ll be speaking at the first Flex on Java eXchange in London on June 16th. My talk will be an introduction to the Spring ActionScript framework, along with other presentations on Flex and Java connectivity and enterprise Flex development.

From the Skills Matter website:

Skills Matter is pleased to organise the first Flex on Java eXchange. This Annual Flex and Java conference brings together the leading experts on RIA, Flex, Java, Spring and Grails with London’s JEE and web development community, for an informal day of deep technical insight and friendly discussion.

Come learn about Java and Flex integration technologies, MVC frameworks, tools, plugins, best practices and innovative ideas from the creators of those technologies and from the industry’s innovators.

In case you’re in the neighborhood, be sure to join!

More info: http://skillsmatter.com/event/java-jee/flex-on-java-exchange-2010


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

Join us at the AUG RIA event

ActionScript, Air, Flex 1 Comment »

Just a quick note to inform you about the Adobe Usergroup RIA event that is happening Thursday, April 29th in Brussels.

Besides some interesting presentations there will also be a panel discussion on Flex frameworks in which I will participate.

Adobe LiveCycle ES2 Mosaic
Marc Meewis, Adobe
Marc will talk about Mosaic, one of the new products in LiveCycle ES2 for creating contextual workspaces using Flex and AIR.
http://www.adobe.com/products/livecycle/mosaic/

Interaction Design
Namahn
Namahn is a Human-Centered Design consultancy agency from Brussels and will talk about the methods and techniques they use when Designing for user interaction.
http://www.namahn.be/

Workflow
Paul Reijnierse, De Monsters
The Monsters from Amsterdam are Interaction Designers and Paul will talk about how they work and the products they develop.
http://www.demonsters.com/

Flex Frameworks Panel Discussion
Christophe Herreman, Roland Zwaga, Steven Peeters, Ferdi Koomen, Jan Van Coppenolle, …
It’s quite a jungle out there if you need to pick a reliable framework for large Flex applications. This panel of community members will discuss architecture, best practices and the tools they use in their everyday projects.

Doors open at 17:30, sessions start at 18:00.

Date: don, 29/04/2010 – 17:30
Location: Hogeschool Universiteit Campus Stormstraat – Stormstraat 2, 1000 Brussel

For more info and reservations see http://www.adobeusergroup.be/events/ria-sig-event


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

Spring ActionScript: Café Townsend sample application

ActionScript, Air, Design Patterns, Domain-Driven Design, Flash, Flash Builder, Flex, Flex Builder, Inversion of Control, Spring ActionScript 11 Comments »

A new Spring ActionScript sample application is now available. This is the Café Townsend application, originally created as a sample application for the Cairngorm framework, that we ported to Spring ActionScript. This should make it easier to compare this implementation with the implementations of some of the other frameworks.

Open the Café Townsend sample.
(Be sure to check the source by right-clicking and choosing "View Source" from the context menu, click here to go to the source directly.)

Download the Flex/Flash Builder project and sources.

Discussion

In what follows, we will discuss the implementation details and motivate certain choices made in this design.

Package Structure

The first thing you might notice is the package structure, that might seem a bit odd at first since it is different from what most frameworks use or prescribe. This example follows the Layered Architecture, described by Eric Evans in the book Domain-Driven Design: Tackling Complexity in the Heart of Software (recommended reading). This architecture makes it easy to detect and apply the different layers of the application and forces us somewhat to have a clean separation of the responsibilities of each layer.

The layered architecture consists of four layers, as shown on the image below:

  • Presentation Layer: contains the user interface (the view component and in this example the presentation models)
  • Application Layer: coordinates the application and forms a communication channel between the UI and the domain
  • Domain Layer: the core of the software. This layer defines the entities and repositories/services that form the business logic of the application. For the most part only the interfaces for the services will be written here. This layer does not contain any implementation details.
  • Infrastructure Layer: provides implementation details for all other layers. Concrete implementations of services will be put here.

Note that it is certainly not needed to structure your application like this. Spring ActionScript does not impose or prescribe this structure, but we certainly think it is useful and wanted to introduce it in this example. Also note that while we have applied this architecture as packages in the same application, you might want to create different swc's or libraries for each of these layers so that they can easily be reused.

Presentation Layer & Presentation Models

This example uses the Presentation Model (PM) as the main presentation pattern for the UI layer. The PM allows us to extract all state and controller logic for the view into a separate class that is view agnostic. A view component contains a reference to its corresponding PM and delegates all UI actions to it. The view component can either instantiate the PM directly, or it can be given one, either by a parent component or by having it "injected" by the Spring ActionScript framework. The process of automatically injecting properties into a (view) component is known as "Autowiring" in Spring ActionScript. Note that since the PM is not a UI component and does not know anything about the view, it can be easily unit tested.

An example of autowiring can be found in the EmployeeLogin.mxml class:

Actionscript:
  1. [Autowired]
  2. [Bindable]
  3. public var presentationModel:EmployeeLoginPresentationModel;

The PMs used in this example will either delegate directly to the business logic (for instance for loading the employees) or will delegate to the Application Layer (for instance for logging the user out of the application). Here again, there is no strict rule to follow, but you can decide for your own what approach seems the bests.

Note that autowiring is disabled by default. This is because in bigger applications, there might be a significant performance hit when autowiring is used. It is adviced to finetune the autowiring by configuring the autowire processor to include or exclude certain classes. To enable autowiring, simply add the following to the XML configuration:

XML:
  1. <object id="autowiringStageProcessor" class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/>

Application Layer

In some cases, the UI will delegate responsibilities to the Application Layer. Since the UI does not know about this layer, it needs a loosely coupled way of communicating with it. The communication channel that provides this capability in Spring ActionScript is the EventBus. It is implemented on top of Flash's event dispatching capability and forms a centralized medium for component and layer interaction.

In the example, the code behind the Logout button will dispatch an event via the EventBus. The application controller listens for this event and will handle it by invoking the logout method on the authentication service. Notice that the application controller takes the authentication service as a constructor argument and that the service is typed to the interface IAuthenticationService. The actual instance is provided in the (XML) configuration, were both the application controller and the authentication service and defined and linked to eachother.

Notice that the application controller does not explicitely listen for the logout event. Instead, it is sufficient to create a method and annotate it with the [EventHandler] metadata. Spring ActionScript will then introspect the controller, pick up all annotated methods and link them automatically with the event received from the EventBus.

Here's what the logout method looks like in the application controller:

Actionscript:
  1. [EventHandler]
  2. public function logout():void {
  3.   var operation:IOperation = _authenticationService.logout();
  4.   operation.addCompleteListener(logout_completeHandler);
  5. }

Notice that the name of the logout method corresponds to the event being dispatched, namely "logout" (see the ApplicationEvents class for that). You can however also choose the name of this method as you like and specify the name of the event as an attribute of the EventHandler metadata.

As with autowiring, the processing of the EventHandler metadata is not enabled by default. If you want to use this in your application, simply add the following to the XML configuration:

XML:
  1. <object id="eventHandlerProcessor" class="org.springextensions.actionscript.ioc.factory.config.EventHandlerMetaDataPostProcessor"/>

For more information on the EventBus, please refer to the documentation.

Domain Layer

The domain for this application is extremely simple. All it contains is an Employee entity and an employee service in the form of the IEmployeeService. Except for the actual entities of the domain, this layer does not contain any implementation details for the services it provides, but merely defines the interfaces for those services.

Infrastructure Layer

The infrastructure layer is where the technical details of the applications live. This layer provides the actual implementation of the services found in the other layers. Depending on the different contexts the application needs to be able to run in, you might provide different implementations of the services here. The implementations used in the application can then be defined the a Spring ActionScript Application Context. As an example, think of an application that needs to be able to connect to a set of services using Remote Objects in one scenario and needs to connect to a set of Webservices in another scenario. If we provide both implementations, we can easily reconfigure the application by changing the XML configuration of the application context.

Application Context

Once we have all components, we can bundle them together and prepare them to be used in the application. By doing this, we are configuring the context of the application. In Spring ActionScript this is done by instantiating a FlexXMLApplicationContext (in case you are working with Flex).

The application context in this example is configured using XML, but it could just as easily be configured using an MXML configuration. Both approaches have there pros and cons and you should decide what fits best for you project.

Looking at the Main.mxml class, which is the entry point of the application, we can see that a FlexXMLApplicationContext is instantiated and given the path to the external XML file (application-context.xml) that forms the application context's configuration. Now all we need to do is wait for the context to load before starting the application.

Conclusion

This example contains significantly less code than the original Cairngorm version. This is mainly because Spring ActionScript does not impose any strict architectural rules and provides the developer with plenty of choice for architecting things that best fit the application being developed. What might work in application A might not necessarily work well for application B or C. Being given so much freedom and choice might feel awkward at first, but you will notice that this is actual a good thing and you will benefit greatly from it.

If you have any remarks on this post, please leave them in comments or contact me. Whether they are errors, things that are unclear, or general questions... all feedback is welcome.

General information and document about Spring ActionScript can be found at http://www.springactionscript.org/

Related articles:


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

Spring ActionScript: The Operation API

ActionScript, Air, Flash, Flex, Spring ActionScript 2 Comments »

Introduction

As Flex and Flash developers, we are used to working with asynchronous code. Whenever we load data from a server for instance, we need to wait for the result to come back as we can't just read the result of such a call directly. The way in which we wait for these asynchronous calls to complete differs from API to API. There are events, async tokens, callback functions, ... The fact that there is no unified approach to this, is a core problem in our opinion of Flash. It is not only confusing to developers, but it also prevents us from easily integrating these various techniques and abstracting away their details.

Consider a service that manages User objects by providing basic operations on these entities like create, read, update and delete (CRUD). If you plan on creating an interface for this user service so you can vary the implementation easily, what return type would the methods have?

Actionscript:
  1. public interface IUserService {
  2.   function addUser(user:User): ? ;
  3.   function deleteUser(user:User): ? ;
  4.   function saveUser(user:User): ? ;
  5.   function loadAllUsers(): ? ;
  6. }

We could either:

  • return nothing and wait for events to be dispatched by the service when its methods have executed: this has the disadvantage that there is no real contract on the method.
  • return nothing and pass in a Responder or result and fault handler callback functions: this has the disadvantage that it blurs the signature of the service method with technical details.
  • return an AsyncToken: this is a stricter contract, but it would tie our code to the Flex framework and it would only work if you create implementations that support AsyncToken

In general, the biggest problem is that there is no standard way of defining an asynchronous execution in the Flash Player.

Operation API

The solution Spring ActionScript provides comes in the form of the Operation API. This is a set of interfaces and classes that enables developers to work with asynchronous processes in a uniform fashion. An "operation" in Spring ActionScript vocabulary is the term used for an asynchronous execution and is defined by the IOperation interface. Once an operation is created, it executes immediately and when it is done executing, it either dispatches a "complete" event or an "error" event.

Going back to our user service, this means that we would type all return types of its (asynchronous) methods to IOperation:

Actionscript:
  1. public interface IUserService {
  2.   function addUser(user:User):IOperation;
  3.   function deleteUser(user:User):IOperation;
  4.   function saveUser(user:User):IOperation;
  5.   function loadAllUsers():IOperation;
  6. }

Whether you now have an implementation that uses Remote Objects, Webservices, locally loaded XML data, a local SQLite database, ... clients working with the user service should not know and care about implementation details. All that they know is that asynchronous methods return an operation to which they can attach listeners to for dealing with the result or error of the call.

A client calling one of these methods might to something like the following, considering there is a userService of type IUserService:

Actionscript:
  1. var user:User = new User("John", "Doe");
  2. var operation:IOperation = userService.saveUser(user);
  3. operation.addCompleteListener(saveUser_completeHandler);
  4. operation.addErrorListener(saveUser_errorHandler);
  5.  
  6. function saveUser_completeHandler(event:OperationEvent):void {
  7.   // user was saved
  8.   // event.result contains an optional result of the asynchronous method
  9. }
  10.  
  11. function saveUser_errorHandler(event:OperationEvent):void {
  12.   // user was not saved, since an error occurred
  13.   // event.error contains error information
  14. }

Notice that each operation has the convenience methods "addCompleteListener" and "addErrorListener" for listening to the events dispatched by the operation. The handlers for these events receive an instance of the OperationEvent which contains either the result or the error details.

We have also included some base classes that make it easy to create operations and services. The AbstractOperation class for instance provides a basic implementation of the IOperation interface and implements the event dispatching functionality. You might want to extend this class if you create your own operations.

Here's an example of a custom operation:

Actionscript:
  1. public class MyOperation extends AbstractOperation {
  2.  
  3.   public function MyOperation() {
  4.     // execute something asynchronously
  5.     // the resultHandler and errorHandler deal with the result of fault
  6.   }
  7.  
  8.   private function resultHandler(aResult:Object):void {
  9.     dispatchCompleteEvent(aResult);
  10.   }
  11.  
  12.   private function errorHandler(anError:Object):void {
  13.     dispatchErrorEvent(anError);
  14.   }
  15.  
  16. }

Notice that we call the "dispatchCompleteEvent" and "dispatchErrorEvent" on either success or failure. We pass in the result or the error we received. These will internally be set on the operation so that clients can request them via the OperationEvent.

The Spring ActionScript framework also contains a series of operation implementations for working with Remote Objects, NetConnections, etc.

Combining Operations into Services

Taking this a step further, we also provide base classes for creating services that consist of operations. Going back to our user service, we might create an implementation that uses RemoteObject by subclassing the RemoteObjectService class. This class provides basic functionality for delegating to the underlying Remote Object. Here's an example:

Actionscript:
  1. public class UserService extends RemoteObjectService implements IUserService {
  2.  
  3.   public function UserService(remoteObject:RemoteObject) {
  4.     super(remoteObject);
  5.   }
  6.  
  7.   public function addUser(user:User):IOperation {
  8.     return call("addUser", user);
  9.   }
  10.  
  11.   public function deleteUser(user:User):IOperation {
  12.     return call("deleteUser", user);
  13.   }
  14.  
  15.   public function saveUser(user:User):IOperation {
  16.     return call("saveUser", user);
  17.   }
  18.  
  19.   public function loadAllUsers():IOperation {
  20.     return call("loadAllUsers");
  21.   }
  22.  
  23. }

Notice how easy it is to abstract away the use of a remote object and make clients unaware of this by only providing them with the IUserService interface. The "call" method is a very convenient method to forward the call to the remote object, without having to take care of AsyncTokens and Reponders.

Progress Operations

For operations that take longer to execute the IOperation interface has a subinterface called IProgressOperation. This might for instance be the loading of a sound file, a module, etc. Implementations of this interface can let clients know about the progress the operation made by dispatching progress events at certain intervals. When listening for these events, via the "addProgressListener" method, a ProgressOperationEvent is received that contains a "progress" and "total" property.

Actionscript:
  1. var loadSoundOperation:IProgressOperation = new MyLoadSoundOperation("aSoundFile.mp3");
  2. loadSoundOperation.addProgressListener(loadSoundOperation_progressHandler);
  3.  
  4. function loadSoundOperation_progressHandler(event:ProgressOperationEvent):void {
  5.   trace("Loaded " + event.progress + " of " + event.total + " bytes");
  6. }

Batch Operations

When you are in a scenario where you need to execute several operations and you don't care about the order in which they finish, you might want to use the OperationQueue class. This is an implementation of the IProgressOperation interface that lets you add operations to a queue and receive information about the progress of the complete execution. Since this also is an IOperation, we can listen to the completion of the queue via the "addCompleteListener" method.

Actionscript:
  1. var queue:OperationQueue = new OperationQueue();
  2.  
  3. // setup event listeners
  4. queue.addCompleteListener(queue_completeHandler);
  5. queue.addProgressListener(queue_progressHandler);
  6.  
  7. // add operations to the queue
  8. queue.addOperation(new AnOperation());
  9. queue.addOperation(new AnotherOperation());
  10. queue.addOperation(new YetAnotherOperation());
  11.  
  12. function queue_completeHandler(event:OperationEvent):void {
  13.   trace("Queue is done executing.");
  14. }
  15.  
  16. function queue_progressHandler(event:ProgressOperationEvent):void {
  17.   trace("Executed " + event.progress + " of " + event.total + " operations");
  18. }

Mocking Operations

During development it is often good to have mock or stub implementations of the services that normally connect to a backend. The main reason is that this provides a way of (unit) testing the use of the services without the backend running. Spring ActionScript provides a class called MockOperation for this purpose. Its constructor takes the following arguments:

  • result: the result returned by the operation
  • delay (optional): the time the operations waits before completing, in milliseconds (default = 1000)
  • returnError (optional): a flag indicating wether or not the operation should return an error at random times (default = false)

If you would mock the user service, you could do this as follows (only one method is implemented):

Actionscript:
  1. public function loadAllUsers():IOperation {
  2.   var users:ArrayCollection = new TypedCollection(User);
  3.   users.addItem(new User("John", "Doe"));
  4.   users.addItem(new User("Mitch", "Hedberg"));
  5.   return new MockOperation(users);
  6. }

Conclusion

The Operation API provides a neat way of abstracting away technical details and makes it easier to swap implementations without affecting any code. It unifies asynchronous programming for the Flash Player into a simple set of interfaces and base classes. You will also see that it is the basis for other APIs in the Spring ActionScript framework such as the Command and Task API.

For more information on Spring ActionScript, refer to www.springactionscript.org


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

Spring ActionScript 1.0RC1 Released

ActionScript, Air, Flex, Inversion of Control, Spring ActionScript 5 Comments »

Dear community,

I'm pleased to announce that the first release candidate for Spring ActionScript 1.0 is now available.

Download | API Documentation | HTML Docs | Changelog

This release is considered feature complete and announces the final stage before moving to a final 1.0 release.

Amongst the many updates and fixes, these are the most important ones:
- Operation API (docs, blog)
- EventBus (docs)
- Task API (docs)
- MXML Configuration (docs)

These changes will be discussed in a couple of follow-up blogposts, so please check back soon for that. In the meantime, please refer to the documentation provided for more information.

I would like to thank all of you who have given us valuable feedback and provided interesting ideas, sent in patches, reported bugs or helped us out in whatever way possible. Your support has been priceless in the development of this framework and it would not be as rich as it is now without you.

Special thanks go out to Martino for mastering the Maven build system and fixing a lot of the problems that stopped us from releasing earlier, and to Roland who has written 99,9% of the AWESOME documentation and took a natural lead in the development of 1.0RC1. You guys rock!

Enjoy this release and have fun coding!

Spring ActionScript 1.0RC1 Changelog

  • fixed constructor-arg type attribute was not declared in spring-actionscript-objects-1.0.xsd.

    config reference link

  • added unregisterStageProcessor() method to the IStageProcessorRegistry interface.

    ASDoc link

  • added DefaultFlexAutowireProcessor that handles binding using the [Autowired(name="objectName",property="property.chain")] metadata.

    documentation link

  • added PureMVC documentation section.

    puremvc documentation link

  • added autowiring support for injecting external property values using [Autowired(externalProperty="propertyName")].

    documentation link

  • added parent context support to IObjectFactory interface and AbstractObjectFactory implementation.

    documentation link

  • added skip-postprocessor and skip-metadata support for ObjectDefinition.

    skip-metadata link

    skip-postprocessor link

  • added name and value attribute support to the property XML element, for defining external properties directly in the configuration instead of an external properties file.

    docs link

  • added parent properties support to XMLObjectFactory.

    docs link

  • added IStageProcessorRegistry interface and FlexStageProcessorRegistry implementation to support stage wiring in a multi-module situation (Thanks to Arnoud for helping debug this).

    docs link

  • added extra functionality to the CairngormFrontController that enables to add commands that are being created by the application context (basically using the context as a commandFactory).

    cairngorm docs link

  • renamed SASCairngormEvent to SASCairngormModuleEvent.

    cairngorm docs link

  • ObjectUtils no longer has a dependency on the Flex framework.
  • added core.* package containing the Operation API.

    operation docs link

  • added core.event.* package containing the EventBus classes.

    eventbus docs link

  • added EventHandlerMetaDataPostProcessor for automatic handling of EventBus events.

    eventbus docs link

  • added parallel or sequencential execution to CompositeCommand class.

    operation docs link

  • added core.task.* package.

    operation docs link

  • added support for property chain retrieval in the FieldRetrievingObjectFactory, for example: Application.application.systemManager.stage can now be retrieved.
  • added support for compound property names in XML config.
  • added support for factory-object in AbstractObjectFactory..

    link

  • added TaskNamespaceHandler for core.task.* package.

    link

  • added createInstance(clazz:Class, constructorArguments:Array = null) method to the IObjectFactory interface to enable a factory to create objects with only annotations and have no object definition.

    link

  • added operation and service for remoting via NetConnection.

    link

  • added support for vector type in XML configuration..

    link

  • Allow adding mx.flash.Event items to EventSequence and facilitate custom trigger calculation. (Thanks Jurgen).
  • Added modulePolicy of type ModulePolicy to FlexStageProcessorRegistry that determines how modules will be handled.
  • Minor documentation fixes. (Thanks Mark).
  • added RouteEventsMetaDataPostProcessor to re-route events from arbitrary objects through the EventBus.

    link

  • Added IApplicationDomainAware and ApplicationDomainAwarePostProcessor to automatically inject the context's application domain in objects that need a reference.
  • Added MethodInvokingFactoryObject to be able to inject method results from other objects.

    link

  • Added util:invoke element as a configuration shortcut for the MethodInvokingFactoryObject.

    link

  • Added support for injecting the application context by using ref="this" in the configuration.

    link

  • Added Maven mojo to generate a flex-config file from an application context (Thanks Ryan).

    link


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 Log in