AMF Module
The AMF deployment module generates the server-side and client-side libraries used to support an
Action Message Format API. The client-side
library is a set of ActionScript classes that are
type-safe wrappers around the ActionScript remoting API that are designed to add clarity and to be easy
to consume for Flex development. Furthermore, the server-side support classes add an extra degree of security to
your Data Services by ensuring that only your public methods are made available for invocation via AMF. There is
also support for invoking the Adobe Flex compiler to compile
a set of Flash applications that can be added to your
Enunciate-generated web application.
The AMF API leverages the Blaze DS package that was recently made
available as an open source product by Adobe. To use the AMF module, you will have to have the
Flex SDK installed.
This documentation is an overview of how to use Enunciate to build your Flex Data Services (AMF API) and associated Flash
application(s). The reader is redirected to the documentation for Flex for
instructions on how to use Flex. There are also two sample applications you may find useful, petclinic and addressbook, that you
will find bundled with the Enunciate distribution.
Steps
generate
The "generate" step generates all source code for the AMF API. This includes server-side support classes and client-side
ActionScript classes that can be used to access the API via AMF.
compile
During the "compile" step, the AMF module compiles the code that was generated. The generated client-side ActionScript
classes are compiled into an SWC file that is made available as an Enunciate artifact. The SWC file can also be made
available as a download from the deployed web application (see the configuration). It is also during the "compile" step that
the Flex compiler is invoked on any Flex applications that are specified in the configuration.
Configuration
The AMF module is configured by the "amf" element under the "modules" element of the enunciate configuration file. The
AMF module is disabled by default because of the added constraints applied to the service endpoints and because of the additional
dependencies required by the module. To enable AMF, be sure to specify disabled="false" on the "amf" element.
The "amf" element supports the following attributes:
- The "flexHome" attribute must be supplied. It is the path to the directory where the Flex SDK is installed.
- The "label" attribute is used to determine the name of the client-side artifact files. The default is the Enunciate project label.
- The "swcName" attribute specifies the name of the compiled SWC. By default, the name is determined by the Enunciate
project label (see the main configuration docs).
- The "swcDownloadable" attribute specifies whether the generated SWC is to be made available as a download from the
generated web application. Default: "false".
- The "asSourcesDownloadable" attribute specifies whether the generated ActionScript source files are downloadable from
generated web application. Default: "false".
- The "mergeServicesConfigXML" attribute specifies the services-config.xml file that is to be merged into the Enunciate-generated
services-config.xml file. No file will be merged if none is specified.
- The "enforceNoFieldAccessors" attribute specifies whether to enforce that a field accessor cannot be used for AMF mapping.
Note: whether this option is enabled or disabled, there currently MUST be a getter and setter for each accessor. This option only
disables the compile-time validation check.
The "war" element
The "war" element under the "amf" element is used to configure the webapp that will host the AMF endpoints and Flex applications. It supports
the following attributes:
- The "amfSubcontext" attribute is the subcontext at which the amf endpoints will be mounted. Default: "/amf".
- The "flexAppDir" attribute is the directory in the war to which the flex applications will be put. The default is the root of the war.
The "compiler" element
The "compiler" element under the "amf" element is used to configure the compiler that will be used to compile the SWC
and the Flex applications. It supports the following attributes, associated directly to the Flex compiler options. For details,
see the documentation for the Flex compiler.
- contextRoot (default: the Enunciate project label)
- flexConfig (default: "$FLEX_SDK_HOME/frameworks/flex-config.xml")
- locale (default: unspecified)
- optimize (boolean, default: unspecified)
- debug (boolean, default: unspecified)
- profile (boolean, default: unspecified)
- strict (boolean, default: unspecified)
- useNetwork (boolean, default: unspecified)
- incremental (boolean, default: unspecified)
- warnings (boolean, default: unspecified)
- showActionscriptWarnings (boolean, default: unspecified)
- showBindingWarnings (boolean, default: unspecified)
- showDeprecationWarnings (boolean, default: unspecified)
- flexCompileCommand (default "flex2.tools.Compiler")
- swcCompileCommand (default "flex2.tools.Compc")
The "compiler" element also supports the following subelements:
- "JVMArg" (additional JVM arguments, passed in order to the JVM used to invoke the compiler, supports a single attribute: "value")
- "arg" (additional compiler arguments, passed in order to the compiler)
- "license" (supports attributes "product" and "serialNumber")
The "app" element
The AMF module supports the development of Flex apps that can be compiled and packaged with the generated Enunciate app.
The "app" element supports the folowing attributes:
- The "name" attribute is the name of the Flex app. This attribute is required.
- The "srcDir" attribute specifies the source directory for the application. This attribute is required.
- The "mainMxmlFile" attribute specifies the main mxml file for the app. This attribute is required. The path to this file is resolved
relative to the enunciate.xml file (not to the "srcDir" attribute of the app).
- The "outputPath" attribute specified the output directory for the application, relative to the "flexAppDir".
The "facets" element
The "facets" element is applicable to the AMF module to configure which facets are to be included/excluded from the AMF artifacts. For
more information, see API Facets
Example Configuration
As an example, consider the following configuration:
<enunciate>
<modules>
<amf disabled="false" swcName="mycompany-amf.swc"
flexHome="/home/myusername/tools/flex-sdk-2">
<app srcDir="src/main/flexapp" name="main" mainMxmlFile="src/main/flexapp/com/mycompany/main.mxml"/>
<app srcDir="src/main/anotherapp" name="another" mainMxmlFile="src/main/anotherapp/com/mycompany/another.mxml"/>
<facets>
...
</facets>
...
</amf>
</modules>
</enunciate>
This configuration enables the AMF module and gives a specific name to the compiled SWC for the client-side ActionScript classes.
There also two Flex applications defined. The first is located at "src/main/flexapp". The name of this app is "main". The MXML
file that defines this app sits at "src/main/flexapp/com/mycompany/main.mxml", relative to the enunciate configuration file. The
second application, rooted at "src/main/anotherapp", is named "another". The mxml file that defines this application sits at
"src/main/anotherapp/com/mycompany/another.mxml".
After the "compile" step of the AMF module, assuming everything compiles correctly, there will be two Flash applications, "main.swf" and "another.swf",
that sit in the applications directory (see "artifacts" below).
For a less contrived example, see the "petclinic" sample Enunciate project bundled with the Enunciate distribution.
Artifacts
- The "amf.client.src.dir" artifact is the directory where the client-side source code is generated.
- The "amf.server.src.dir" artifact is the directory where the server-side source code is generated.
- The "as3.client.swc" artifact is the packaged client-side ActionScript SWC.
- The "flex.app.dir" artifact is the directory to which the Flex apps are compiled.