KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > repository > StandardApplicationsRepository


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.repository;
5
6 import com.tc.config.schema.validate.ConfigurationValidator;
7 import com.tc.util.Assert;
8 import com.terracottatech.config.Application;
9
10 import java.util.Arrays JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.HashSet JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * The standard implementation of {@link ApplicationsRepository}.
20  */

21 public class StandardApplicationsRepository implements ApplicationsRepository {
22
23   private final Map JavaDoc applications;
24   private final Set JavaDoc configurationValidators;
25
26   public StandardApplicationsRepository() {
27     this.applications = new HashMap JavaDoc();
28     this.configurationValidators = new HashSet JavaDoc();
29   }
30
31   public void addRepositoryValidator(ConfigurationValidator validator) {
32     Assert.assertNotNull(validator);
33     this.configurationValidators.add(validator);
34   }
35
36   public synchronized MutableBeanRepository repositoryFor(String JavaDoc applicationName) {
37     Assert.assertNotBlank(applicationName);
38
39     MutableBeanRepository out = (MutableBeanRepository) this.applications.get(applicationName);
40     if (out == null) {
41       out = new StandardBeanRepository(Application.class);
42
43       Iterator JavaDoc iter = this.configurationValidators.iterator();
44       while (iter.hasNext()) {
45         out.addValidator((ConfigurationValidator) iter.next());
46       }
47
48       this.applications.put(applicationName, out);
49     }
50
51     return out;
52   }
53
54   public synchronized Iterator JavaDoc applicationNames() {
55     List JavaDoc names = Arrays.asList(this.applications.keySet().toArray(new String JavaDoc[this.applications.size()]));
56     return names.iterator();
57   }
58
59 }
60
Popular Tags