FCG : A Flex Code Generator

Posted by HCL - RIA Group in



Install FCG Beta for AIR 1.0 by clicking the following install badge :

This application requires the following be installed:

  1. Adobe® AIR™ Runtime
  2. FCG

Please click on each link in the order above to complete the installation process.

Overview / Features
How to
Release notes
Feedbacks


Overview / Features


FCG is an
AIR application, currently under development, which primary goal is to automatically provide the base code for your RemoteObject based Flex applications. Basically, it means that it reads some code from the server side, and creates a bunch of MXML and AS files to boost your productivity. Its goal is not to create a ready-to-use application, but to provide the tools you need to do so as quickly as possible.

FCG generates code using either the Cairngorm framework or the PureMVC framework. So FCG is both a Cairngorm generator and a PureMVC generator.

There are some differences between FCG and the other (mainly Cairngorm) generators:

  • It does not just create some packages and close-to-empty files : it can read your PHP, Java or C# code and then create the according AS and MXML files.
  • Contrary to some other generators, I chose not to add any personal class to the generated code. I think it should remain the developer's decision to use, say, a super class, for its Commands that could deal with some common issues. It should not be the generator's decision. Of course, one could argue that some of the code generated by FCG is too invasive, but I generally try to do things "by the book".
  • As an AIR application, it runs on your computer, so you don't need to publish anything on a server to make it work.
  • It is independent from any kind of server side technologies (though only PHP, Java and C# files are supported so far) and from any kind of remoting gateway. In fact, with FCG, you could use, say, an AMFPHP service, a WebORB for Java service, and a Fluorine service, in the same Flex project.
  • It allows you to keep control over the generated files. Many developers are a bit skeptical about code generators, and for a good reason : they're afraid to lose control over their code. Most of the time, they assume that the resulting code just "won't fit". Indeed, generators always have to take some decisions that will obviously not satisfy everyone.
    FCG allows you to keep control over the generated files in three ways:

    1. Options, such as defining some ValueObject properties as getter setters, selecting which Service method you want to implement, strongly type their arguments even if it comes from a not strongly typed language such as PHP. Note that C# and Java data types are automatically "mapped" to a default corresponding AS3 type.

    2. Templates : FCG is a Mixed Code Generator. It means that it uses templates you can modify to adapt it to your dirty habits ;)
    Note : you can find the templates directory at user/applicationdata/FCG/ASTemplates (Windows XP) or user/Library/preferences/FCG/ASTemplates (OSX)

    3. You can generate what you want, when you want, and where you want. This means that you absolutely don't have to use all the files that FCG generates for a project. For instance, you can use it to simply create ModelLocators or business delegates for your existing apps, or even just custom event subclasses, and not use anything else.

Now, what's wrong with FCG?

  • It's a beta version. This means that it has bugs, and some things may not work as expected.
  • It only parses PHP, Java and C# files, and the way it does it is really not that good. FCG makes heavy use of regexps, and I'm still pretty new to this topic. There is big room for improvement here.
  • I wish there were many more options to let the users have even better control over the generated files.
  • On the (crowded) Cairngorm code generation space, Steven Webster has announced that Adobe Consulting was working on a Eclipse Plugin which will probably better than FCG in just every aspect... at least we can hope so.
  • And finally, I think we can all agree to say that it's not the sexiest app out there, and its logo just sucks.


How to



Project set up

You first have to set up your project by setting your fully qualified main package name, and choosing your architecture framework. FCG starts by creating some base files :

  • MainView.mxml, which is supposed to be placed in your application root tag (whether it is mx:Application, mx:WindowedApplication or mx:Module)
  • (if using PureMVC) the ApplicationFacade and a StartUpCommand
  • (if using Cairngorm) the ModelLocator, the FrontController, and the ServiceLocator


Adding Value objects

When you add a ValueObject based on a PHP, Java or C# file, FCG generates an AS3 ValueObject. You can specify its attributes type (especially for PHP since it's not strongly typed) and ask it to create it as a getter setter. Optionally, you can generate an Event based on this Object, with constants representing the CRUD operations. If you use Cairngorm, this Event will be a CairngormEvent. If you use PureMVC, it will be a flash.events.Event.

You can also ask FCG to generate two basic views : a Form view (to let the users edit the ValueObject) and a List view (to display a list of these value objects). Since those views are independent from any framework, they dispatch events (the event we just talked about) using a their dispatchEvent() method, not Cairngorm's dispatch() method (neither do they send PureMVC's Notifications).

If you use Cairngorm, the ModelLoactor will be added two properties : an ArrayCollection and a current[Vo]:[VOClass]
property.

If you use PureMVC, a Proxy based on this object is created and, with each view, a Mediator whose job is to listen to its associated view and then send a Notification.

Adding Remote Services

When you add a PHP, Java or C# Remote Service, FCG generates a BusinessDelegate and one Command per Service method/operation. You can specify the methods parameters types, which, again, is especially useful for PHP with which, by default, the type is Object, and so is the default return type of the methods. Java and C# data types for method parameters and return values are automatically converted to a corresponding AS3 data type.

Back to Flex Builder

FCG does not deliver a ready-to-run application. You'll still have to code to get your application working. Here's what you generally do with the generated code (assuming that you've used all the default options):

  • 1. Add the MainView component to your application tag (Application, WindowedApplication or Module)
  • 2.Cairngorm

    Add to the Lists and Forms components the corresponding Model bindings and event dispatch. The List view has a "collection" property (type ArrayCollection) which is supposed to be bound to the [vo]Collection property of your ModelLocator. It disptaches a set[Vo] event when the user selects something in the Datagrid. The Form view has a current[Vo] property that is supposed to be bound to the current[Vo] property of your ModelLocator.

    Edit MainView.mxml to dispatch the first CairngormEvent.

    Edit the registered Commands to set the appropriate delegate methods parameters (if needed, you'll end up with an error if it is).

    Edit the registered Commands to update the Model in their result() methods.

  • 2* PureMVC

    Edit StartUpCommand to send the first Notification.

    Edit your RemoteProxy to update the corresponding Proxy in the result methods.

    Edit your mediators to call the remoteProxy when needed (or optionnally let them sendNotification and have a Command do the job).

You can check a small video preview here by clicking the image below.
The video was made with an early version of FCG, but there is no much difference, excepted that you can also use Java files and that you have more options.
(please excuse my english):




Release Notes


You can download the latest beta version here, but remember that you'll need to have
AIR 1.0 installed. Thanks to Rich Tretola, the application has the ability to auto-update, so that you don't have to wonder if you have the latest version installed.

Latest version is 0.9.6

Main new Features / bug fixes

General

  • New architecture to enable custom extensions (TBD)

Generation Layer

  • You can now choose to generate for code for Flex - not using any architecture framework at all
  • Templates keywords have been normalized (LC prefix refers to lower case on the first char, UP to upper case on the whole word)

UI

  • Auto-complete TextInputs for entering AS3 types
  • It's now possiblie to start a new project without having to close / open FCG
  • Help icons can be disabled/enabled
  • The file tree seems to have a better behavior (although it's still far from being perfect)
  • Application height has be optimized

Analysis layer

  • minor bug fixes

Download FCG for AIR 1.0



This entry was posted on Jun 5, 2008 at 3:37 PM and is filed under . You can follow any responses to this entry through the comments feed .

0 comments

Post a Comment