KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > service > CustomizationServiceProvider


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.model.service;
14
15
16
17 import java.beans.beancontext.BeanContextServices JavaDoc;
18
19 import java.util.Arrays JavaDoc;
20
21 import java.util.Collection JavaDoc;
22
23 import java.util.Iterator JavaDoc;
24
25 import java.util.Vector JavaDoc;
26
27
28
29 import org.apache.log4j.Logger;
30
31 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
32
33 import org.ejtools.jmx.browser.mbean.CustomViewDeployer;
34
35 import org.ejtools.jmx.browser.mbean.View;
36
37 import org.ejtools.jmx.browser.model.Resource;
38
39
40
41 /**
42
43  * Description of the Class
44
45  *
46
47  * @author letiemble
48
49  * @created 13 d?cembre 2001
50
51  * @version $Revision: 1.6 $
52
53  * @todo Javadoc to complete
54
55  * @todo Service release to complete
56
57  */

58
59 public class CustomizationServiceProvider extends CustomBeanContextServiceProvider implements CustomizationService
60
61 {
62
63    /** Description of the Field */
64
65    protected CustomizationService service = null;
66
67    /** Description of the Field */
68
69    private static Logger logger = Logger.getLogger(CustomizationServiceProvider.class);
70
71
72
73
74
75    /** Constructor for the CustomizationServiceProvider object */
76
77    public CustomizationServiceProvider()
78
79    {
80
81       this.service = this;
82
83    }
84
85
86
87
88
89    /**
90
91     * Getter for the currentServiceSelectors attribute
92
93     *
94
95     * @param bcs Description of the Parameter
96
97     * @param serviceClass Description of the Parameter
98
99     * @return The value
100
101     */

102
103    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, java.lang.Class JavaDoc serviceClass)
104
105    {
106
107       return (new Vector JavaDoc()).iterator();
108
109    }
110
111
112
113
114
115    /**
116
117     * Getter for the service attribute
118
119     *
120
121     * @param bcs Description of the Parameter
122
123     * @param requestor Description of the Parameter
124
125     * @param serviceClass Description of the Parameter
126
127     * @param serviceSelector Description of the Parameter
128
129     * @return The value
130
131     */

132
133    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Class JavaDoc serviceClass, java.lang.Object JavaDoc serviceSelector)
134
135    {
136
137       return service;
138
139    }
140
141
142
143
144
145    /**
146
147     * Gets the view attribute of the CustomizationServiceProvider object
148
149     *
150
151     * @param index Description of the Parameter
152
153     * @return The view value
154
155     */

156
157    public View getView(int index)
158
159    {
160
161       logger.debug("Getting view by index=" + index);
162
163
164
165       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
166
167
168
169       View result = null;
170
171
172
173       if (context.hasService(ConnectionService.class) && context.hasService(CacheService.class))
174
175       {
176
177          logger.debug("Using service ConnectionService and CacheService...");
178
179          try
180
181          {
182
183             ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
184
185             CacheService cache = (CacheService) context.getService(this, this, CacheService.class, this, this);
186
187
188
189             Resource resource = (Resource) cache.get(CacheService.RESOURCE_TYPE, CustomViewDeployer.OBJECT_NAME);
190
191             if (resource != null)
192
193             {
194
195                result = (View) resource.invoke("getView", new Object JavaDoc[]{new Integer JavaDoc(index)}, new String JavaDoc[]{"int"});
196
197             }
198
199
200
201             context.releaseService(this, this, CacheService.class);
202
203             context.releaseService(this, this, ConnectionService.class);
204
205          }
206
207          catch (Exception JavaDoc e)
208
209          {
210
211             e.printStackTrace();
212
213             logger.error("Error during utilisation of service ConnectionService or CacheService (" + e.getMessage() + ")");
214
215          }
216
217       }
218
219
220
221       return result;
222
223    }
224
225
226
227
228
229    /**
230
231     * Gets the views attribute of the CustomizationServiceProvider object
232
233     *
234
235     * @return The views value
236
237     */

238
239    public Collection JavaDoc getViews()
240
241    {
242
243       logger.debug("Getting views");
244
245
246
247       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
248
249
250
251       Collection JavaDoc result = new Vector JavaDoc();
252
253
254
255       if (context.hasService(ConnectionService.class) && context.hasService(CacheService.class))
256
257       {
258
259          logger.debug("Using service ConnectionService and CacheService...");
260
261          try
262
263          {
264
265             ConnectionService service = (ConnectionService) context.getService(this, this, ConnectionService.class, this, this);
266
267             CacheService cache = (CacheService) context.getService(this, this, CacheService.class, this, this);
268
269
270
271             Resource resource = (Resource) cache.get(CacheService.RESOURCE_TYPE, CustomViewDeployer.OBJECT_NAME);
272
273             if (resource != null)
274
275             {
276
277                View[] views = (View[]) resource.getAttribute("Views");
278
279                if (views != null)
280
281                {
282
283                   result.addAll(Arrays.asList(views));
284
285                }
286
287             }
288
289
290
291             context.releaseService(this, this, CacheService.class);
292
293             context.releaseService(this, this, ConnectionService.class);
294
295          }
296
297          catch (Exception JavaDoc e)
298
299          {
300
301             e.printStackTrace();
302
303             logger.error("Error during utilisation of service ConnectionService or CacheService (" + e.getMessage() + ")");
304
305          }
306
307       }
308
309
310
311       return result;
312
313    }
314
315
316
317
318
319    /**
320
321     * Description of the Method
322
323     *
324
325     * @param bcs Description of the Parameter
326
327     * @param requestor Description of the Parameter
328
329     * @param service Description of the Parameter
330
331     */

332
333    public void releaseService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Object JavaDoc service) { }
334
335
336
337
338
339    /**
340
341     * @return The serviceClass value
342
343     */

344
345    protected Class JavaDoc[] getServiceClass()
346
347    {
348
349       return new Class JavaDoc[]{CustomizationService.class};
350
351    }
352
353 }
354
355
Popular Tags