KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webjmx > tags > MBeanTag


1 /*
2  * Copyright (C) WebJMX.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the WebJMX License version 2.0.
6  * See the terms of the WebJMX License in the documentation provided with this software.
7  */

8 /*
9  * MBeanTag.java
10  *
11  * Created on December 12, 2001, 3:19 PM
12  */

13
14 package org.webjmx.tags;
15
16 import java.io.*;
17 import java.util.*;
18 import javax.servlet.jsp.*;
19 import javax.servlet.jsp.tagext.*;
20
21 /** This tag writes a hidden HTML form input tag to the output stream. The content
22  of the tag should contain an ObjectName within an MBeanServer. This tag can be
23  used within a FormMBean tag instead of specifying the mbean attribute of the FormMBean.
24  *
25  * @author John Aronson
26  */

27 public class MBeanTag extends BodyTagSupport
28     implements JMXTaglibConstants
29 {
30     /** Process the end tag for this instance.
31      * @throws JspException
32      */

33     public int doEndTag()
34         throws JspException
35     {
36         //establish the parent jmx tag
37
Object JavaDoc o = getParent();
38         while(o != null && !(o instanceof FormMBeanTag))
39             o = ((Tag)o).getParent();
40         Tag parent = (Tag)o;
41
42         //read in the mbean name
43
BufferedReader in = new BufferedReader(getBodyContent().getReader());
44         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
45                     
46         try
47         {
48             String JavaDoc line = in.readLine();
49             while(line != null)
50             {
51                 sb.append(line);
52                 line = in.readLine();
53             }
54             if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("mbean tag body content: " +sb.toString());
55             getBodyContent().clear();
56
57             if(parent != null)
58                 ((FormMBeanTag)parent).setMbean(sb.toString());
59             else
60                 writeHiddenTag(sb);
61
62         }catch(IOException ex) { ex.printStackTrace(); }
63         
64     return (EVAL_BODY_INCLUDE);
65     }
66     
67     void writeHiddenTag(StringBuffer JavaDoc sb)
68         throws IOException
69     {
70         //convert to a form element
71
sb.insert(0, "\" VALUE=\"");
72         sb.insert(0, TAGLIB_NAME);
73         sb.insert(0, "<INPUT TYPE=HIDDEN NAME=\"");
74         sb.append("\">\n");
75
76         //write out the form element
77
pageContext.getOut().write(sb.toString());
78     }
79 }
80
Popular Tags