OpenSource的東西有點(diǎn)好處就是有問(wèn)題隨時(shí)可以看代碼解決。
但是讀代碼也有訣竅,就是盡可能的抓住和你有關(guān)的那部分,不要在一大堆代碼里浪費(fèi)時(shí)間。

第一個(gè)挑出org.hibernate.cfg.Configuration。因?yàn)檫@個(gè)東西用得最多。

例如addXXXX方法最后都調(diào)用到add方法,一下子就可以跳過(guò)N多段代碼直接看add方法

    protected void add(org.dom4j.Document doc) throws MappingException {
        HbmBinder.bindRoot( doc, createMappings(), CollectionHelper.EMPTY_MAP );
    }


bindRoot方法稍微看了一下,一看到是解析xml的,就可以跳過(guò)不看。其實(shí)猜也能猜到是解析hbm.xml的。

有意思的是".hbm.xml"在里面是固定寫(xiě)死的,連個(gè)constant 變量都沒(méi)有做,看來(lái)作者以后是不打算改了

且看addDirectory方法
    /**
     * Read all mapping documents from a directory tree.
     * <p/>
     * Assumes that any file named <tt>*.hbm.xml</tt> is a mapping document.
     *
     * 
@param dir The directory
     * 
@return this (for method chaining purposes)
     * 
@throws MappingException Indicates problems reading the jar file or
     * processing the contained mapping documents.
     
*/
    
public Configuration addDirectory(File dir) throws MappingException {
        File[] files 
= dir.listFiles();
        
for ( int i = 0; i < files.length ; i++ ) {
            
if ( files[i].isDirectory() ) {
                addDirectory( files[i] );
            }
            
else if ( files[i].getName().endsWith( ".hbm.xml" ) ) {
                addFile( files[i] );
            }
        }
        
return this;
    }

這段代碼告訴我們什么?告訴我們".hbm.xml"素區(qū)分大小寫(xiě)的。。。。.HBM.XML這樣的后綴名作者不打算接受。。。