Question

I am developing an application in Flex using the cairngorm module library and Parsley.

Parsley documentation chapter 5 says: "Interceptors may come in handy when you want to decide whether or not the message should be passed to handlers".

When using the ModuleMessageInterceptor the above is not true. Which means that my MessageHandler receive the message before the MessageInterceptor.

Does anyone knows a work around?

Regards,

Fadi

Was it helpful?

Solution

The solution to this problem was extending the ModuleMessageInterceptor class as follows:

package fr.core.patch.cairngorm
{
    import com.adobe.cairngorm.module.ModuleIdMetadata;
    import com.adobe.cairngorm.module.ModuleMessageDispatcher;
    import com.adobe.cairngorm.module.ModuleMessageInterceptor;
    import com.adobe.cairngorm.module.ParsleyModuleMessage;

    import flash.system.ApplicationDomain;

    import org.spicefactory.lib.reflect.ClassInfo;
    import org.spicefactory.lib.reflect.Property;
    import org.spicefactory.parsley.core.registry.ObjectDefinitionRegistry;
    import org.spicefactory.parsley.core.registry.RootObjectDefinition;
    import org.spicefactory.parsley.tag.messaging.MessageHandlerDecorator;
    import org.spicefactory.parsley.tag.messaging.MessageInterceptorDecorator;

    public class ATPModuleMessageInterceptor extends ModuleMessageInterceptor
    {
        public function ATPModuleMessageInterceptor()
        {
            super();
        }

        public var order:int;

        private var target:Property;

        override public function process(registry:ObjectDefinitionRegistry):void
        {
            target=getModuleIdTargetProperty(registry.domain);

            var interceptor:MessageInterceptorDecorator=new MessageInterceptorDecorator();
            interceptor.type=type;
            interceptor.selector=selector;
            interceptor.method="interceptModuleMessage";
            interceptor.order = order;

            var messageHandler:MessageHandlerDecorator=new MessageHandlerDecorator();
            messageHandler.type=ParsleyModuleMessage;
            messageHandler.method="parsleyModuleMessageHandler";

            var definition:RootObjectDefinition=registry.builders.forRootDefinition(ModuleMessageDispatcher).decorators([interceptor, messageHandler]).buildAndRegister();

            definition.constructorArgs.addValue(target);

            if (moduleRef)
            {
                definition.constructorArgs.addIdReference(moduleRef);
            }
        }

        private function getModuleIdTargetProperty(domain:ApplicationDomain):Property
        {
            var props:Array=ClassInfo.forClass(type, domain).getProperties();

            for each (var prop:Property in props)
            {
                if (prop.hasMetadata(ModuleIdMetadata))
                {
                    return prop;
                }
            }

            return null;
        }
    }
}

By doing the above we have added the order property to the ModuleMessageInterceptor which solve the problem I had.

Regards,

Fadi Mansour

OTHER TIPS

In Parsley 2.4, MessageInterceptors have been depracated:

And ModuleMessageInterceptor is not a Parsley thing, it's a Cairngorm thing. Personally, I'd stay away of Cairngorm altogether because of my experience with it. After looking online, I saw that other people had similar issues. Your best bet is to post on the same forum and hopes somebody helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top