Package com.alibaba.citrus.service.mappingrule

Examples of com.alibaba.citrus.service.mappingrule.MappingRuleService


            // controlTool支持跨component调用,现在取得指定component下的service。
            ModuleLoaderService moduleLoaderService = getService("moduleLoaderService", componentName,
                                                                 this.moduleLoaderService, ModuleLoaderService.class);

            MappingRuleService mappingRuleService = getService("mappingRuleService", componentName,
                                                               this.mappingRuleService, MappingRuleService.class);

            TemplateService templateService = getService("templateService", componentName, this.templateService,
                                                         TemplateService.class);

            // 取得实际的template/module名称
            String templateName = null;
            String moduleName = null;

            if (isTemplate) {
                templateName = target;
                moduleName = mappingRuleService.getMappedName(CONTROL_MODULE, target);
            } else {
                moduleName = mappingRuleService.getMappedName(CONTROL_MODULE_NO_TEMPLATE, target);
            }

            // 执行control module
            Module controlModule;

            if (templateName == null) {
                // templateName未指定时,必须有module,如没有则抛出ModuleNotFoundException
                controlModule = moduleLoaderService.getModule(CONTROL_MODULE, moduleName);
            } else {
                // 当指定了templateName时,可以没有的control module,而单单渲染模板。
                // 这样就实现了page-driven,即先写模板,必要时再写一个module class与之对应。
                controlModule = moduleLoaderService.getModuleQuiet(CONTROL_MODULE, moduleName);
            }

            if (log.isTraceEnabled()) {
                if (templateName != null) {
                    log.trace("Rendering control: template=" + templateName + ", control=" + moduleName);
                } else {
                    log.trace("Rendering control without template: control=" + moduleName);
                }
            }

            // 设置参数
            this.bufferedRequestContext.pushBuffer();

            try {
                controlParameterStack.addFirst(new ControlParameters()); // 支持control的嵌套

                TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(this.request);
                Context contextForControl = createContextForControl(params, componentName);

                rundata.pushContext(contextForControl, templateName);

                try {
                    if (controlModule != null) {
                        controlModule.execute();
                    }

                    // Control module可以通过注入ControlParameters接口来修改template。
                    String templateOverriden = rundata.getControlTemplate();

                    if (!isEquals(templateOverriden, templateName)) {
                        log.debug("Control template has been changed by module: " + templateName + " -> "
                                  + templateOverriden);

                        templateName = templateOverriden;
                    }

                    if (templateName != null) {
                        templateName = mappingRuleService.getMappedName(CONTROL_TEMPLATE, templateName);
                    }

                    if (templateName != null) {
                        templateService.writeTo(templateName, new ContextAdapter(contextForControl), rundata
                                .getResponse().getWriter());
View Full Code Here


            // controlTool֧�ֿ�component���ã�����ȡ��ָ��component�µ�service��
            ModuleLoaderService moduleLoaderService = getService("moduleLoaderService", componentName,
                    this.moduleLoaderService, ModuleLoaderService.class);

            MappingRuleService mappingRuleService = getService("mappingRuleService", componentName,
                    this.mappingRuleService, MappingRuleService.class);

            TemplateService templateService = getService("templateService", componentName, this.templateService,
                    TemplateService.class);

            // ȡ��ʵ�ʵ�template/module����
            String templateName = null;
            String moduleName = null;

            if (isTemplate) {
                templateName = target;
                moduleName = mappingRuleService.getMappedName(CONTROL_MODULE, target);
            } else {
                moduleName = mappingRuleService.getMappedName(CONTROL_MODULE_NO_TEMPLATE, target);
            }

            // ִ��control module
            Module controlModule;

            if (templateName == null) {
                // templateNameδָ��ʱ��������module����û�����׳�ModuleNotFoundException
                controlModule = moduleLoaderService.getModule(CONTROL_MODULE, moduleName);
            } else {
                // ��ָ����templateNameʱ������û�е�control module����������Ⱦģ�塣
                // ������ʵ����page-driven������дģ�壬��Ҫʱ��дһ��module class��֮��Ӧ��
                controlModule = moduleLoaderService.getModuleQuiet(CONTROL_MODULE, moduleName);
            }

            if (log.isTraceEnabled()) {
                if (templateName != null) {
                    log.trace("Rendering control: template=" + templateName + ", control=" + moduleName);
                } else {
                    log.trace("Rendering control without template: control=" + moduleName);
                }
            }

            // ���ò���
            this.bufferedRequestContext.pushBuffer();

            try {
                controlParameterStack.addFirst(new ControlParameters()); // ֧��control��Ƕ��

                TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(this.request);
                Context contextForControl = createContextForControl(params, componentName);

                rundata.pushContext(contextForControl, templateName);

                try {
                    if (controlModule != null) {
                        controlModule.execute();
                    }

                    // Control module����ͨ��ע��ControlParameters�ӿ����޸�template��
                    String templateOverriden = rundata.getControlTemplate();

                    if (!isEquals(templateOverriden, templateName)) {
                        log.debug("Control template has been changed by module: " + templateName + " -> "
                                + templateOverriden);

                        templateName = templateOverriden;
                    }

                    if (templateName != null) {
                        templateName = mappingRuleService.getMappedName(CONTROL_TEMPLATE, templateName);
                    }

                    if (templateName != null) {
                        templateService.writeTo(templateName, new ContextAdapter(contextForControl), rundata
                                .getResponse().getWriter());
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.mappingrule.MappingRuleService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.