org.spicefactory.cinnamon.io.mapping
Class BeanClassMapping

java.lang.Object
  extended by org.spicefactory.cinnamon.io.mapping.AbstractClassMapping
      extended by org.spicefactory.cinnamon.io.mapping.AbstractPropertyClassMapping
          extended by org.spicefactory.cinnamon.io.mapping.BeanClassMapping
All Implemented Interfaces:
ClassMapping

public class BeanClassMapping
extends AbstractPropertyClassMapping

ClassMapping implementation that is responsible for mapping the properties of ActionScript classes to bean properties of Java classes following standard Java bean conventions. The mapped ActionScript class must have an alias registered in ActionScript with flash.net.registerClassAlias or the [RemoteClass] metadata tag (which only works in Flex Applications).

Implementation note: For reflection on the properties of a Java bean this class does not use the standard Introspector built into Java SE since that class does not work properly with generic properties. The Spicelib reflection library will be used instead.

Author:
Jens Halm

Constructor Summary
BeanClassMapping(String alias, String actionScriptClass, Class<?> javaClass, Class<?> javaFactory, Set<String> omittedProperties, ReflectionFactory factory)
          Creates a new BeanClassMapping instance.
 
Method Summary
protected  Object getProperty(Object instance, String propertyName)
          Reads the property with the given name from the specified target instance.
 void init(CinnamonConfig config)
          Initialization method that will be called once for each ClassMapping instance at application startup.
 Object newJavaInstance()
          Creates a new instance of the mapped Java class.
protected  void setProperty(Object instance, String propertyName, Object value)
          Sets the property on the given target instance to the specified value.
 void setReflectionFactory(ReflectionFactory reflectionFactory)
          Sets the factory to use for reflecting on bean properties.
 String toString()
           
 
Methods inherited from class org.spicefactory.cinnamon.io.mapping.AbstractPropertyClassMapping
readObject, writeObject
 
Methods inherited from class org.spicefactory.cinnamon.io.mapping.AbstractClassMapping
getActionScriptClass, getAlias, getEncoding, getJavaClass, getJavaFactory, getPropertyNames, setPropertyNames, writeClassDescriptor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeanClassMapping

public BeanClassMapping(String alias,
                        String actionScriptClass,
                        Class<?> javaClass,
                        Class<?> javaFactory,
                        Set<String> omittedProperties,
                        ReflectionFactory factory)
Creates a new BeanClassMapping instance.

Parameters:
alias - the alias for this mapping
actionScriptClass - the fully qualified ActionScript class name
javaClass - the Java class
javaFactory - the (optional) Java factory
omittedProperties - a set of property names to exclude from this mapping
factory - the factory to use for reflecting on bean properties
Method Detail

init

public void init(CinnamonConfig config)
Description copied from interface: ClassMapping
Initialization method that will be called once for each ClassMapping instance at application startup.

Parameters:
config - the Cinnamon configuration instance

newJavaInstance

public Object newJavaInstance()
Description copied from interface: ClassMapping
Creates a new instance of the mapped Java class.

Returns:
a new instance of the mapped Java class

getProperty

protected Object getProperty(Object instance,
                             String propertyName)
Description copied from class: AbstractPropertyClassMapping
Reads the property with the given name from the specified target instance.

Specified by:
getProperty in class AbstractPropertyClassMapping
Parameters:
instance - the instance to read the property from
propertyName - the name of the property
Returns:
the value of the property

setProperty

protected void setProperty(Object instance,
                           String propertyName,
                           Object value)
Description copied from class: AbstractPropertyClassMapping
Sets the property on the given target instance to the specified value.

Specified by:
setProperty in class AbstractPropertyClassMapping
Parameters:
instance - the instance to set the property on
propertyName - the name of the property
value - the new value of the property

setReflectionFactory

public void setReflectionFactory(ReflectionFactory reflectionFactory)
Sets the factory to use for reflecting on bean properties.

Parameters:
reflectionFactory - the factory to use for reflecting on bean properties

toString

public String toString()
Overrides:
toString in class AbstractClassMapping