KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > web > taglib > MBeanParameterEditorTag


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.web.taglib;
14
15
16
17 import java.beans.PropertyEditor JavaDoc;
18
19
20
21 import javax.management.MBeanParameterInfo JavaDoc;
22
23 import javax.servlet.jsp.JspException JavaDoc;
24
25 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
26
27
28
29 import org.apache.log4j.Logger;
30
31 import org.apache.struts.util.MessageResources;
32
33 import org.apache.struts.util.RequestUtils;
34
35 import org.apache.struts.util.ResponseUtils;
36
37 import org.ejtools.beans.CustomPropertyEditorManager;
38
39 import org.ejtools.util.ClassTools;
40
41
42
43 /**
44
45  * Description of the Class
46
47  *
48
49  * @author letiemble
50
51  * @created 25 avril 2002
52
53  * @version $Revision: 1.6 $
54
55  * @todo Javadoc to complete
56
57  * @jsp:tag name="mbeanParameterEditor" body-content="empty"
58
59  */

60
61 public class MBeanParameterEditorTag extends TagSupport JavaDoc
62
63 {
64
65    /** Filter the rendered output for characters that are sensitive in HTML? */
66
67    protected boolean filter = true;
68
69    /** Description of the Field */
70
71    protected String JavaDoc id = null;
72
73    /** Should we ignore missing beans and simply output nothing? */
74
75    protected boolean ignore = false;
76
77    /** Name of the bean that contains the data we will be rendering. */
78
79    protected String JavaDoc name = null;
80
81    /** The scope to be searched to retrieve the specified bean. */
82
83    protected String JavaDoc scope = null;
84
85    /** Description of the Field */
86
87    private static Logger logger = Logger.getLogger(MBeanAttributeEditorTag.class);
88
89    /** Description of the Field */
90
91    private static MessageResources messages = MessageResources.getMessageResources("org.ejtools.jmx.browser.web.taglib.MBeanAttributeInfoEditor");
92
93
94
95
96
97    /**
98
99     * Description of the Method
100
101     *
102
103     * @return Description of the Returned Value
104
105     * @exception JspException Description of the Exception
106
107     */

108
109    public int doStartTag()
110
111       throws JspException JavaDoc
112
113    {
114
115       // Look up the requested bean (if necessary)
116

117       MBeanParameterInfo JavaDoc info = (MBeanParameterInfo JavaDoc) RequestUtils.lookup(pageContext, name, scope);
118
119
120
121       if (ignore)
122
123       {
124
125          if (info == null)
126
127          {
128
129             return (SKIP_BODY);
130
131          }
132
133          // Nothing to output
134

135       }
136
137
138
139       PropertyEditor JavaDoc propertyeditor = null;
140
141       Class JavaDoc c = ClassTools.getClass(info.getType());
142
143
144
145       logger.debug("Parameter class " + c);
146
147
148
149       if (c == null)
150
151       {
152
153          this.addUnsupportedParameter();
154
155       }
156
157       else
158
159       {
160
161          if (c.isArray())
162
163          {
164
165             this.addUnsupportedArrayParameter();
166
167          }
168
169          else
170
171          {
172
173             propertyeditor = CustomPropertyEditorManager.findEditor(c);
174
175
176
177             logger.debug("Property Editor " + propertyeditor);
178
179
180
181             if (propertyeditor == null)
182
183             {
184
185                this.addUnsupportedParameter();
186
187             }
188
189             else
190
191             {
192
193                this.addParameter(propertyeditor, info);
194
195             }
196
197          }
198
199       }
200
201
202
203       // Continue processing this page
204

205       return (SKIP_BODY);
206
207    }
208
209
210
211
212
213    /**
214
215     * Getter for the filter attribute
216
217     *
218
219     * @return The value of filter attribute
220
221     * @jsp:attribute name="filter" required="false" rtexprvalue="true"
222
223     */

224
225    public boolean getFilter()
226
227    {
228
229       return (this.filter);
230
231    }
232
233
234
235
236
237    /**
238
239     * @return The id value
240
241     * @jsp:attribute name="id" required="true" rtexprvalue="true"
242
243     */

244
245    public String JavaDoc getId()
246
247    {
248
249       return (this.id);
250
251    }
252
253
254
255
256
257    /**
258
259     * Getter for the ignore attribute
260
261     *
262
263     * @return The value of ignore attribute
264
265     * @jsp:attribute name="ignore" required="false" rtexprvalue="true"
266
267     */

268
269    public boolean getIgnore()
270
271    {
272
273       return (this.ignore);
274
275    }
276
277
278
279
280
281    /**
282
283     * Getter for the name attribute
284
285     *
286
287     * @return The value of name attribute
288
289     * @jsp:attribute name="name" required="true" rtexprvalue="true"
290
291     */

292
293    public String JavaDoc getName()
294
295    {
296
297       return (this.name);
298
299    }
300
301
302
303
304
305    /**
306
307     * Getter for the scope attribute
308
309     *
310
311     * @return The value of scope attribute
312
313     * @jsp:attribute name="scope" required="false" rtexprvalue="true"
314
315     */

316
317    public String JavaDoc getScope()
318
319    {
320
321       return (this.scope);
322
323    }
324
325
326
327
328
329    /** Release all allocated resources. */
330
331    public void release()
332
333    {
334
335       super.release();
336
337       filter = true;
338
339       ignore = false;
340
341       name = null;
342
343       scope = null;
344
345       id = null;
346
347    }
348
349
350
351
352
353    /**
354
355     * Setter for the filter attribute
356
357     *
358
359     * @param filter The new filter value
360
361     */

362
363    public void setFilter(boolean filter)
364
365    {
366
367       this.filter = filter;
368
369    }
370
371
372
373
374
375    /**
376
377     * Sets the id attribute of the MBeanParameterEditorTag object
378
379     *
380
381     * @param id The new id value
382
383     */

384
385    public void setId(String JavaDoc id)
386
387    {
388
389       this.id = id;
390
391    }
392
393
394
395
396
397    /**
398
399     * Setter for the ignore attribute
400
401     *
402
403     * @param ignore The new ignore value
404
405     */

406
407    public void setIgnore(boolean ignore)
408
409    {
410
411       this.ignore = ignore;
412
413    }
414
415
416
417
418
419    /**
420
421     * Setter for the name attribute
422
423     *
424
425     * @param name The new name value
426
427     */

428
429    public void setName(String JavaDoc name)
430
431    {
432
433       this.name = name;
434
435    }
436
437
438
439
440
441    /**
442
443     * Setter for the scope attribute
444
445     *
446
447     * @param scope The new scope value
448
449     */

450
451    public void setScope(String JavaDoc scope)
452
453    {
454
455       this.scope = scope;
456
457    }
458
459
460
461
462
463    /**
464
465     * Adds a feature to the UnsupportedProperty attribute of the MBeanAttributeEditorTag object
466
467     *
468
469     * @param propertyeditor The feature to be added to the Parameter attribute
470
471     * @param info The feature to be added to the Parameter attribute
472
473     * @exception JspException Description of the Exception
474
475     */

476
477    protected void addParameter(PropertyEditor JavaDoc propertyeditor, MBeanParameterInfo JavaDoc info)
478
479       throws JspException JavaDoc
480
481    {
482
483       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
484
485       int id = -1;
486
487
488
489       logger.debug("addParameter " + propertyeditor + " " + info.getName());
490
491
492
493       try
494
495       {
496
497          Integer JavaDoc value = (Integer JavaDoc) pageContext.getAttribute(getId());
498
499          id = value.intValue();
500
501       }
502
503       catch (Exception JavaDoc e)
504
505       {
506
507          logger.error("Exception during numbering reading " + e.getMessage());
508
509          throw new JspException JavaDoc(e.getMessage());
510
511       }
512
513
514
515       buffer.append("<input type=\"hidden\" name=\":parameter:");
516
517       buffer.append(id);
518
519       buffer.append("\" value=\"");
520
521       buffer.append(info.getType());
522
523       buffer.append("\"/>");
524
525
526
527       buffer.append("<input type=\"hidden\" name=\":editor:");
528
529       buffer.append(id);
530
531       buffer.append("\" value=\"");
532
533       buffer.append(propertyeditor.getClass().getName());
534
535       buffer.append("\"/>");
536
537
538
539       // Boolean types
540

541       if (("java.lang.Boolean".equals(info.getType())) || ("boolean".equals(info.getType())))
542
543       {
544
545          buffer.append("<select name=\":value:");
546
547          buffer.append(id);
548
549          buffer.append("\">");
550
551
552
553          buffer.append("<option value=\"true\">");
554
555          buffer.append(messages.getMessage("boolean.true"));
556
557          buffer.append("</option>");
558
559
560
561          buffer.append("<option value=\"false\">");
562
563          buffer.append(messages.getMessage("boolean.false"));
564
565          buffer.append("</option>");
566
567
568
569          buffer.append("</select>");
570
571       }
572
573       // Others types
574

575       else
576
577       {
578
579          buffer.append("<input type=\"text\" name=\":value:");
580
581          buffer.append(id);
582
583          buffer.append("\"/>");
584
585       }
586
587
588
589       ResponseUtils.write(pageContext, buffer.toString());
590
591    }
592
593
594
595
596
597    /**
598
599     * Adds a feature to the UnsupportedProperty attribute of the MBeanAttributeEditorTag object
600
601     *
602
603     * @exception JspException Description of the Exception
604
605     * @todo I18N
606
607     */

608
609    protected void addUnsupportedArrayParameter()
610
611       throws JspException JavaDoc
612
613    {
614
615       String JavaDoc output = "Unsupported Array Paramater";
616
617
618
619       if (filter)
620
621       {
622
623          output = "<i>" + ResponseUtils.filter(output) + "</i>";
624
625       }
626
627       else
628
629       {
630
631          output = "<i>" + output + "</i>";
632
633       }
634
635
636
637       ResponseUtils.write(pageContext, output);
638
639    }
640
641
642
643
644
645    /**
646
647     * Adds a feature to the UnsupportedProperty attribute of the MBeanAttributeEditorTag object
648
649     *
650
651     * @exception JspException Description of the Exception
652
653     * @todo I18N
654
655     */

656
657    protected void addUnsupportedParameter()
658
659       throws JspException JavaDoc
660
661    {
662
663       String JavaDoc output = "Unsupported Parameter";
664
665
666
667       if (filter)
668
669       {
670
671          output = "<i>" + ResponseUtils.filter(output) + "</i>";
672
673       }
674
675       else
676
677       {
678
679          output = "<i>" + output + "</i>";
680
681       }
682
683
684
685       ResponseUtils.write(pageContext, output);
686
687    }
688
689 }
690
691
Popular Tags