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());
}
} finally {
rundata.popContext();
}