KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > config > SecurityConfigFactory


1 package com.atlassian.seraph.config;
2
3 /**
4  * Factory for {@link SecurityConfig} instances.
5  */

6 public class SecurityConfigFactory
7 {
8     private static SecurityConfig instance;
9
10     /** Get a SecurityConfig instance.
11      * @return A default implementation of SecurityConfig.
12      * @throws RuntimeException If loading the configuration failed.
13      */

14     public static SecurityConfig getInstance()
15     {
16         if (instance == null)
17             loadInstance(SecurityConfigImpl.DEFAULT_CONFIG_LOCATION);
18         return instance;
19     }
20
21     /** Get a SecurityConfig instance.
22      *
23      * @param configFileLocation Path to config file resource (usu. 'seraph-config.xml')
24      * @return
25      * @throws RuntimeException If loading the configuration failed.
26      */

27     public static SecurityConfig getInstance(final String JavaDoc configFileLocation)
28     {
29         if (instance == null)
30             loadInstance(configFileLocation);
31         return instance;
32     }
33
34
35     /** Set the SecurityConfig instance to return. Useful for unit tests. */
36     public static void setSecurityConfig(final SecurityConfig securityConfig)
37     {
38         instance = securityConfig;
39     }
40
41
42     private static void loadInstance(final String JavaDoc configFileLocation)
43     {
44         try
45         {
46             instance = new SecurityConfigImpl(configFileLocation);
47         }
48         catch (ConfigurationException e)
49         {
50             e.printStackTrace();
51             throw new RuntimeException JavaDoc("Could not load security config '"+configFileLocation+"': " + e.getMessage());
52         }
53     }
54
55     // Factories should never be instantiated
56
private SecurityConfigFactory() {}
57
58 }
59
Popular Tags