9.3. A Sample Custom Adapter

In this section, I create a simple BlazeDS adapter to illustrate how you could create one, too. The custom adapter extends JavaAdapter and allows you to call multiple POJOs (Plain Old Java Objects, in case you forgot!) class methods, using a single destination. Under normal conditions, one destination maps to a single Java class. Although the custom adapter itself provides a convenient implementation that could be very handy, especially if your application involves remote procedure calls to a large number of server-side Java classes, the purpose here is to illustrate how you could create a custom adapter.

First, look at the invoke method of the multiple POJO adapter, shown in Listing 9-1. The MultiplePOJOAdapter is available as a part of the open source dsadapters project, which aims to provide a number of useful extensions to BlazeDS. Details on the dsadapters project are available at http://code.google.com/p/dsadapters/.

Example 9.1. invoke Method of the MultiplePOJOAdapter
@Override
    public Object invoke(Message message)
    {
        Object result = null;

        try
        {
            RemotingDestination remotingDestination = (RemotingDestination)
               getDestination();
            RemotingMessage remotingMessage = (RemotingMessage)message;
            FactoryInstance factoryInstance = remotingDestination.
               getFactoryInstance();
            String remoteObjectSourceProperty = remotingMessage.getSource();

            boolean sourceMatchesRegEx = false;
            String classToInvoke = null;
if(remoteObjectSourceProperty != null && remoteObjectSourceProperty. ...

Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.