1 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 ; 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 21 public class StandardApplicationsRepository implements ApplicationsRepository { 22 23 private final Map applications; 24 private final Set configurationValidators; 25 26 public StandardApplicationsRepository() { 27 this.applications = new HashMap (); 28 this.configurationValidators = new HashSet (); 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 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 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 applicationNames() { 55 List names = Arrays.asList(this.applications.keySet().toArray(new String [this.applications.size()])); 56 return names.iterator(); 57 } 58 59 } 60 | Popular Tags |