damn you Aral, giving me ideas of things to do. (WARNING, long email)

so, im trying the ARP codegen from the service browser but i cant get it to
compile straight away for a variety of reasons.

I just downloaded ARP (2.02) as i am not normally an ARP user.

So the generated code has

1. References to a type 'RemotingService'. I cant find this anywhere, what is 
it?

2. Calls to ServiceLocator.getService() rather than
ServiceLocator.getInstance().getService();

3. The commands dont extend CommandTemplate which isnt a big deal as from what i
can see its just a wrapper to use with the command handling part of ARP's
ControllerTemplate.

Also the generated commands contain an execute method which is
missing the argument to the object I want to send to the server e.g.

/**
  *
  * Args: user
  */
public function execute(pViewRef:Object):Void
{
        // some code here

        // Argument not supplied...
        var pc:PendingCall = service.test(user);
}

although the generate comment says there is an argument. *but* commands in ARP
dont take parameters, so the object is usually pulled from the viewRef (which is
one of the things im not so keen on with ARP, i havent checked the labs to see 
if anyone thought the same and modified theirs)

anyway, not a great start but with some fiddling i've got it to compile.
This makes me think that the codegen is either for an old ARP version or its
just broken.

Now the real meat of the matter, what exactly are you suggesting?

Do you mean that the command can marshal responses from cake into the correct vo
types?

Like a hand-rolled Object.registerClass ?

Cake creates responses that are just plain objects, i.e. retrieving a user from
the database via something like $this->User->findByName($name) will give you a
response like :

{User:
        {name : martin,
        password : secret}
}

so you could just scan the response, look for names that match registered VO
names, create a VO and stuff the values in. That way the rest of the application
can happily use VO types.

...a few hours pass...

right, so i've implemented a basic version of what i think it is you are 
suggesting. here's a zip of the code im working with

http://relivethefuture.com/work/arpCake.zip

In there are 3 directories,

as : actionscript code, built with mtasc. Startup is the main class.
cake : just the cake code that needs to go into the /app directory
db : an sql script to generate and populate the test tables

So what i did was this :

each vo has a call :

private static var _reg:Boolean = 
TypeMapper.registerType("CakeModelName",vo.ThisClass)

just like Object.registerClass. You could probably do something with hi-jacking 
registerType and some setPropFlags to hook into that directly. Although its a 
shame you cant ask for the type map e.g. Object.getClassRegistry();

Second, i've subclassed CommandTemplate to allow unmarshalling of the responses 
from cake into registered types. (arp.TypeMappedCommand)

Its pretty simple at the moment, just a for..in scanner and basic copying.

And last, I made my own ControllerTemplate so i could pass parameters to 
commands when dispatching events or just execute commands directly from the 
controller instance.

It all seems to work so far and I like it, whats missing at the moment is 
sending types from flash -> cake and them turning up at the other end in cake 
format.

As you see earlier cake uses a layer around each object to keep its type, so 
what would be needed is something like a subclass / alternative implementation 
of mx.remoting.Service that can use the type mapper to create the extra layer 
so 
that on the cake end you can go from using this :

function save($user)
{
   $this->autoRender = false;
   $this->constructClasses();
   return $this->User->save(array('User'=>$user));
}

to a more normal

..
return $this->User-save($user);
..

and hence be able to use most of the cake code for html and flash without any 
changes.

Now, finally back to the original point of using the code generator.

What would be great is to combine the cake bake script and amfphp code 
generator 
to generate the cake and arp code at the same time, models, commands, service 
locator etc.

Maybe i'll look into that soon, for now the type mapper is useful for me so 
i'll 
probably expand that to do more, like building actionsscipt object associations 
from the returned data by matching id's etc..

id be interested to hear other peoples ideas and thoughts..

:)

martin



Aral Balkan wrote:
> Hi Martin,
> 
> I haven't had time to look into this but ideally, you should be able to 
> use AMFPHP's Arp code generation to do this. Now that my latest project 
> is done, I can actively look into this. (Or, if you beat me to it, I'll 
> owe you a beer! Hint, hint!) :)
> 
> Aral

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to