KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > RepositoryFactory


1 package com.sslexplorer.boot;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 /**
7  * Factory class to get an instance of the configure {@link com.sslexplorer.boot.Repository}.
8  * <p>
9  * If the repository has already been created then the same instance will be
10  * returned.
11  * <p>
12  * The repository implementation to use is determined by the value of
13  * the <i>sslexplorer.repositoryClass</i> system property that should contain
14  * the full qualified class name to use.
15  *
16  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
17  * @see com.sslexplorer.boot.LocalRepository
18  */

19 public class RepositoryFactory {
20     static Repository instance;
21     static Log log = LogFactory.getLog(RepositoryFactory.class);
22
23     /**
24      * Get an instance of the configured repository.
25      *
26      * @return repository
27      */

28     public static Repository getRepository() {
29         if (instance != null)
30             return instance;
31         try {
32             if (System.getProperty("sslexplorer.repositoryClass") != null) {
33                 instance = (Repository) Class.forName(System.getProperty("sslexplorer.repositoryClass")).newInstance();
34             } else
35                 instance = new LocalRepository();
36         } catch (Exception JavaDoc e) {
37             log.error("Failed to initialize repository", e);
38             return null;
39         }
40         return instance;
41     }
42 }
43
Popular Tags