1. 页面创建
a) 说明:页面创建主要是指当页面文件被找到以后,如何根据声明中的信息,初始化页面类及其控件树。
b) 流程图:
c) 代码:
i. IPageLoader.loadPage()
public IPage loadPage(String name, INamespace namespace, IRequestCycle cycle,
IComponentSpecification specification){
IPage page = null;
_count = 0;
_depth = 0;
_maxDepth = 0;
_locale = _threadLocale.getLocale();
try{
page = instantiatePage(name, namespace, specification);
page.attach(cycle.getEngine(), cycle);
constructComponent(cycle, page, page, specification, namespace);
……
page.firePageAttached();
}finally{
_locale = null;
_inheritedBindingQueue.clear();
}
return page;
}
注:上述代码描述了页面创建过程的基本骨架,首先是对页面类进行实例化,然后注入所需要的上下文信息,然后就是构造页面的整棵控件树。最后是发出通知。
ii. ComponentConstructorFactory.getComponentCoustructor()
public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
String className){
synchronized (specification){
ComponentConstructor result = (ComponentConstructor) _cachedConstructors.
get(specification);
if (result == null){
Class baseClass = _classResolver.findClass(className); EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
specification, baseClass, _classFactory, _log); _chain.performEnhancement(eo, specification);
result = eo.getConstructor();
// TODO: This should be optional to work around that IBM JVM bug.
_validator.validate(baseClass, result.getComponentClass(), specification);
_cachedConstructors.put(specification, result);
}
return result;
}
}
注:上述代码解释了为什么在得到了页面类以后,还要专门通过ComponentConstructorFactory来获得构造
函数,然后实例化。由于我们声明的页面类可能是一些抽象类,它包含了一些抽象的属性操作方法,这些方
法的实现就是在这一步完成的。