KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GetMBeanInfoTag.java
10  *
11  * Created on October 24, 2001, 9:52 AM
12  */

13
14 package org.webjmx.tags;
15
16 import java.io.*;
17 import javax.management.*;
18 import javax.servlet.jsp.*;
19 import javax.servlet.jsp.tagext.*;
20
21 /** This tag gets an MBeanInfo instance and puts it in the page context under the given ID.
22  * CALL -> server.getMBeanInfo(name)
23  *
24  * @author John Aronson
25  */

26 public class GetMBeanInfoTag extends TagSupport
27     implements JMXTaglibConstants
28 {
29     /** Holds value of property id. Page context attribute name of where the MBeanInfo will be placed. */
30     private String JavaDoc id;
31     
32     /** server is the ID of a page attribute of type MBeanServer */
33     private String JavaDoc server;
34     
35     /** name is the ID of a page attribute of type ObjectName. */
36     private String JavaDoc name;
37     
38     /** Creates new GetMBeanInfoTag */
39     public GetMBeanInfoTag()
40     { }
41
42     /** Process the start tag for this instance.
43      */

44     public int doStartTag()
45         throws JspException
46     {
47         Object JavaDoc o = pageContext.getAttribute(server);
48         if(o == null ||!(o instanceof MBeanServer))
49             throw new JspException("GetMBeanInfoTag requires type MBeanServer, Illegal server: " +o.getClass());
50         MBeanServer s = (MBeanServer)o;
51         o = pageContext.getAttribute(name);
52         if(o == null)
53         {
54             try{ o = new ObjectName(name); }
55             catch(MalformedObjectNameException mex) { throw new JspException(mex.toString()); }
56         }else if(!(o instanceof ObjectName))
57             throw new JspException("GetMBeanInfoTag requires type ObjectName, Illegal name: " +o);
58         ObjectName n = (ObjectName)o;
59         try
60         {
61             MBeanInfo mbi = s.getMBeanInfo(n);
62             if(mbi != null)
63                 pageContext.setAttribute(id, mbi);
64         }catch(Exception JavaDoc ex) { ex.printStackTrace(); }
65         return (SKIP_BODY);
66     }
67
68     /** Getter for property id.
69      * @return Value of property id.
70      */

71     public String JavaDoc getId()
72     {
73         return id;
74     }
75     
76     /** Setter for property id.
77      * @param id New value of property id.
78      */

79     public void setId(String JavaDoc id)
80     {
81         this.id = id;
82     }
83     
84     /** Getter for property server.
85      * @return Value of property server.
86      */

87     public String JavaDoc getServer()
88     {
89         return server;
90     }
91     
92     /** Setter for property server.
93      * @param server New value of property server.
94      */

95     public void setServer(String JavaDoc server)
96     {
97         this.server = server;
98     }
99     
100     /** Getter for property name.
101      * @return Value of property name.
102      */

103     public String JavaDoc getName()
104     {
105         return name;
106     }
107     
108     /** Setter for property name.
109      * @param name New value of property name.
110      */

111     public void setName(String JavaDoc name)
112     {
113         this.name = name;
114     }
115     
116     /** Called on a Tag handler to release state
117      *
118      */

119     public void release()
120     {
121         name = id = server = null;
122     }
123 }
124
Popular Tags