jsf源代码分析之FactoryFinder的问题(在线等)
如题,我在看JSF源代码的时候,在看javax.faces.FactoryFinder类时,有些疑惑,望大家共同探讨,找到解决问题的答案。
在FactoryFinder的
public static Object getFactory(String factoryName)
throws FacesException {
validateFactoryName(factoryName);
// Identify the web application class loader
ClassLoader classLoader = getClassLoader();
synchronized (applicationMaps) {
Map appMap = getApplicationMap();
// assert(null != appMap);
Object
factory = null,
factoryOrList = appMap.get(factoryName);
// If this factory has been retrieved before
if (factoryOrList != null && (!(factoryOrList instanceof List))) {
// just return it.
return (factoryOrList);
}
// else, this factory has not been retrieved before; let's
// find it.
factory = getImplementationInstance(classLoader, factoryName,
(List) factoryOrList);
// Record and return the new instance
appMap.put(factoryName, factory);
return (factory);
}
}
调用getImplementationInstance方法
private static Object getImplementationInstance(ClassLoader classLoader,
String factoryName,
List implementations)
throws FacesException {
Object result = null;
String curImplClass = null;
int len = 0, i = 0;
// step 1.
if (null != implementations &&
(1 < (len = implementations.size()) || 1 == len)) {
curImplClass = (String) implementations.remove(len - 1);
// since this is the hard coded implementation default,
// there is no preceding implementation, so don't bother
// with a non-zero-arg ctor.
result = getImplGivenPreviousImpl(classLoader, factoryName,
curImplClass, null);
}
// step 2.
if (null != (curImplClass = getImplNameFromServices(classLoader,
factoryName))) {
result = getImplGivenPreviousImpl(classLoader, factoryName,
curImplClass, result);
}
// step 3.
if (null != implementations) {
for (len = (implementations.size() - 1); 0 <= len; len--) {
curImplClass = (String) implementations.remove(len);
result = getImplGivenPreviousImpl(classLoader, factoryName,
curImplClass, result);
}
}
return result;
}
它的执行顺序应该是怎样的,step1和step3有什么区别,step2什么时候能正常运行。