Java Annotations

By using the @Service and @RemotingDestination annotations a lot of the bean declarations in the Spring context are not needed anymore. The component-scan saves a lot of type work. So implementing new remote services for BlazeDS can be done in Java itself with no XML declarations at all.

Castor

Paddles uses Castor to generate Java objects from the XSD definition. To enable custom serialization Paddle transforms the XSD first to a custom XSD with wrapper definitions around all simple types. In this way it prevents Castor from generating java simple types directly into complex type class attributes.

Datatype mapping

Paddle generates its own mapping from Flex to Java. For complex objects no custom serialization is used. While wrappers are generated around simple types a complex type cannot exist of simple types directly so there is no need to serialize them in custom way.

All simple types are serialized in a custom way. At this moment only for enumeration custom serialization is made functional. While Flex has no enumeration it is 'simulated'. When passing an enumeration to Java a string representation is passed which is converted to the corresponding Java enum type.

Person case - Person back-end service

In the Person service back-end provides three functions: Create a Person document, Make an Xml of a Person document and write a Person document to file. The interface is defined as follows.


package nl.devoorkant.person.api;

import nl.devoorkant.person.Document;

/**
 * Created by IntelliJ IDEA.
 * User: Martijn Bruinenberg
 * Date: 1-jul-2009
 * Time: 15:11:40
 */
public interface IPersonService {
    public Document createDocument();

    public String getXmlOfDocument(Document poDocument);

    public void writeDocumentToFile(Document poDocument);
}
		

In the implementation of the Spring bean the @Service annotation will designate the PersonServiceBean as a service component. The @RemotingDestination annotation will register the service bean within the message broker.


package nl.devoorkant.person.api;

/**
 * Created by IntelliJ IDEA.
 * User: Martijn Bruinenberg
 * Date: 1-jul-2009
 * Time: 15:11:54
 */

import nl.devoorkant.person.Document;

import org.springframework.stereotype.Service;
import org.springframework.flex.remoting.RemotingDestination;
import org.apache.log4j.Logger;

@Service("personService")
@RemotingDestination
public class PersonServiceBean extends PersonServiceAbstractBean{
    private Logger ioLogger = Logger.getLogger(PersonServiceBean.class);

    /*
     * Method createDocument creates a new Document structure
     *
     * @return empty document with person fields
     */
    public Document createDocument() {
        return doCreateDocument();
    }

    /*
     * Method getXmlOfDocument returns XML string of person document
     *
     * @param poDocument    XML object which is filled with a person
     * @return string with the XML content
     */
    public String getXmlOfDocument(Document poDocument) {
        return doGetXmlOfDocument(poDocument);
    }

    /*
     * Method writeDocumentToFile writes document content as XML to file. (placed in Tomcat bin folder)
     *
     * @param poDocument    XML object which is filled with a person
     */
    public void writeDocumentToFile(Document poDocument) {
        doWriteDocumentToFile(poDocument);
    }
}