After repeatedly performing the same routines—writing Java JDBC calls, declaring the Data Transfer Objects (DTO) in Java and ActionScript, mapping and customizing DataGrid columns and form items, defining standard event handlers—we decided to automate the process. So, we created and used special code templates that do the tedious work and generate the Flex and Java code for us.
The DAOFlex tool that we created takes a Java abstract class containing doclet tags and produces an XML file. Next, it takes the XML file and puts it through XSL Transform to generate the required Java, MXML, and ActionScript code. Finally, an Ant script prepares all configuration files required for deployment on the Java EE application server. Finally, an Ant script compiles and packages Java files required for deployment on the Java EE application server and writes them into destination directories.
Java abstract class, in Listing 1, provides SQL to retrieve data from the database. The tableName tag within Listing 1 specifies the table that is the target of updates, thus DAOFlex has enough information to generate the code for performing the database inserts, updates, and deletes.
/**
* @daoflex:service pool=jdbc/theriabook
*/
import java.util.List;
public abstract class Employee{
/*
* @daoflex:sql transferType= EmployeeDTO[]
* sql=select * from Employee where startDt < :startDate
* tableName=EMPLOYEE
*
* keyColumns=EMP_ID
* updateWhere=key_and_modified
* /
public abstract List getEmployees(Date startDate);
}
Listing 1. The annotated java class, Employee
After running the build script against the sample abstract java class code and updating services configuration on the server to include newly generated services, you'll have a fully functional Flex/Java application deployed to the Java EE application server of your choice. This application can use both Flex Data Services and Flex Remote Objects.
The resulting application will look like Figure 1:
Figure 1. DAOFlex generated application
Along the way, DAOFlex generates and deploys JARs with Java DTO, DAO and Assemblers, sample MXML, ActionScript classes, and XML for configuration files.