1 4 package com.tc.config.schema.setup; 5 6 import org.apache.xmlbeans.XmlObject; 7 8 import com.tc.config.schema.IllegalConfigurationChangeHandler; 9 import com.tc.config.schema.context.ConfigContext; 10 import com.tc.config.schema.context.StandardConfigContext; 11 import com.tc.config.schema.defaults.DefaultValueProvider; 12 import com.tc.config.schema.repository.ApplicationsRepository; 13 import com.tc.config.schema.repository.BeanRepository; 14 import com.tc.config.schema.repository.ChildBeanFetcher; 15 import com.tc.config.schema.repository.ChildBeanRepository; 16 import com.tc.config.schema.repository.MutableBeanRepository; 17 import com.tc.config.schema.repository.StandardApplicationsRepository; 18 import com.tc.config.schema.repository.StandardBeanRepository; 19 import com.tc.config.schema.utils.XmlObjectComparator; 20 import com.tc.object.config.schema.NewDSOApplicationConfig; 21 import com.tc.object.config.schema.NewDSOApplicationConfigObject; 22 import com.tc.object.config.schema.NewSpringApplicationConfig; 23 import com.tc.object.config.schema.NewSpringApplicationConfigObject; 24 import com.tc.util.Assert; 25 import com.terracottatech.config.Application; 26 import com.terracottatech.config.Client; 27 import com.terracottatech.config.DsoApplication; 28 import com.terracottatech.config.Servers; 29 import com.terracottatech.config.SpringApplication; 30 import com.terracottatech.config.System; 31 32 import java.io.File ; 33 import java.util.HashMap ; 34 import java.util.HashSet ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 41 public class BaseTVSConfigurationSetupManager { 42 43 private final MutableBeanRepository clientBeanRepository; 44 private final MutableBeanRepository serversBeanRepository; 45 private final MutableBeanRepository systemBeanRepository; 46 private final ApplicationsRepository applicationsRepository; 47 48 private final DefaultValueProvider defaultValueProvider; 49 private final XmlObjectComparator xmlObjectComparator; 50 private final IllegalConfigurationChangeHandler illegalConfigurationChangeHandler; 51 52 private final Map dsoApplicationConfigs; 53 private final Map springApplicationConfigs; 54 55 public BaseTVSConfigurationSetupManager(DefaultValueProvider defaultValueProvider, 56 XmlObjectComparator xmlObjectComparator, 57 IllegalConfigurationChangeHandler illegalConfigurationChangeHandler) { 58 Assert.assertNotNull(defaultValueProvider); 59 Assert.assertNotNull(xmlObjectComparator); 60 Assert.assertNotNull(illegalConfigurationChangeHandler); 61 62 this.systemBeanRepository = new StandardBeanRepository(System .class); 63 this.clientBeanRepository = new StandardBeanRepository(Client.class); 64 this.serversBeanRepository = new StandardBeanRepository(Servers.class); 65 this.applicationsRepository = new StandardApplicationsRepository(); 66 67 this.defaultValueProvider = defaultValueProvider; 68 this.xmlObjectComparator = xmlObjectComparator; 69 this.illegalConfigurationChangeHandler = illegalConfigurationChangeHandler; 70 71 this.dsoApplicationConfigs = new HashMap (); 72 this.springApplicationConfigs = new HashMap (); 73 } 74 75 protected final MutableBeanRepository clientBeanRepository() { 76 return this.clientBeanRepository; 77 } 78 79 protected final MutableBeanRepository serversBeanRepository() { 80 return this.serversBeanRepository; 81 } 82 83 protected final MutableBeanRepository systemBeanRepository() { 84 return this.systemBeanRepository; 85 } 86 87 protected final ApplicationsRepository applicationsRepository() { 88 return this.applicationsRepository; 89 } 90 91 protected final XmlObjectComparator xmlObjectComparator() { 92 return this.xmlObjectComparator; 93 } 94 95 protected final void runConfigurationCreator(ConfigurationCreator configurationCreator) 96 throws ConfigurationSetupException 97 { 98 configurationCreator.createConfigurationIntoRepositories(clientBeanRepository, 99 serversBeanRepository, 100 systemBeanRepository, 101 applicationsRepository); 102 } 103 104 public String [] applicationNames() { 105 Set names = new HashSet (); 106 107 names.addAll(this.dsoApplicationConfigs.keySet()); 108 names.addAll(this.springApplicationConfigs.keySet()); 109 110 return (String []) names.toArray(new String [names.size()]); 111 } 112 113 protected final ConfigContext createContext(BeanRepository beanRepository, File configFilePath) { 114 Assert.assertNotNull(beanRepository); 115 return new StandardConfigContext(beanRepository, this.defaultValueProvider, this.illegalConfigurationChangeHandler, 116 configFilePath); 117 } 118 119 public synchronized NewDSOApplicationConfig dsoApplicationConfigFor(String applicationName) { 120 Assert.eval(applicationName.equals(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME)); 122 123 NewDSOApplicationConfig out = (NewDSOApplicationConfig) this.dsoApplicationConfigs.get(applicationName); 124 if (out == null) { 125 out = createNewDSOApplicationConfig(applicationName); 126 this.dsoApplicationConfigs.put(applicationName, out); 127 } 128 129 return out; 130 } 131 132 public synchronized NewSpringApplicationConfig springApplicationConfigFor(String applicationName) { 133 Assert.eval(applicationName.equals(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME)); 135 136 NewSpringApplicationConfig out = (NewSpringApplicationConfig) this.springApplicationConfigs.get(applicationName); 137 if (out == null) { 138 out = createNewSpringApplicationConfig(applicationName); 139 this.springApplicationConfigs.put(applicationName, out); 140 } 141 142 return out; 143 } 144 145 protected NewDSOApplicationConfig createNewDSOApplicationConfig(String applicationName) { 146 return new NewDSOApplicationConfigObject(createContext(new ChildBeanRepository(this.applicationsRepository 147 .repositoryFor(applicationName), DsoApplication.class, new ChildBeanFetcher() { 148 public XmlObject getChild(XmlObject parent) { 149 return ((Application) parent).getDso(); 150 } 151 }), null)); 152 } 153 154 protected NewSpringApplicationConfig createNewSpringApplicationConfig(String applicationName) { 155 return new NewSpringApplicationConfigObject(createContext(new ChildBeanRepository(this.applicationsRepository 156 .repositoryFor(applicationName), SpringApplication.class, new ChildBeanFetcher() { 157 public XmlObject getChild(XmlObject parent) { 158 return ((Application) parent).getSpring(); 159 } 160 }), null)); 161 } 162 163 } 164 | Popular Tags |