1 package com.atlassian.user.configuration;
2
3 import com.atlassian.user.repository.RepositoryIdentifier;
4
5 import java.util.Map;
6 import java.util.Set;
7 import java.util.Collections;
8 import java.util.HashMap;
9
10 import org.apache.log4j.Logger;
11
12 public class DefaultRepositoryConfiguration implements RepositoryConfiguration
13 {
14 protected final Logger logger = Logger.getLogger(getClass());
15 private final RepositoryIdentifier identifier;
16 private final RepositoryProcessor processor;
17 private final Map<String, Object> components;
18 private final Map componentClassNames;
19 private CacheConfiguration cacheConfiguration;
20
21 public DefaultRepositoryConfiguration(RepositoryIdentifier identifier, RepositoryProcessor processor, Map<String, String> components, Map componentClassNames)
22 {
23 this.identifier = identifier;
24 this.processor = processor;
25 this.components = new HashMap<String, Object>(components);
26 this.componentClassNames = componentClassNames;
27 }
28
29 public void addComponent(String componentName, Object component)
30 {
31 if (hasComponent(componentName))
32 logger.info("Overwriting existing component with name [" + componentName + "]");
33 components.put(componentName, component);
34 }
35
36 public Object getComponent(String componentName)
37 {
38 return components.get(componentName);
39 }
40
41 public String getStringComponent(String componentName)
42 {
43 return (String) getComponent(componentName);
44 }
45
46 public boolean hasComponent(String componentName)
47 {
48 return components.containsKey(componentName) && components.get(componentName) != null;
49 }
50
51 public String getComponentClassName(String componentName)
52 {
53 return (String) componentClassNames.get(componentName);
54 }
55
56 public RepositoryAccessor configure() throws ConfigurationException
57 {
58 return processor.process(this);
59 }
60
61 public RepositoryIdentifier getIdentifier()
62 {
63 return identifier;
64 }
65
66 public boolean hasClassForComponent(String componentName)
67 {
68 return componentClassNames.containsKey(componentName);
69 }
70
71 public Set getComponentNames()
72 {
73 return Collections.unmodifiableSet(components.keySet());
74 }
75
76 public void setCacheConfiguration(CacheConfiguration cacheConfiguration)
77 {
78 this.cacheConfiguration = cacheConfiguration;
79 }
80
81 public boolean isCachingEnabled()
82 {
83 return cacheConfiguration != null;
84 }
85
86 public CacheConfiguration getCacheConfiguration()
87 {
88 return cacheConfiguration;
89 }
90 }