01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.test;
05:
06: import com.tc.config.schema.builder.SpringApplicationContextConfigBuilder;
07: import com.tc.config.schema.builder.SpringBeanConfigBuilder;
08:
09: public class SpringApplicationContextConfigBuilderImpl extends
10: BaseConfigBuilder implements
11: SpringApplicationContextConfigBuilder {
12:
13: protected SpringApplicationContextConfigBuilderImpl() {
14: super (5, new String[] { "paths", "beans" });
15: }
16:
17: public static SpringApplicationContextConfigBuilder newMinimalInstance() {
18: return new SpringApplicationContextConfigBuilderImpl();
19: }
20:
21: public String toString() {
22: return elementGroup("application-context", new String[] {
23: "paths", "beans" });
24: }
25:
26: public void setPaths(String[] paths) {
27: SpringApplicationContextPathConfigBuilder[] pcb = new SpringApplicationContextPathConfigBuilder[paths.length];
28: for (int i = 0; i < paths.length; i++) {
29: String path = paths[i];
30: pcb[i] = new SpringApplicationContextPathConfigBuilderImpl(
31: path);
32: }
33: setPaths(pcb);
34: }
35:
36: public void setPaths(
37: SpringApplicationContextPathConfigBuilder[] paths) {
38: setProperty("paths", selfTaggingArray(paths));
39: }
40:
41: public SpringBeanConfigBuilder addBean(String beanName) {
42: if (!isSet("beans")) {
43: setProperty("beans",
44: selfTaggingArray(new SpringBeanConfigBuilder[0]));
45: }
46: SpringBeanConfigBuilder springBean = new SpringBeanConfigBuilderImpl(
47: beanName);
48: SpringBeanConfigBuilder[] existingBeans = (SpringBeanConfigBuilder[]) ((SelfTaggingArray) getRawProperty("beans"))
49: .values();
50: SpringBeanConfigBuilder[] newBeans = new SpringBeanConfigBuilder[existingBeans.length + 1];
51: System.arraycopy(existingBeans, 0, newBeans, 0,
52: existingBeans.length);
53: newBeans[existingBeans.length] = springBean;
54: setProperty("beans", selfTaggingArray(newBeans));
55: return springBean;
56: }
57:
58: // beans
59:
60: }
|