com.carbonfive.flash
Class ASTranslator

java.lang.Object
  extended by com.carbonfive.flash.ASTranslator

public class ASTranslator
extends java.lang.Object

ASTranslator provides the ability to translate between ASObjects used by Macromedia Flash Remoting and Java objects in your application. See the project documentation for details.

$Id: ASTranslator.java,v 1.27 2004/03/03 20:42:38 wynholds Exp $


Constructor Summary
ASTranslator()
           
 
Method Summary
 java.lang.Object fromActionScript(java.lang.Object asObject)
          Given an Object that is either an ASObject or Collection of ASObjects, fromActionScript creates a corresponding JavaBean or Collection of JavaBeans.
 java.lang.Object fromActionScript(java.lang.Object actionScriptObject, java.lang.Class desiredBeanClass)
          Translate an object to another object of type 'desiredBeanClass' obj types should be ASObject, Boolean, String, Number, Date, ArrayList
 void ignoreClass(java.lang.Class klass)
          Ignore objects that are an instance of klass when translating.
 void ignoreProperty(java.lang.Class klass, java.lang.String property)
          Ignore the specified property of objects that are instances of klass.
 void setUseEquivalence(boolean b)
          Determines whether object that are equivalent (using Object.equals()) should be considered identical by ASTranslator.
 java.lang.Object toActionScript(java.lang.Object serverObject)
          Given an Object, toActionScript creates a corresponding ASObject or Collection of ASObjects that maps the source object's JavaBean properties to ASObject fields, Collections and Sets to ArrayLists, and all Numbers to Doubles while maintaining object references (including circular references).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ASTranslator

public ASTranslator()
Method Detail

ignoreClass

public void ignoreClass(java.lang.Class klass)
Ignore objects that are an instance of klass when translating. For example, ignoreClass(Object.class) would cause ASTranslator to ignore everything.
Objects that are ignored are returned from ASTranslator as null.

Parameters:
klass - The class (or superclass or interface) to ignore

ignoreProperty

public void ignoreProperty(java.lang.Class klass,
                           java.lang.String property)
Ignore the specified property of objects that are instances of klass. Properties that are ignored are returned from ASTranslator as null.

Parameters:
klass - The class (or superclass or interface) of the property to ignore
property - The name of the property to ignore

setUseEquivalence

public void setUseEquivalence(boolean b)
Determines whether object that are equivalent (using Object.equals()) should be considered identical by ASTranslator.

When walking the object graph ASTranslator stores a cache of objects viewed. This cache is used to maintain references within the object graph. If useEquivalence is set to true, this cache is an equivalence cache, which means objects are compared by Object.equals() instead of the == operator. So if two objects are equal (but not identical) in the object graph, one will be stored as a reference to the other one when translated to ASObjects.

The consequences of this are:

You should use this only if your Flash code is using the ASObjects in a read-only manner, or you are very well aware of what is going on.

This setting also assumes that the Flash Remoting gateway supports maintaining references. Unfortunately, this is not currently the case. However, it is pretty easy to hack this behavior in to Flash Remoting or OpenAMF.

The default value for useEquivalence is false.

Parameters:
b - Whether to use equivalence or not

toActionScript

public java.lang.Object toActionScript(java.lang.Object serverObject)
Given an Object, toActionScript creates a corresponding ASObject or Collection of ASObjects that maps the source object's JavaBean properties to ASObject fields, Collections and Sets to ArrayLists, and all Numbers to Doubles while maintaining object references (including circular references).

These mappings are consistent with Flash Remoting's rules for converting Objects to ASObjects. They just add the behavior of using JavaBean-style introspection to determine property names. Additionally, toActionScript sets the "type" field of all ASObjects created to be the class name of the source JavaBean. This enables two-way translation between ASObjects and JavaBeans.

Parameters:
serverObject - an Object to translate to ASObjects or corresponding primitive or Collection classes
Returns:
an Object that may be an ASObject or nested Collections of ASObjects or null if translation fails

fromActionScript

public java.lang.Object fromActionScript(java.lang.Object asObject)
Given an Object that is either an ASObject or Collection of ASObjects, fromActionScript creates a corresponding JavaBean or Collection of JavaBeans.

The "type" field of an ASObject identifies the class name of the JavaBean to create. If the type field is null, an ASObject becomes a HashMap. The interface of the JavaBean is more specific that the relatively loosely-typed ASObject and therefore drives the translation of ASObject fields.

Parameters:
asObject - an Object that is usually an ASObject but may also be a Collection or primitive
Returns:
an Object value that is either a JavaBean or Collection of JavaBeans or null if translation fails

fromActionScript

public java.lang.Object fromActionScript(java.lang.Object actionScriptObject,
                                         java.lang.Class desiredBeanClass)
Translate an object to another object of type 'desiredBeanClass' obj types should be ASObject, Boolean, String, Number, Date, ArrayList