acegi 之 FilterInvocationDefinitionSourceEditor

引用自 http://www.iteye.com/post/475224
Spring Reference Guide states:

Quote:
Spring uses the java.beans.PropertyEditorManager to set the search-path for property editors that might be
needed. The search-path also includes sun.bean.editors, which includes PropertyEditors for Font, Color and
all the primitive types.
The JavaDocs for PropertyEditorManager states:

Quote:
The PropertyEditorManager uses three techniques for locating an editor for a given type. First, it provides a registerEditor method to allow an editor to be specifically registered for a given type. Second it tries to locate a suitable class by adding "Editor" to the full qualified classname of the given type (e.g. "foo.bah.FozEditor"). Finally it takes the simple classname (without the package name) adds "Editor" to it and looks in a search-path of packages for a matching cl

 

曾经查看Acegi的源码,FilterSecurityInterceptor的objectDefinitionSource属性的类型为FilterInvocationDefinitionSource,猜测Acegi是使用FilterInvocationDefinitionSourceEditor 读取配置并赋值给它(objectDefinitionSource)的,因为查看FilterInvocationDefinitionSourceEditor 的源码,其中有相关的读取配置的代码。但FilterInvocationDefinitionSourceEditor 是在何时及如何被调用的呢?

在Spring的官方论坛中找到一个帖子:http://forum.springframework.org/showthread.php?t=11242&highlight=objectDefinitionSource

其中提到:

引用
The PropertyEditorManager uses three techniques for locating an editor for a given type. First, it provides a registerEditor method to allow an editor to be specifically registered for a given type. Second it tries to locate a suitable class by adding "Editor" to the full qualified classname of the given type (e.g. "foo.bah.FozEditor"). Finally it takes the simple classname (without the package name) adds "Editor" to it and looks in a search-path of packages for a matching class.


PropertyEditorManager 是java.beans包中的一个类,难道其中的根据“类型名称+Editor”来查找属性相应的编辑器(姑且这么翻译)的机制是Java早就拥有的?查 看JDK中PropertyEditorManager相关的内容,果然找到上面的那段话!

原来是这样!难怪在Spring、Acegi的源码中都找不到注册或调用 FilterInvocationDefinitionSourceEditor 的代码。我以为这是Spring或Acegi提供的机制,原来是Java的标准机制!

至此可以理解读取配置并给属性赋值的过程大致如下:
1.Spring读取Acegi相关的配置,知道需要把类似

引用
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/secured/usermanage/**=ROLE_TEST
/secured/**=ROLE_USER



的内容赋值给bean filterSecurityInterceptor的objectDefinitionSource属性

2.Spring 知道filterSecurityInterceptor的objectDefinitionSource属性的类型为 FilterInvocationDefinitionSource,查找该类型的编辑器。因为Acegi并未为该类型显式地注册编辑器(查Acegi代 码可知),Spring应用上面的规则查到相应的编辑器为FilterInvocationDefinitionSourceEditor

3.Spring实例化FilterInvocationDefinitionSourceEditor ,并调用它完成后续的读取配置并给属性赋值的工作

 

 

你可能感兴趣的:(spring,PHP,bean,ant,Acegi)