FCG : a Flex Code Generator
Updated on August, 25th 2008
This project is now officially discontinued.
Please read this entry for more infos.
This is the content that would be shown if the user does not have Flash Player 6.0.65 or higher installed.
Menu
Overview / Features
How to
Download & Release Notes
Source code
Feedbacks
Overview / Features
FCG is an AIR application 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. Note that it can also generate Flex only (non framework related ) code, but in this case the productivity value of FCG in less obvious.

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?
- Despite all my efforts, the application still has bugs (and probably always will), 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 version here, but remember that you'll need to have AIR 1.1 installed. The application has the ability to auto-update, so that you don't have to wonder if you have the latest version installed.
Warning : users of FCG prior to v 1.0 will have to upgrade manually by reinstalling the air package from here, as the previous update mechanism won't work.
Latest version is 1.0
Main new Features / bug fixes
General
- AIR 1.1 build
- Adobe AIR update framework implemented in replacement to Rich Tretola's
Source code
During the main development phase, I tried to find a way to allow some sort of plugin functionnality to FCG so that users would be able to easily add their own code parsers and generators and share it with the community. Unfortunately, after a lot of time spent on rewriting the whole architecture, I had to face the fact that I was unable to properly deliver this feature.
So the only way for me to let users adapt FCG to their needs is to simply release the whole source code (the code is release under GNU GPL licence), which comes in two parts :
- FGL : a Flex library which deals with the whole code parsing and code generation. This library is air independant.
- FCG : an AIR application that a GUI for accessing the functionnalities of FGL
-
Download the source code
Note :If you use FlexBuilder, you'll have to change the properties of the FCG project >library path > FGL and target the FCL swc file on your computer.
If you need, say, to add support for a new Flex framework, you'll first have to create the corresponding IGenManager class in FGL. Then, you'll have to create the corresponding user interface (OperationDialog classes) in FCG.
Be warned : this can be a lot of work. The source code is (not enough) commented but doesn't come with a proper developer documentation, and it probably never will. However, I'll be glad to answer your questions by email.
I won't create any public code repository anytime soon neither. First because I simply don't have enough time for this, and second because I'm not sure what my commitment to the project will be in the near future. Moreover, Flex productivity is a topic which has finally been taken seriously, both by Adobe (see Flex 4 specs) and third parties - more on that on a later post. So I'm not sure FCG's model will be relevant in the future months.
That said, if you want to get involved with the project (not only adapt it to your private needs), then let me know by contacting me (see below). I'm open to any reasonable proposition.
Feedbacks
Of course, I'd love to hear what you guys have to say about it, so feel free to leave me comments, or to contact me via my contact page.
| Attachment | Size |
|---|---|
| FCGFGL_SRC.zip | 3.29 MB |
| FCG_PureMVCMulticore_Yishay_Weiss.rar | 7.59 MB |
