Re: Converting parameters

"Jonas Bonèr" <[email protected]> Thu, 24 Apr 2003 12:58:44 +0200
Newsgroups gmane.comp.java.aspectwerkz
Message-ID <[email protected]>
Hi Carlos.

I guess you can solve your problem by:

Creating a MethodAdvice that converts your object and replaces the old para=
meter to the method with the converted one. Then the type of the paramete=
r will not be correct so you must either have both objects implement the =
same interface or change the parameter type to java.lang.Object.

    // your method advice
    ...
    public void execute(final JoinPoint joinPoint) {
        MethodJoinPoint jp =3D (MethodJoinPoint)joinPoint;
        // something like this...
        ASObject asUser =3D (ASObject)jp.getParameters()[0]; =20
`        User user =3D (User) new ASTranslator().fromActionScript(asUser);
        setParameters(new Object[]{user}); // or use a common interface
        jp.proceed();
    }
    ...
Then apply this advice to your original methods.

It is maybe not the cleanest solution but it should work.

- Jonas

-----Original Message-----
From: Carlos Villela <[email protected]>
To: [email protected]
Date: Thu, 24 Apr 2003 01:49:30 -0300=20
Subject: [aspectwerkz-developer] Converting parameters

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=20
who don't have an idea of what Flash Remoting is, here's a simple=20
desciption: it's a RPC layer for Flash MX, allowing any Flash movie to=20
connect to a J2EE, Coldfusion or .NET component and manipulate objects=20
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=20
architecture, which is a GoodThing(tm) when using Flash Remoting or=20
webservices
public class UserServices {
    public void saveUser(ASObject asUser) {
        User user =3D (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 =3D NetServices.createGatewayConnection();
var service =3D gatewayConnection.getService("eg.UserServices", this);

User =3D function() {}

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

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

service.saveUser(user);

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


Pretty cool, huh? Well, now I can finally get to the point: how to=20
handle the translation of ASObjects to real Java objects automatically,=20
using aspects? I already have the handy ASTranslator class that does the=20
conversion, but explicitly calling its toActionScript and=20
fromActionScript methods is definitely a cross-cutting concern, and I=20
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=20
now. Any ideas?

[]'s
-cv

PS: If you're into commercial application development, be sure to check=20
out Flash Remoting. It's a damn good way to build a very interesting GUI=20
for web applications, and saves a lot of time if you happen to have some=20
unused Flash talents around. Here's a very good article for us, Java=20
developers:=20
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
_______________________________________________
aspectwerkz-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aspectwerkz-developer


- Jonas



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