org.codehaus.enunciate.modules.amf
Class AMFDeploymentModule

java.lang.Object
  extended by org.codehaus.enunciate.modules.BasicDeploymentModule
      extended by org.codehaus.enunciate.modules.FreemarkerDeploymentModule
          extended by org.codehaus.enunciate.modules.amf.AMFDeploymentModule
All Implemented Interfaces:
EnunciateClasspathListener, EnunciateModelAware, DeploymentModule, FlexHomeAwareModule, ProjectExtensionModule

public class AMFDeploymentModule
extends FreemarkerDeploymentModule
implements ProjectExtensionModule, FlexHomeAwareModule, EnunciateClasspathListener

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 "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 "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.

The "compiler" element also supports the following subelements:

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:

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"/>       ...     </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

Author:
Ryan Heaton

Field Summary
 
Fields inherited from class org.codehaus.enunciate.modules.BasicDeploymentModule
enunciate
 
Constructor Summary
AMFDeploymentModule()
           
 
Method Summary
 void addFlexApp(FlexApp flexApp)
          Adds a flex app to be compiled.
protected  void compileSwc(java.util.List<java.lang.String> commandLine)
          Compiles the SWC.
protected  void doBuild()
          Default implementation is a no-op.
protected  void doCompile()
          Default implementation is a no-op.
protected  void doFlexCompile()
          Invokes the flex compiler on the apps specified in the configuration file.
 void doFreemarkerGenerate()
          Generate using Freemarker.
 java.lang.String getAmfSubcontext()
          The amf subcontext.
 java.io.File getClientSideGenerateDir()
          Get the generate directory for client-side AMF classes.
 FlexCompilerConfig getCompilerConfig()
          The compiler configuration.
 org.apache.commons.digester.RuleSet getConfigurationRules()
          AMF configuration rule set.
 java.lang.String getFlexAppDir()
          The flex app dir.
 java.util.List<FlexApp> getFlexApps()
          The amf apps to compile.
 java.lang.String getFlexHome()
          The amf home directory
 java.lang.String getLabel()
          The label for the ActionScript API.
 java.lang.String getMergeServicesConfigXML()
          The services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.
protected  java.net.URL getMergeServicesConfigXmlTemplateURL()
           
 java.lang.String getName()
          The name of the deployment module.
protected  freemarker.template.ObjectWrapper getObjectWrapper()
          The object wrapper to use for the model.
 java.util.List<java.io.File> getProjectResourceDirectories()
          Any additional project resource directories to add to the project.
 java.util.List<java.io.File> getProjectSources()
          Any additional project source roots to add to the project.
 java.util.List<java.io.File> getProjectTestResourceDirectories()
          Any additional project resource directories to add to the project.
 java.util.List<java.io.File> getProjectTestSources()
          Any additional project test source roots to add to the project.
 java.io.File getServerSideGenerateDir()
          Get the generate directory for server-side AMF classes.
 java.io.File getSwcCompileDir()
          The directory for the destination for the SWC.
 java.lang.String getSwcName()
          The name of the swc file.
 java.io.File getSwfCompileDir()
          The directory for the destination for the SWF.
protected  java.net.URL getTemplateURL(java.lang.String template)
          Get a template URL for the template of the given name.
 Validator getValidator()
          AMF validator.
 java.io.File getXMLGenerateDir()
          Get the generate directory for XML configuration.
 void init(Enunciate enunciate)
          Sets the enunciate mechanism.
 void initModel(EnunciateFreemarkerModel model)
          Initialize the model.
protected  boolean isAMFTransient(com.sun.mirror.declaration.Declaration declaration)
          Whether the given type declaration is AMF-transient.
protected  boolean isAMFTransient(com.sun.mirror.declaration.TypeDeclaration declaration)
          Whether the given type declaration is AMF-transient.
 boolean isAsSourcesDownloadable()
          Whether the generated ActionScript sources are downloadable.
 boolean isDisabled()
          Whether this deployment module has been disabled, e.g.
 boolean isSwcDownloadable()
          Whether the swc is downloadable.
protected  freemarker.ext.dom.NodeModel loadMergeXmlModel(java.io.InputStream inputStream)
          Loads the node model for merging xml.
 void onClassesFound(java.util.Set<java.lang.String> classes)
          Logic for handling a set of classes that were found on the Enunciate classpath.
protected  java.lang.String readResource(java.lang.String resource)
          Reads a resource into string form.
 void setAmfSubcontext(java.lang.String amfSubcontext)
          The amf subcontext.
 void setAsSourcesDownloadable(boolean asSourcesDownloadable)
          Whether the generated ActionScript sources are downloadable.
 void setCompilerConfig(FlexCompilerConfig compilerConfig)
          The compiler configuration.
 void setFlexAppDir(java.lang.String flexAppDir)
          The flex app dir.
 void setFlexHome(java.lang.String flexHome)
          Set the path to the AMF home directory.
 void setLabel(java.lang.String label)
          The label for the ActionScript API.
 void setMergeServicesConfigXML(java.lang.String mergeServicesConfigXML)
          Specifies the services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.
 void setSwcDownloadable(boolean swcDownloadable)
          Whether the swc is downloadable.
 void setSwcName(java.lang.String swcName)
          The name of the swc file.
 
Methods inherited from class org.codehaus.enunciate.modules.FreemarkerDeploymentModule
close, doGenerate, getConfiguration, getModel, getModelInternal, getTemplateExceptionHandler, getTemplateLoader, processTemplate, processTemplate, processTemplate, processTemplate
 
Methods inherited from class org.codehaus.enunciate.modules.BasicDeploymentModule
debug, doPackage, getAliases, getBuildDir, getCompileDir, getEnunciate, getGenerateDir, getOrder, getPackageDir, info, setBuildDir, setCompileDir, setDisabled, setGenerateDir, setPackageDir, step, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.enunciate.modules.DeploymentModule
close, getAliases, getOrder, step
 

Constructor Detail

AMFDeploymentModule

public AMFDeploymentModule()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: DeploymentModule
The name of the deployment module. Identifies its section in the enunciate configuration.

Specified by:
getName in interface DeploymentModule
Overrides:
getName in class BasicDeploymentModule
Returns:
"amf"

init

public void init(Enunciate enunciate)
          throws EnunciateException
Description copied from class: BasicDeploymentModule
Sets the enunciate mechanism.

Specified by:
init in interface DeploymentModule
Overrides:
init in class BasicDeploymentModule
Parameters:
enunciate - The enunciate mechanism.
Throws:
EnunciateException

initModel

public void initModel(EnunciateFreemarkerModel model)
Description copied from interface: EnunciateModelAware
Initialize the model.

Specified by:
initModel in interface EnunciateModelAware
Overrides:
initModel in class FreemarkerDeploymentModule
Parameters:
model - The model to initialize.

onClassesFound

public void onClassesFound(java.util.Set<java.lang.String> classes)
Description copied from interface: EnunciateClasspathListener
Logic for handling a set of classes that were found on the Enunciate classpath.

Specified by:
onClassesFound in interface EnunciateClasspathListener
Parameters:
classes - The classes that were found.

doFreemarkerGenerate

public void doFreemarkerGenerate()
                          throws java.io.IOException,
                                 freemarker.template.TemplateException,
                                 EnunciateException
Description copied from class: FreemarkerDeploymentModule
Generate using Freemarker. Same as FreemarkerDeploymentModule.doGenerate() but can throw a TemplateException.

Specified by:
doFreemarkerGenerate in class FreemarkerDeploymentModule
Throws:
java.io.IOException
freemarker.template.TemplateException
EnunciateException

loadMergeXmlModel

protected freemarker.ext.dom.NodeModel loadMergeXmlModel(java.io.InputStream inputStream)
                                                  throws EnunciateException
Loads the node model for merging xml.

Parameters:
inputStream - The input stream of the xml.
Returns:
The node model.
Throws:
EnunciateException

doFlexCompile

protected void doFlexCompile()
                      throws EnunciateException,
                             java.io.IOException
Invokes the flex compiler on the apps specified in the configuration file.

Throws:
EnunciateException
java.io.IOException

compileSwc

protected void compileSwc(java.util.List<java.lang.String> commandLine)
                   throws java.io.IOException,
                          EnunciateException
Compiles the SWC.

Parameters:
commandLine - The command line.
Throws:
java.io.IOException
EnunciateException

doCompile

protected void doCompile()
                  throws EnunciateException,
                         java.io.IOException
Description copied from class: BasicDeploymentModule
Default implementation is a no-op.

Overrides:
doCompile in class BasicDeploymentModule
Throws:
EnunciateException
java.io.IOException

doBuild

protected void doBuild()
                throws EnunciateException,
                       java.io.IOException
Description copied from class: BasicDeploymentModule
Default implementation is a no-op.

Overrides:
doBuild in class BasicDeploymentModule
Throws:
EnunciateException
java.io.IOException

readResource

protected java.lang.String readResource(java.lang.String resource)
                                 throws java.io.IOException,
                                        EnunciateException
Reads a resource into string form.

Parameters:
resource - The resource to read.
Returns:
The string form of the resource.
Throws:
java.io.IOException
EnunciateException

isAMFTransient

protected boolean isAMFTransient(com.sun.mirror.declaration.TypeDeclaration declaration)
Whether the given type declaration is AMF-transient.

Parameters:
declaration - The type declaration.
Returns:
Whether the given tyep declaration is AMF-transient.

isAMFTransient

protected boolean isAMFTransient(com.sun.mirror.declaration.Declaration declaration)
Whether the given type declaration is AMF-transient.

Parameters:
declaration - The type declaration.
Returns:
Whether the given tyep declaration is AMF-transient.

getTemplateURL

protected java.net.URL getTemplateURL(java.lang.String template)
Get a template URL for the template of the given name.

Parameters:
template - The specified template.
Returns:
The URL to the specified template.

getServerSideGenerateDir

public java.io.File getServerSideGenerateDir()
Get the generate directory for server-side AMF classes.

Returns:
The generate directory for server-side AMF classes.

getClientSideGenerateDir

public java.io.File getClientSideGenerateDir()
Get the generate directory for client-side AMF classes.

Returns:
The generate directory for client-side AMF classes.

getXMLGenerateDir

public java.io.File getXMLGenerateDir()
Get the generate directory for XML configuration.

Returns:
The generate directory for the XML configuration.

getSwcCompileDir

public java.io.File getSwcCompileDir()
The directory for the destination for the SWC.

Returns:
The directory for the destination for the SWC.

getSwfCompileDir

public java.io.File getSwfCompileDir()
The directory for the destination for the SWF.

Returns:
The directory for the destination for the SWF.

getConfigurationRules

public org.apache.commons.digester.RuleSet getConfigurationRules()
AMF configuration rule set.

Specified by:
getConfigurationRules in interface DeploymentModule
Overrides:
getConfigurationRules in class BasicDeploymentModule
Returns:
AMF configuration rule set.

getValidator

public Validator getValidator()
AMF validator.

Specified by:
getValidator in interface DeploymentModule
Overrides:
getValidator in class BasicDeploymentModule
Returns:
AMF validator.

getObjectWrapper

protected freemarker.template.ObjectWrapper getObjectWrapper()
Description copied from class: FreemarkerDeploymentModule
The object wrapper to use for the model.

Overrides:
getObjectWrapper in class FreemarkerDeploymentModule
Returns:
The object wrapper to use for the model.

getFlexHome

public java.lang.String getFlexHome()
The amf home directory

Returns:
The amf home directory

setFlexHome

public void setFlexHome(java.lang.String flexHome)
Set the path to the AMF home directory.

Specified by:
setFlexHome in interface FlexHomeAwareModule
Parameters:
flexHome - The amf home directory

getFlexApps

public java.util.List<FlexApp> getFlexApps()
The amf apps to compile.

Returns:
The amf apps to compile.

addFlexApp

public void addFlexApp(FlexApp flexApp)
Adds a flex app to be compiled.

Parameters:
flexApp - The flex app to be compiled.

getCompilerConfig

public FlexCompilerConfig getCompilerConfig()
The compiler configuration.

Returns:
The compiler configuration.

setCompilerConfig

public void setCompilerConfig(FlexCompilerConfig compilerConfig)
The compiler configuration.

Parameters:
compilerConfig - The compiler configuration.

getMergeServicesConfigXmlTemplateURL

protected java.net.URL getMergeServicesConfigXmlTemplateURL()
Returns:
The URL to "web.xml.fmt"

getSwcName

public java.lang.String getSwcName()
The name of the swc file.

Returns:
The name of the swc file.

setSwcName

public void setSwcName(java.lang.String swcName)
The name of the swc file.

Parameters:
swcName - The name of the swc file.

isSwcDownloadable

public boolean isSwcDownloadable()
Whether the swc is downloadable.

Returns:
Whether the swc is downloadable.

setSwcDownloadable

public void setSwcDownloadable(boolean swcDownloadable)
Whether the swc is downloadable.

Parameters:
swcDownloadable - Whether the swc is downloadable.

isAsSourcesDownloadable

public boolean isAsSourcesDownloadable()
Whether the generated ActionScript sources are downloadable.

Returns:
Whether the generated ActionScript sources are downloadable.

setAsSourcesDownloadable

public void setAsSourcesDownloadable(boolean asSourcesDownloadable)
Whether the generated ActionScript sources are downloadable.

Parameters:
asSourcesDownloadable - Whether the generated ActionScript sources are downloadable.

getMergeServicesConfigXML

public java.lang.String getMergeServicesConfigXML()
The services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.

Returns:
the services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.

setMergeServicesConfigXML

public void setMergeServicesConfigXML(java.lang.String mergeServicesConfigXML)
Specifies the services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.

Parameters:
mergeServicesConfigXML - the services-config.xml file that is to be merged into the Enunciate-generated services-config.xml file.

getAmfSubcontext

public java.lang.String getAmfSubcontext()
The amf subcontext.

Returns:
The amf subcontext.

setAmfSubcontext

public void setAmfSubcontext(java.lang.String amfSubcontext)
The amf subcontext.

Parameters:
amfSubcontext - The amf subcontext.

getFlexAppDir

public java.lang.String getFlexAppDir()
The flex app dir.

Returns:
The flex app dir.

setFlexAppDir

public void setFlexAppDir(java.lang.String flexAppDir)
The flex app dir.

Parameters:
flexAppDir - The flex app dir.

getLabel

public java.lang.String getLabel()
The label for the ActionScript API.

Returns:
The label for the ActionScript API.

setLabel

public void setLabel(java.lang.String label)
The label for the ActionScript API.

Parameters:
label - The label for the ActionScript API.

isDisabled

public boolean isDisabled()
Description copied from interface: DeploymentModule
Whether this deployment module has been disabled, e.g. in the config file. Since the discovery mechanism is used to discover the modules on the classpath, it may be necessary to be able to disable a module.

Specified by:
isDisabled in interface DeploymentModule
Overrides:
isDisabled in class BasicDeploymentModule
Returns:
Whether this deployment module has been disabled.

getProjectSources

public java.util.List<java.io.File> getProjectSources()
Description copied from interface: ProjectExtensionModule
Any additional project source roots to add to the project.

Specified by:
getProjectSources in interface ProjectExtensionModule
Returns:
Any additional project source roots to add to the project.

getProjectTestSources

public java.util.List<java.io.File> getProjectTestSources()
Description copied from interface: ProjectExtensionModule
Any additional project test source roots to add to the project.

Specified by:
getProjectTestSources in interface ProjectExtensionModule
Returns:
Any additional project test source roots to add to the project.

getProjectResourceDirectories

public java.util.List<java.io.File> getProjectResourceDirectories()
Description copied from interface: ProjectExtensionModule
Any additional project resource directories to add to the project.

Specified by:
getProjectResourceDirectories in interface ProjectExtensionModule
Returns:
Any additional project resource directories to add to the project.

getProjectTestResourceDirectories

public java.util.List<java.io.File> getProjectTestResourceDirectories()
Description copied from interface: ProjectExtensionModule
Any additional project resource directories to add to the project.

Specified by:
getProjectTestResourceDirectories in interface ProjectExtensionModule
Returns:
Any additional project resource directories to add to the project.