[ Team LiB ] |
Recipe 20.17 Receiving Typed Objects with Java20.17.1 ProblemYou want to handle typed objects using a J2EE service function. 20.17.2 SolutionUse JavaBean classes that correspond to the ActionScript classes, and use the third-party ASTranslator class to perform conversions between datatypes. 20.17.3 DiscussionUnlike the .NET version, Flash Remoting for J2EE does not automatically convert typed ActionScript objects into corresponding custom Java types. Instead, the gateway converts the ActionScript objects into ASObject types. The flashgateway.io.ASObject class (included in flashgateway.jar) is a subclass of java.util.HashMap to which two additional methods (getType( ) and setType( )) have been added. The properties of the ActionScript object are stored as key/value pairs in the ASObject. You can create your own proprietary code to convert between an ASObject and the appropriate Java datatype. However, Carbon Five has already created an excellent utility named ASTranslator to do this for you. ASTranslator is freely available for download from http://www.carbonfive.com/opensource-main-1.html. It converts between ASObject and custom Java datatypes using JavaBean-style introspection. Therefore, it requires that your custom Java datatypes adhere to the JavaBean rules (namely, they must implement java.io.Serializable, use get/set methods for all publicly accessible properties, and have a constructor that requires no parameters). Here is how to use ASTranslator to receive typed objects and convert them to custom Java types:
20.17.4 See Also |
[ Team LiB ] |