longsleep / as3-commons

Automatically exported from code.google.com/p/as3-commons
1 stars 1 forks source link

Introducing an Interface fails on bytecode 1.0RC3 #57

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When trying to generate a proxy with an intrdocued interface, I get the below 
error when invoking generateProxyClasses()

Cannot invoke loadProxyClasses() while the factory is busy generating proxy 
classes.com.mangofactory.parsley.IAccountService

Failing unit test attached.

    public class SampleTests
    {
        [BeforeClass]
        public static function setup():void
        {
            ByteCodeType.fromLoader(FlexGlobals.topLevelApplication.loaderInfo);
        }
        [Test(async)]
        public function tryBuildingService():void
        {
            var proxyfactory:IProxyFactory = new ProxyFactory();
            var proxyInfo:IClassProxyInfo = proxyfactory.defineProxy(RemoteObject);
            proxyInfo.introduce(IAccountService);
            proxyfactory.generateProxyClasses(); // <--- Test fails on this line
            var handler:Function = Async.asyncHandler(this,onProxyBuilt,2000,proxyfactory);
            proxyfactory.addEventListener(Event.COMPLETE,handler);
            proxyfactory.addEventListener(IOErrorEvent.VERIFY_ERROR,handler);
            proxyfactory.loadProxyClasses();

        }

        private function onProxyBuilt(event:Event,args:Array):void
        {
            assertThat(event.type,equalTo(Event.COMPLETE));
        }
}

package com.mangofactory.parsley
{
    public interface IAccountService
    {
        function validatePassword(password:String):Boolean;
    }
}

Original issue reported on code.google.com by martypit...@gtempaccount.com on 18 Jun 2011 at 6:01

GoogleCodeExporter commented 9 years ago
Ah, I think I understand -- the issue is that you can't introduce an Interface, 
only another class (and then the proxy inherits any interfaces implemented on 
that class).

It would be nice if I could introduce an iterface this way, and allow the 
method interceptor to handle the implementation, essentially providing a 
shorthand approach, rather than hooking the ClassBuilder.

Original comment by martypit...@gtempaccount.com on 18 Jun 2011 at 6:12

GoogleCodeExporter commented 9 years ago
hey there,

yep, you are correct, introduce() is actually a merge of an existing class with 
the generated proxy.
As for your ideas about using the method interceptor, this might be interesting 
indeed. What do you think would be the most intuitive approach for this?

Would a developer use the introduce() method for both situations? Or should I 
just add a proxyInterface() method that automatically adds the interfaces 
methods to the generated proxy? I guess the latter would be clearer, right?

cheers,

Roland

Original comment by ihatelivelyids on 19 Jun 2011 at 8:51

GoogleCodeExporter commented 9 years ago
I think that if you're introducing an interface, the developer should be 
responsible for also providing the interceptor responsible for the methods.  
Therefore, as the signatures would be different, I guess a seperate method:

function 
introduceInterface(interface:Class,interceptor:IMethodInvocationInterceptor):voi
d;

Thanks for the feedback - much appreciated.

Cheers,

Marty

Original comment by martypit...@gtempaccount.com on 20 Jun 2011 at 11:11

GoogleCodeExporter commented 9 years ago
Ok,

I've added a implementInterface() method to the IClassProxyInfo. I decided not 
to use 'introcudeInterface' since this would be even more confusing with the 
already existing introduce() method.
implementInterface() will dynamically add all of the members of the interface 
to the proxy class. It is up to the existing IMethodInvocationInterceptor(s) to 
figure out where the intercepted methods belong to. The IMethodInvocation 
instance holds enough contextual information for this I'd say.

Thanks for suggesting this feature!

cheers,

Roland

Original comment by ihatelivelyids on 3 Sep 2011 at 8:47

GoogleCodeExporter commented 9 years ago
Ow, the changes are currently only available in the trunk.
I'm having issues with our Nexus server so I can't make a release for the 
moment, once this is sorted I'll release RC6 of the bytecode library.

cheers,

ROland

Original comment by ihatelivelyids on 3 Sep 2011 at 8:48