Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ServiceManagerServiceImpl |
|
| 1.0;1 |
1 | package org.apache.fulcrum.servicemanager; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.avalon.framework.activity.Disposable; | |
23 | import org.apache.avalon.framework.context.Context; | |
24 | import org.apache.avalon.framework.context.ContextException; | |
25 | import org.apache.avalon.framework.context.Contextualizable; | |
26 | import org.apache.avalon.framework.logger.Logger; | |
27 | import org.apache.avalon.framework.logger.LogEnabled; | |
28 | import org.apache.avalon.framework.parameters.ParameterException; | |
29 | import org.apache.avalon.framework.parameters.Parameterizable; | |
30 | import org.apache.avalon.framework.parameters.Parameters; | |
31 | import org.apache.avalon.framework.service.ServiceException; | |
32 | import org.apache.avalon.framework.service.ServiceManager; | |
33 | import org.apache.avalon.framework.service.Serviceable; | |
34 | import org.apache.avalon.framework.configuration.Configuration; | |
35 | import org.apache.avalon.framework.configuration.ConfigurationException; | |
36 | import org.apache.avalon.framework.configuration.Reconfigurable; | |
37 | ||
38 | /** | |
39 | * This is a sort of "edelhack" to solve the problem of accessing | |
40 | * the Avalon infrastructure without having an instance of the | |
41 | * container. The implementation stores the very first instance | |
42 | * of itself in a static variable which can be accessed using | |
43 | * getInstance(). | |
44 | * | |
45 | * This allows access to the various Avalon artifacts. | |
46 | * | |
47 | * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> | |
48 | */ | |
49 | ||
50 | public class ServiceManagerServiceImpl | |
51 | implements ServiceManagerService, LogEnabled, Contextualizable, Reconfigurable, Parameterizable, Serviceable, Disposable | |
52 | { | |
53 | /** The one and only instance */ | |
54 | private static ServiceManagerServiceImpl instance; | |
55 | ||
56 | /** Store the Avalon logger */ | |
57 | private Logger logger; | |
58 | ||
59 | /** Store the ServiceContainer on a per instance base */ | |
60 | private ServiceManager serviceManager; | |
61 | ||
62 | /** Store the passed parameters on a per instance base */ | |
63 | private Parameters parameters; | |
64 | ||
65 | /** Store the passed context on a per instance base */ | |
66 | private Context context; | |
67 | ||
68 | /** Store the passed configuration on a per instance base */ | |
69 | private Configuration configuration; | |
70 | ||
71 | /** | |
72 | * Constructor | |
73 | */ | |
74 | public ServiceManagerServiceImpl() | |
75 | 1 | { |
76 | 1 | setInstance(this); |
77 | 1 | } |
78 | ||
79 | ///////////////////////////////////////////////////////////////////////// | |
80 | // Avalon Lifecycle Implementation | |
81 | ///////////////////////////////////////////////////////////////////////// | |
82 | ||
83 | /** | |
84 | * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger) | |
85 | */ | |
86 | public void enableLogging(Logger logger) | |
87 | { | |
88 | 1 | this.logger = logger; |
89 | 1 | } |
90 | ||
91 | /** | |
92 | * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) | |
93 | */ | |
94 | public void service(ServiceManager serviceManager) throws ServiceException | |
95 | { | |
96 | 1 | this.serviceManager = serviceManager; |
97 | 1 | } |
98 | ||
99 | /** | |
100 | * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) | |
101 | */ | |
102 | public void contextualize(Context context) throws ContextException | |
103 | { | |
104 | 1 | this.context = context; |
105 | 1 | } |
106 | ||
107 | /** | |
108 | * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) | |
109 | */ | |
110 | public void configure(Configuration configuration) throws ConfigurationException | |
111 | { | |
112 | 1 | this.configuration = configuration; |
113 | 1 | } |
114 | ||
115 | /** | |
116 | * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) | |
117 | */ | |
118 | public void reconfigure(Configuration configuration) throws ConfigurationException | |
119 | { | |
120 | 0 | this.configuration = configuration; |
121 | 0 | } |
122 | ||
123 | /** | |
124 | * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters) | |
125 | */ | |
126 | public void parameterize(Parameters parameters) throws ParameterException | |
127 | { | |
128 | 1 | this.parameters = parameters; |
129 | 1 | } |
130 | ||
131 | /** | |
132 | * @see org.apache.avalon.framework.activity.Disposable#dispose() | |
133 | */ | |
134 | public void dispose() | |
135 | { | |
136 | 1 | this.serviceManager = null; |
137 | 1 | this.parameters = null; |
138 | 1 | this.context = null; |
139 | 1 | this.configuration = null; |
140 | 1 | this.logger = null; |
141 | 1 | ServiceManagerServiceImpl.instance = null; |
142 | 1 | } |
143 | ||
144 | ///////////////////////////////////////////////////////////////////////// | |
145 | // Service Interface Implementation | |
146 | ///////////////////////////////////////////////////////////////////////// | |
147 | ||
148 | /** | |
149 | * @see org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String) | |
150 | */ | |
151 | public boolean hasService(String name) | |
152 | { | |
153 | 1 | return this.serviceManager.hasService(name); |
154 | } | |
155 | ||
156 | /** | |
157 | * @see org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String) | |
158 | */ | |
159 | public Object lookup(String name) throws ServiceException | |
160 | { | |
161 | 1 | return this.serviceManager.lookup(name); |
162 | } | |
163 | ||
164 | /** | |
165 | * @see org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object) | |
166 | */ | |
167 | public void release(Object object) | |
168 | { | |
169 | 1 | this.serviceManager.release(object); |
170 | 1 | } |
171 | ||
172 | /** | |
173 | * @return the ServiceManager for the container | |
174 | */ | |
175 | public ServiceManager getServiceManager() | |
176 | { | |
177 | 1 | return this.serviceManager; |
178 | } | |
179 | ||
180 | /** | |
181 | * @return the Parameters for the container | |
182 | */ | |
183 | public Parameters getParameters() | |
184 | { | |
185 | 1 | return this.parameters; |
186 | } | |
187 | ||
188 | /** | |
189 | * @return the Context for the container | |
190 | */ | |
191 | public Context getContext() | |
192 | { | |
193 | 1 | return this.context; |
194 | } | |
195 | ||
196 | /** | |
197 | * @see org.apache.fulcrum.servicemanager.ServiceManagerService#getLogger() | |
198 | */ | |
199 | public Logger getLogger() | |
200 | { | |
201 | 2 | return this.logger; |
202 | } | |
203 | ||
204 | /** | |
205 | * @see org.apache.fulcrum.servicemanager.ServiceManagerService#getConfiguration() | |
206 | */ | |
207 | public Configuration getConfiguration() | |
208 | { | |
209 | 1 | return this.configuration; |
210 | } | |
211 | ||
212 | ///////////////////////////////////////////////////////////////////////// | |
213 | // Service Implementation | |
214 | ///////////////////////////////////////////////////////////////////////// | |
215 | ||
216 | /** | |
217 | * @return the one and only instance of this class | |
218 | */ | |
219 | public static synchronized ServiceManagerService getInstance() | |
220 | { | |
221 | 0 | return instance; |
222 | } | |
223 | ||
224 | /** | |
225 | * Create the one and only instance | |
226 | * @param instance the instance | |
227 | */ | |
228 | protected static synchronized void setInstance( ServiceManagerServiceImpl instance ) | |
229 | { | |
230 | 1 | ServiceManagerServiceImpl.instance = instance; |
231 | 1 | } |
232 | } |