ModuleMessageInterceptor 与 MessageInterceptor

发布于 2024-11-06 10:25:46 字数 255 浏览 0 评论 0原文

我正在使用 cairngorm 模块库和 Parsley 在 Flex 中开发一个应用程序。

Parsley 文档第 5 章说:“当您想要决定是否应将消息传递给处理程序时,拦截器可能会派上用场”。

当使用 ModuleMessageInterceptor 时,上述情况不成立。这意味着我的 MessageHandler 在 MessageInterceptor 之前接收到消息。

有谁知道解决办法吗?

问候,

法迪

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╄→承喏 2024-11-13 10:25:46

这个问题的解决方案是扩展 ModuleMessageInterceptor 类,如下所示:

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;
        }
    }
}

通过执行上述操作,我们已将 order 属性添加到 ModuleMessageInterceptor 中,这解决了我遇到的问题。

问候,

法迪·曼苏尔

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

人心善变 2024-11-13 10:25:46

在 Parsley 2.4 中,MessageInterceptors 已被废弃:

ModuleMessageInterceptor 不是 Parsley 的东西,而是 Cairngorm 的东西。就我个人而言,由于我的经验,我会完全远离凯恩戈姆。上网查了一下,其他人也有类似的问题。您最好的选择是在同一个论坛上发帖并希望有人提供帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文