PropertyEditorRegistrySupport.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:lams 作者:
/**
 * Get custom editor for the given type. If no direct match found,
 * try custom editor for superclass (which will in any case be able
 * to render a value as String via {@code getAsText}).
 * @param requiredType the type to look for
 * @return the custom editor, or {@code null} if none found for this type
 * @see java.beans.PropertyEditor#getAsText()
 */
private PropertyEditor getCustomEditor(Class<?> requiredType) {
    if (requiredType == null || this.customEditors == null) {
        return null;
    }
    // Check directly registered editor for type.
    PropertyEditor editor = this.customEditors.get(requiredType);
    if (editor == null) {
        // Check cached editor for type, registered for superclass or interface.
        if (this.customEditorCache != null) {
            editor = this.customEditorCache.get(requiredType);
        }
        if (editor == null) {
            // Find editor for superclass or interface.
            for (Iterator<Class<?>> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
                Class<?> key = it.next();
                if (key.isAssignableFrom(requiredType)) {
                    editor = this.customEditors.get(key);
                    // Cache editor for search type, to avoid the overhead
                    // of repeated assignable-from checks.
                    if (this.customEditorCache == null) {
                        this.customEditorCache = new HashMap<Class<?>, PropertyEditor>();
                    }
                    this.customEditorCache.put(requiredType, editor);
                }
            }
        }
    }
    return editor;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号