jsf源代码分析之FactoryFinder的问题(在线等)

GONHON 2006-08-21 04:43:12
如题,我在看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什么时候能正常运行。
...全文
280 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jl_lsj 2006-08-24
  • 打赏
  • 举报
回复
刚接触这东西,关注^^^^^^
GONHON 2006-08-24
  • 打赏
  • 举报
回复
怎么没人顶,JSF有人用过吗?帮帮忙!
GONHON 2006-08-21
  • 打赏
  • 举报
回复
自已顶一下,怎么没人支持呀!
GONHON 2006-08-21
  • 打赏
  • 举报
回复
step2用到的方法
private static String getImplNameFromServices(ClassLoader classLoader,
String factoryName) {

// Check for a services definition
String result = null;
BufferedReader reader = null;
String resourceName = "META-INF/services/" + factoryName;
Properties props = null;
InputStream stream = null;
try {
stream = classLoader.getResourceAsStream(resourceName);
if (stream != null) {
// Deal with systems whose native encoding is possibly
// different from the way that the services entry was created
try {
reader =
new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
} catch (UnsupportedEncodingException e) {
reader = new BufferedReader(new InputStreamReader(stream));
}
result = reader.readLine();
reader.close();
reader = null;
stream = null;
}
} catch (IOException e) {
} catch (SecurityException e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
;
}
reader = null;
stream = null;
}
if (stream != null) {
try {
stream.close();
} catch (Throwable t) {
;
}
stream = null;
}
}
return result;
}
我找了很久String resourceName = "META-INF/services/" + factoryName;找不到,这个我觉得应该是通过子类来实例化工厂。

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧