1 4 package com.tc.config.schema.setup; 5 6 import org.apache.xmlbeans.XmlException; 7 8 import com.tc.config.schema.repository.ApplicationsRepository; 9 import com.tc.config.schema.repository.MutableBeanRepository; 10 import com.tc.util.Assert; 11 12 import java.io.File ; 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 19 public class TestConfigurationCreator implements ConfigurationCreator { 20 21 private final TestConfigBeanSet beanSet; 22 private boolean loadedFromTrustedSource; 23 private final Set allRepositoriesStoredInto; 24 25 public TestConfigurationCreator(TestConfigBeanSet beanSet, boolean trustedSource) { 26 Assert.assertNotNull(beanSet); 27 this.beanSet = beanSet; 28 this.loadedFromTrustedSource = trustedSource; 29 this.allRepositoriesStoredInto = new HashSet (); 30 } 31 32 public synchronized MutableBeanRepository[] allRepositoriesStoredInto() { 33 return (MutableBeanRepository[]) this.allRepositoriesStoredInto 34 .toArray(new MutableBeanRepository[this.allRepositoriesStoredInto.size()]); 35 } 36 37 public boolean loadedFromTrustedSource() { 38 return this.loadedFromTrustedSource; 39 } 40 41 public String describeSources() { 42 return "Dynamically-generated configuration for tests"; 43 } 44 45 public void createConfigurationIntoRepositories(MutableBeanRepository l1BeanRepository, 46 MutableBeanRepository l2sBeanRepository, 47 MutableBeanRepository systemBeanRepository, 48 ApplicationsRepository applicationsRepository) 49 throws ConfigurationSetupException { 50 try { 51 l1BeanRepository.setBean(this.beanSet.clientBean(), "from test config"); 52 addRepository(l1BeanRepository); 53 l1BeanRepository.saveCopyOfBeanInAnticipationOfFutureMutation(); 54 55 l2sBeanRepository.setBean(this.beanSet.serversBean(), "from test config"); 56 addRepository(l2sBeanRepository); 57 l2sBeanRepository.saveCopyOfBeanInAnticipationOfFutureMutation(); 58 59 systemBeanRepository.setBean(this.beanSet.systemBean(), "from test config"); 60 addRepository(systemBeanRepository); 61 systemBeanRepository.saveCopyOfBeanInAnticipationOfFutureMutation(); 62 63 String [] allNames = this.beanSet.applicationNames(); 64 for (int i = 0; i < allNames.length; ++i) { 65 MutableBeanRepository repository = applicationsRepository.repositoryFor(allNames[i]); 66 addRepository(repository); 67 repository.setBean(this.beanSet.applicationBeanFor(allNames[i]), "from test config"); 68 repository.saveCopyOfBeanInAnticipationOfFutureMutation(); 69 } 70 } catch (XmlException xmle) { 71 throw new ConfigurationSetupException("Unable to set bean", xmle); 72 } 73 } 74 75 public File directoryConfigurationLoadedFrom() { 76 return null; 77 } 78 79 private synchronized void addRepository(MutableBeanRepository theRepository) { 80 this.allRepositoriesStoredInto.add(theRepository); 81 } 82 83 } 84 | Popular Tags |