1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache.config;
18
19 import net.sf.ehcache.ObjectExistsException;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Set;
24
25
26
27
28
29
30 public final class Configuration {
31
32 private DiskStoreConfiguration diskStoreConfiguration;
33 private CacheConfiguration defaultCacheConfiguration;
34 private FactoryConfiguration cacheManagerPeerProviderFactoryConfiguration;
35 private FactoryConfiguration cacheManagerPeerListenerFactoryConfiguration;
36 private FactoryConfiguration cacheManagerEventListenerFactoryConfiguration;
37 private final Map cacheConfigurations = new HashMap();
38 private String configurationSource;
39
40
41
42
43
44
45
46 public Configuration() { }
47
48
49
50
51
52 public final void addDiskStore(DiskStoreConfiguration diskStoreConfigurationParameter) throws ObjectExistsException {
53 if (diskStoreConfiguration != null) {
54 throw new ObjectExistsException("The Disk Store has already been configured");
55 }
56 diskStoreConfiguration = diskStoreConfigurationParameter;
57 }
58
59
60
61
62
63
64 public final void addCacheManagerEventListenerFactory(FactoryConfiguration
65 cacheManagerEventListenerFactoryConfiguration) throws ObjectExistsException {
66 if (this.cacheManagerEventListenerFactoryConfiguration == null) {
67 this.cacheManagerEventListenerFactoryConfiguration = cacheManagerEventListenerFactoryConfiguration;
68 }
69 }
70
71
72
73
74
75
76 public final void addCacheManagerPeerProviderFactory(FactoryConfiguration factory) {
77 if (cacheManagerPeerProviderFactoryConfiguration == null) {
78 cacheManagerPeerProviderFactoryConfiguration = factory;
79 }
80 }
81
82
83
84
85
86
87 public final void addCacheManagerPeerListenerFactory(FactoryConfiguration factory) {
88 if (cacheManagerPeerListenerFactoryConfiguration == null) {
89 cacheManagerPeerListenerFactoryConfiguration = factory;
90 }
91 }
92
93
94
95
96
97 public final void addDefaultCache(CacheConfiguration defaultCacheConfiguration) throws ObjectExistsException {
98 if (this.defaultCacheConfiguration != null) {
99 throw new ObjectExistsException("The Default Cache has already been configured");
100 }
101 this.defaultCacheConfiguration = defaultCacheConfiguration;
102 }
103
104
105
106
107 public final void addCache(CacheConfiguration cacheConfiguration) throws ObjectExistsException {
108 if (cacheConfigurations.get(cacheConfiguration.name) != null) {
109 throw new ObjectExistsException("Cannot create cache: " + cacheConfiguration.name
110 + " with the same name as an existing one.");
111 }
112 if (cacheConfiguration.name.equalsIgnoreCase(net.sf.ehcache.Cache.DEFAULT_CACHE_NAME)) {
113 throw new ObjectExistsException("The Default Cache has already been configured");
114 }
115
116 cacheConfigurations.put(cacheConfiguration.name, cacheConfiguration);
117 }
118
119
120
121
122 public final Set getCacheConfigurationsKeySet() {
123 return cacheConfigurations.keySet();
124 }
125
126
127
128
129 public final CacheConfiguration getDefaultCacheConfiguration() {
130 return defaultCacheConfiguration;
131 }
132
133
134
135
136
137 public final void setDefaultCacheConfiguration(CacheConfiguration defaultCacheConfiguration) {
138 this.defaultCacheConfiguration = defaultCacheConfiguration;
139 }
140
141
142
143
144
145 public final DiskStoreConfiguration getDiskStoreConfiguration() {
146 return diskStoreConfiguration;
147 }
148
149
150
151
152 public final FactoryConfiguration getCacheManagerPeerProviderFactoryConfiguration() {
153 return cacheManagerPeerProviderFactoryConfiguration;
154 }
155
156
157
158
159 public final FactoryConfiguration getCacheManagerPeerListenerFactoryConfiguration() {
160 return cacheManagerPeerListenerFactoryConfiguration;
161 }
162
163
164
165
166 public final FactoryConfiguration getCacheManagerEventListenerFactoryConfiguration() {
167 return cacheManagerEventListenerFactoryConfiguration;
168 }
169
170
171
172
173 public final Map getCacheConfigurations() {
174 return cacheConfigurations;
175 }
176
177
178
179
180
181
182 public final void setSource(String configurationSource) {
183 this.configurationSource = configurationSource;
184 }
185
186
187
188
189 public final String getConfigurationSource() {
190 return configurationSource;
191 }
192 }