View Javadoc

1   /***
2    * 
3    */
4   package hu.elte.tribus.util;
5   
6   import java.io.File;
7   
8   import org.apache.lucene.store.Directory;
9   import org.apache.lucene.store.FSDirectory;
10  import org.springframework.beans.factory.FactoryBean;
11  
12  /***
13   * @author kocka
14   *
15   */
16  public class FsDirectoryFactory implements FactoryBean {
17  
18  	String indexDir = null;
19  	
20  	/* (non-Javadoc)
21  	 * @see org.springframework.beans.factory.FactoryBean#getObject()
22  	 */
23  	public Object getObject() throws Exception {
24  		File dir = new File(indexDir);
25  		/*
26  		 * this only row is why this whole class is needed and
27  		 * we can not push it simply to the spring configuration file.
28  		 */
29  		return FSDirectory.getDirectory(dir, !dir.exists());
30  	}
31  
32  	/* (non-Javadoc)
33  	 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
34  	 */
35  	public Class getObjectType() {
36  		return Directory.class;
37  	}
38  
39  	/* (non-Javadoc)
40  	 * @see org.springframework.beans.factory.FactoryBean#isSingleton()
41  	 */
42  	public boolean isSingleton() {
43  		return true;
44  	}
45  
46  	public String getIndexDir() {
47  		return indexDir;
48  	}
49  
50  	public void setIndexDir(String indexDir) {
51  		this.indexDir = indexDir;
52  	}
53  
54  }