Converting parameters

Carlos Villela <[email protected]> Thu, 24 Apr 2003 01:49:30 -0300
Newsgroups gmane.comp.java.aspectwerkz
Organization Bluebox Technologies
Message-ID <[email protected]>
Hi folks!

Just another quick question that might solve a big problem to me:

I'm using Flash Remoting to create the GUI for my application. For those 
who don't have an idea of what Flash Remoting is, here's a simple 
desciption: it's a RPC layer for Flash MX, allowing any Flash movie to 
connect to a J2EE, Coldfusion or .NET component and manipulate objects 
or call methods at will. Here's a simple example:

// Create a JavaBean named User
public class User {
    private String name;
    public void setName(String name)...
    public String getName()...
    ...
}

// Create a UserServices class, to achieve a services-oriented 
architecture, which is a GoodThing(tm) when using Flash Remoting or 
webservices
public class UserServices {
    public void saveUser(ASObject asUser) {
        User user = (User) new ASTranslator().fromActionScript(asUser);
        // do whatever is needed to save the user
    }

    public ASObject findUser(String name) {
        // do whatever is needed to find an user by name
        return (ASObject) new ASTranslator().toActionScript(user);
    }
}

// ActionScript (Flash) code
#include "NetServices.as"

NetServices.setDefaultGatewayUrl("http://localhost/gateway");
var gatewayConnection = NetServices.createGatewayConnection();
var service = gatewayConnection.getService("eg.UserServices", this);

User = function() {}

// User in Flash maps to eg.User in Java
Object.registerClass("eg.User",User);

var user = new User();
user.name = "Carlos Villela";

service.saveUser(user);

var newUser = service.findUser("Carlos Villela");


Pretty cool, huh? Well, now I can finally get to the point: how to 
handle the translation of ASObjects to real Java objects automatically, 
using aspects? I already have the handy ASTranslator class that does the 
conversion, but explicitly calling its toActionScript and 
fromActionScript methods is definitely a cross-cutting concern, and I 
don't want it sprinkled around in my service-layer code.

I would like to have a UserServices class like this:

public class UserServices {
    public void saveUser(User user) {
        // do whatever is needed to save the user
    }

    public User findUser(String name) {
        // do whatever is needed to find an user by name
        return user;
    }
}

Apparently the solution for this is very simple, but I can't see it for 
now. Any ideas?

[]'s
-cv

PS: If you're into commercial application development, be sure to check 
out Flash Remoting. It's a damn good way to build a very interesting GUI 
for web applications, and saves a lot of time if you happen to have some 
unused Flash talents around. Here's a very good article for us, Java 
developers: 
http://www.onjava.com/pub/a/onjava/2003/02/26/flash_remoting.html




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf