KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GetAttributeTag.java
10  *
11  * Created on December 5, 2001, 3:34 PM
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 /**
22  *
23  * @author john
24  * @version
25  */

26 public class GetAttributeTag extends TagSupport
27     implements JMXTaglibConstants
28 {
29     /** Holds value of property id. */
30     private String JavaDoc id;
31     
32     /** Holds value of property server. */
33     private String JavaDoc server;
34     
35     /** Holds value of property name. */
36     private String JavaDoc name;
37     
38     /** Holds value of property attribute. */
39     private String JavaDoc attribute;
40     
41     /** Holds value of property attributeInfo. */
42     private String JavaDoc attributeInfo;
43     
44     /** Creates new GetAttributeTag */
45     public GetAttributeTag() {
46     }
47
48     public int doStartTag()
49         throws JspException
50     {
51         Object JavaDoc o = pageContext.getAttribute(server);
52         if(o == null ||!(o instanceof MBeanServer))
53             throw new JspException("GetAttributeTag requires type MBeanServer, Illegal server: " +o);
54         MBeanServer s = (MBeanServer)o;
55         o = pageContext.getAttribute(name);
56         if(o == null ||!(o instanceof ObjectName))
57             throw new JspException("GetAttributeTag requires type ObjectName, Illegal name: " +o);
58         ObjectName n = (ObjectName)o;
59         if(attributeInfo != null)
60         {
61             o = pageContext.getAttribute(attributeInfo);
62             if(o == null ||!(o instanceof MBeanAttributeInfo))
63                 throw new JspException("GetAttributeTag requires type MBeanAttributeInfo, Illegal attributeInfo: " +o);
64             MBeanAttributeInfo attrInfo = (MBeanAttributeInfo)o;
65             attribute = attrInfo.getName();
66         }
67         
68         if(attribute == null)
69             throw new JspException("GetAttributeTag requires a value");
70
71         try
72         {
73             o = s.getAttribute(n, attribute);
74             
75             if(id == null)
76                 pageContext.getOut().write(o != null ? o.toString() : "null");
77             else if(o != null)
78                 pageContext.setAttribute(id, o);
79
80             //should write out a list if o is a Collection
81
}catch(Exception JavaDoc ex) { ex.printStackTrace(); }
82         return (SKIP_BODY);
83     }
84
85     /** Getter for property id.
86      * @return Value of property id.
87      */

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

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

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

112     public void setServer(String JavaDoc server)
113     {
114         this.server = server;
115     }
116     
117     /** Getter for property name.
118      * @return Value of property name.
119      */

120     public String JavaDoc getName()
121     {
122         return name;
123     }
124     
125     /** Setter for property name.
126      * @param name New value of property name.
127      */

128     public void setName(String JavaDoc name)
129     {
130         this.name = name;
131     }
132     
133     /** Getter for property attribute.
134      * @return Value of property attribute.
135      */

136     public String JavaDoc getAttribute()
137     {
138         return attribute;
139     }
140     
141     /** Setter for property attribute.
142      * @param attribute New value of property attribute.
143      */

144     public void setAttribute(String JavaDoc attribute)
145     {
146         this.attribute = attribute;
147     }
148     
149     /** Getter for property attributeInfo.
150      * @return Value of property attributeInfo.
151      */

152     public String JavaDoc getAttributeInfo()
153     {
154         return attributeInfo;
155     }
156     
157     /** Setter for property attributeInfo.
158      * @param attributeInfo New value of property attributeInfo.
159      */

160     public void setAttributeInfo(String JavaDoc attributeInfo)
161     {
162         this.attributeInfo = attributeInfo;
163     }
164     
165 }
166
Popular Tags