01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.repository;
05:
06: import com.tc.config.schema.validate.ConfigurationValidator;
07: import com.tc.util.Assert;
08: import com.terracottatech.config.Application;
09:
10: import java.util.Arrays;
11: import java.util.HashMap;
12: import java.util.HashSet;
13: import java.util.Iterator;
14: import java.util.List;
15: import java.util.Map;
16: import java.util.Set;
17:
18: /**
19: * The standard implementation of {@link ApplicationsRepository}.
20: */
21: public class StandardApplicationsRepository implements
22: ApplicationsRepository {
23:
24: private final Map applications;
25: private final Set configurationValidators;
26:
27: public StandardApplicationsRepository() {
28: this .applications = new HashMap();
29: this .configurationValidators = new HashSet();
30: }
31:
32: public void addRepositoryValidator(ConfigurationValidator validator) {
33: Assert.assertNotNull(validator);
34: this .configurationValidators.add(validator);
35: }
36:
37: public synchronized MutableBeanRepository repositoryFor(
38: String applicationName) {
39: Assert.assertNotBlank(applicationName);
40:
41: MutableBeanRepository out = (MutableBeanRepository) this .applications
42: .get(applicationName);
43: if (out == null) {
44: out = new StandardBeanRepository(Application.class);
45:
46: Iterator iter = this .configurationValidators.iterator();
47: while (iter.hasNext()) {
48: out.addValidator((ConfigurationValidator) iter.next());
49: }
50:
51: this .applications.put(applicationName, out);
52: }
53:
54: return out;
55: }
56:
57: public synchronized Iterator applicationNames() {
58: List names = Arrays.asList(this .applications.keySet().toArray(
59: new String[this.applications.size()]));
60: return names.iterator();
61: }
62:
63: }
|