KickJava   Java API By Example, From Geeks To Geeks.

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


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 a locator for an MBeanServer. This tag can be used
23  * within a FormMBean tag instead of specifying the server attribute of the FormMBean.
24  *
25  * @author John Aronson
26  */

27 public class MBeanServerTag 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 our jmx parent tag
37
Object JavaDoc o = getParent();
38         while(o != null && !(o instanceof ILocatorTag))
39             o = ((Tag)o).getParent();
40
41         Tag parent = (Tag)o;
42
43         //read in the mbean server name
44
BufferedReader in = new BufferedReader(getBodyContent().getReader());
45         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
46                     
47         try
48         {
49             String JavaDoc line = in.readLine();
50             while(line != null)
51             {
52                 sb.append(line);
53                 line = in.readLine();
54             }
55             if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("mbean tag body content: " +sb.toString());
56             getBodyContent().clear();
57             
58             if(parent != null)
59                 ((ILocatorTag)parent).setLocator(sb.toString());
60             else
61                 writeHiddenTag(sb);
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_SERVER);
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