KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > Domain


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;
14
15
16
17 import java.beans.beancontext.BeanContextServiceAvailableEvent JavaDoc;
18
19 import java.beans.beancontext.BeanContextServiceRevokedEvent JavaDoc;
20
21 import java.beans.beancontext.BeanContextServices JavaDoc;
22
23
24
25 import javax.management.ObjectInstance JavaDoc;
26
27
28
29 import org.apache.log4j.Logger;
30
31 import org.ejtools.jmx.browser.model.service.CacheService;
32
33
34
35
36
37 /**
38
39  * Description of the Class
40
41  *
42
43  * @author letiemble
44
45  * @created 13 décembre 2001
46
47  * @version $Revision: 1.6 $
48
49  * @todo Javadoc to complete
50
51  * @javabean:class displayName="JMX Domain"
52
53  * shortDescription="JMX Domain"
54
55  * @javabean:icons color16="/toolbarButtonGraphics/development/J2EEDomain16.gif"
56
57  * @javabean:property name="name"
58
59  * class="java.lang.String"
60
61  * displayName="Name"
62
63  * shortDescription="Domain name"
64
65  * @javabean:property name="size"
66
67  * class="int"
68
69  * displayName="Size"
70
71  * shortDescription="Number of MBean"
72
73  */

74
75 public class Domain extends Node
76
77 {
78
79    /** Description of the Field */
80
81    private static Logger logger = Logger.getLogger(Domain.class);
82
83
84
85
86
87    /** Constructor */
88
89    public Domain()
90
91    {
92
93       super();
94
95    }
96
97
98
99
100
101    /**
102
103     * Gets the size attribute of the Domain object
104
105     *
106
107     * @return The size value
108
109     */

110
111    public int getSize()
112
113    {
114
115       return this.size();
116
117    }
118
119
120
121
122
123    /**
124
125     * Description of the Method
126
127     *
128
129     * @param bcsae Description of the Parameter
130
131     */

132
133    public void serviceAvailable(BeanContextServiceAvailableEvent JavaDoc bcsae)
134
135    {
136
137       if (CacheService.class.equals(bcsae.getServiceClass()))
138
139       {
140
141          BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
142
143          if (context != null)
144
145          {
146
147             this.useServices(context);
148
149          }
150
151       }
152
153       super.serviceAvailable(bcsae);
154
155    }
156
157
158
159
160
161
162
163    /**
164
165     * Description of the Method
166
167     *
168
169     * @param bcsre Description of the Parameter
170
171     */

172
173    public void serviceRevoked(BeanContextServiceRevokedEvent JavaDoc bcsre)
174
175    {
176
177       if (CacheService.class.equals(bcsre.getServiceClass()))
178
179       {
180
181          BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
182
183          if (context != null)
184
185          {
186
187             this.releaseServices(context);
188
189          }
190
191       }
192
193       super.serviceRevoked(bcsre);
194
195    }
196
197
198
199
200
201    /**
202
203     * Setter for the reference attribute
204
205     *
206
207     * @param resource The new reference value
208
209     */

210
211    public void setReference(ObjectInstance JavaDoc resource)
212
213    {
214
215       this.name = resource.getObjectName().getDomain();
216
217    }
218
219
220
221
222
223    /** Description of the Method */
224
225    protected void initializeBeanContextResources()
226
227    {
228
229       super.initializeBeanContextResources();
230
231       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
232
233       this.useServices(context);
234
235    }
236
237
238
239
240
241    /** Description of the Method */
242
243    protected void releaseBeanContextResources()
244
245    {
246
247       BeanContextServices JavaDoc context = (BeanContextServices JavaDoc) getBeanContext();
248
249       this.releaseServices(context);
250
251       super.releaseBeanContextResources();
252
253    }
254
255
256
257
258
259    /**
260
261     * Description of the Method
262
263     *
264
265     * @param context Description of the Parameter
266
267     */

268
269    protected void releaseServices(BeanContextServices JavaDoc context)
270
271    {
272
273       logger.debug("In releaseServices...");
274
275       if (context.hasService(CacheService.class))
276
277       {
278
279 // logger.debug("Using service CacheService...");
280

281          try
282
283          {
284
285             CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this);
286
287             service.remove(CacheService.DOMAIN_TYPE, this.name);
288
289             context.releaseService(this, this, CacheService.class);
290
291          }
292
293          catch (Exception JavaDoc e)
294
295          {
296
297             logger.error("Error during utilisation of service CacheService for " + this.name, e);
298
299          }
300
301       }
302
303    }
304
305
306
307
308
309    /**
310
311     * Description of the Method
312
313     *
314
315     * @param context Description of the Parameter
316
317     */

318
319    protected void useServices(BeanContextServices JavaDoc context)
320
321    {
322
323       if (context.hasService(CacheService.class))
324
325       {
326
327 // logger.debug("Using service CacheService...");
328

329          try
330
331          {
332
333             CacheService service = (CacheService) context.getService(this, this, CacheService.class, this, this);
334
335             service.add(CacheService.DOMAIN_TYPE, this.name, this);
336
337             context.releaseService(this, this, CacheService.class);
338
339          }
340
341          catch (Exception JavaDoc e)
342
343          {
344
345             logger.error("Error during utilisation of service CacheService for " + this.name, e);
346
347          }
348
349       }
350
351    }
352
353 }
354
355
Popular Tags