1 4 package com.tc.config.schema.setup; 5 6 import org.apache.xmlbeans.XmlObject; 7 import org.apache.xmlbeans.XmlOptions; 8 9 import com.tc.util.Assert; 10 import com.terracottatech.config.Application; 11 import com.terracottatech.config.Client; 12 import com.terracottatech.config.Server; 13 import com.terracottatech.config.Servers; 14 import com.terracottatech.config.System; 15 16 import java.util.ArrayList ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 26 public class TestConfigBeanSet { 27 28 private final Client rootClientBean; 29 private final Servers rootServersBean; 30 private final System rootSystemBean; 31 private final Map rootApplicationBeans; 32 33 public TestConfigBeanSet() { 34 this.rootClientBean = Client.Factory.newInstance(); 35 36 this.rootServersBean = Servers.Factory.newInstance(); 37 Server initialServer = this.rootServersBean.addNewServer(); 38 initialServer.setName("localhost"); 39 40 this.rootSystemBean = System.Factory.newInstance(); 41 42 this.rootApplicationBeans = new HashMap (); 43 this.rootApplicationBeans.put(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME, createNewApplication()); 44 45 checkValidates(this.rootClientBean); 46 checkValidates(this.rootServersBean); 47 checkValidates(this.rootSystemBean); 48 49 Iterator iter = this.rootApplicationBeans.values().iterator(); 50 while (iter.hasNext()) { 51 checkValidates((XmlObject) iter.next()); 52 } 53 } 54 55 private void checkValidates(XmlObject object) { 56 List errors = new ArrayList (); 57 XmlOptions options = new XmlOptions().setErrorListener(errors); 58 59 boolean result = object.validate(options); 60 if ((!result) || (errors.size() > 0)) { 61 throw Assert 63 .failure("Object " + object + " of " + object.getClass() + " didn't validate; errors were: " + errors); 64 } 65 } 66 67 public Client clientBean() { 68 return this.rootClientBean; 69 } 70 71 public Servers serversBean() { 72 return this.rootServersBean; 73 } 74 75 public System systemBean() { 76 return this.rootSystemBean; 77 } 78 79 public String [] applicationNames() { 80 return (String []) this.rootApplicationBeans.keySet().toArray(new String [this.rootApplicationBeans.size()]); 81 } 82 83 public Application applicationBeanFor(String applicationName) { 84 Application out = (Application) this.rootApplicationBeans.get(applicationName); 85 if (out == null) { 86 out = createNewApplication(); 87 this.rootApplicationBeans.put(applicationName, out); 88 } 89 return out; 90 } 91 92 private Application createNewApplication() { 93 Application out = Application.Factory.newInstance(); 94 out.addNewDso().addNewInstrumentedClasses(); 95 return out; 96 } 97 98 } 99 | Popular Tags |