1 package org.apache.fulcrum.spring;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.avalon.framework.activity.Disposable;
25 import org.apache.avalon.framework.context.DefaultContext;
26 import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration;
27 import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory;
28
29
30
31
32
33
34
35
36 public class YaafiContainerBean extends AvalonContainerBean
37 {
38
39 private String containerConfigValue;
40
41
42 private String applicationHome;
43
44
45 private String tempHome;
46
47
48
49
50 public YaafiContainerBean()
51 {
52 super();
53
54 this.containerConfigValue = "./conf/containerConfiguration.xml";
55 this.applicationHome = ".";
56 this.tempHome = System.getProperty("java.io.tmpdir",".");
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 public void initialize() throws Exception
71 {
72 ServiceContainerConfiguration config = new ServiceContainerConfiguration();
73
74
75 BeanFactoryServiceManager beanFactoryServiceManager = new BeanFactoryServiceManager(this.getBeanFactory());
76
77
78 config.setLogger( this.getLogger() );
79 config.setApplicationRootDir( this.getApplicationHome() );
80 config.setTempRootDir( this.getTempHome() );
81 config.loadContainerConfiguration( this.getContainerConfigValue(), "auto" );
82 config.setParentServiceManager(beanFactoryServiceManager);
83 config.setContext(new DefaultContext(this.getDefaultContext()));
84
85 this.setServiceManager(ServiceContainerFactory.create(config));
86 }
87
88
89
90
91
92
93
94 public void dispose()
95 {
96 if( this.getServiceManager() == null)
97 {
98 return;
99 }
100
101 try
102 {
103
104 ((Disposable) this.getServiceManager()).dispose();
105 }
106 catch (Exception e)
107 {
108 String msg = "Failed to terminate " + this.getClass().getName();
109 this.getLogger().error(msg,e);
110 }
111 finally {
112 this.setServiceManager(null);
113 }
114 }
115
116
117
118
119
120
121
122
123 public String getApplicationHome()
124 {
125 return this.applicationHome;
126 }
127
128
129
130
131 public void setApplicationHome(String applicationHome)
132 {
133 this.applicationHome = applicationHome;
134 }
135
136
137
138
139 public String getContainerConfigValue()
140 {
141 return containerConfigValue;
142 }
143
144
145
146
147 public void setContainerConfigValue(String containerConfigValue)
148 {
149 this.containerConfigValue = containerConfigValue;
150 }
151
152
153
154
155 public String getTempHome()
156 {
157 return this.tempHome;
158 }
159
160
161
162
163 public void setTempHome(String tempHome)
164 {
165 this.tempHome = tempHome;
166 }
167
168
169
170
171
172
173
174
175 public String toString()
176 {
177 StringBuffer result = new StringBuffer();
178 result.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode()));
179 result.append('[');
180 result.append("beanName=").append(this.getBeanName());
181 result.append(',');
182 result.append("workingDir=").append(new File("").getAbsolutePath());
183 result.append(',');
184 result.append("applicationHome=").append(this.getApplicationHome());
185 result.append(',');
186 result.append("tempHome=").append(this.getTempHome());
187 result.append(',');
188 result.append("logger=").append(this.getLogger().getClass().getName());
189 result.append(',');
190 result.append("containerConfigValue=").append(this.getContainerConfigValue());
191 result.append(']');
192 return result.toString();
193 }
194 }