KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GetFeatureByNameTag.java
10  *
11  * Created on July 11, 2002, 3:33 PM
12  */

13
14 package org.webjmx.tags;
15
16 import java.lang.reflect.*;
17 import java.util.*;
18 import javax.management.*;
19 import javax.servlet.jsp.*;
20 import javax.servlet.jsp.tagext.*;
21
22 /** Searches an array of MBeanFeatureInfo objects for a specified name
23  *
24  * @author John Aronson
25  */

26 public class GetFeatureByNameTag extends TagSupport
27     implements JMXTaglibConstants
28 {
29     
30     /** Holds value of property id. */
31     private String JavaDoc id;
32     
33     /** Holds value of property name. */
34     private String JavaDoc name;
35     
36     /** Holds value of property property. */
37     private String JavaDoc property;
38     
39     /** Holds value of property featureName. */
40     private String JavaDoc featureName;
41     
42     public int doEndTag()
43         throws JspException
44     {
45         Object JavaDoc o = pageContext.getAttribute(name);
46         if(o == null)
47             throw new JspException("GetFeatureByNameTag requires type MBeanServer, no object found under name: " +name);
48         if(property != null)
49         {
50             String JavaDoc name = "get" +property.substring(0, 1).toUpperCase() +property.substring(1);
51             try
52             {
53                 Class JavaDoc clazz = o.getClass();
54                 Method m = clazz.getDeclaredMethod(name, new Class JavaDoc[0]);
55                 o = m.invoke(o, new Object JavaDoc[0]);
56             }catch(Exception JavaDoc ex)
57             {
58                 throw new JspException("error while accessing property: " +name +"; on object: "+ o +" - " +ex.getMessage());
59             }
60         }
61         
62         if(o == null ||!(o instanceof MBeanFeatureInfo[]))
63             throw new JspException("GetFeatureByNameTag requires type MBeanFeatureInfo[], Illegal name and or property");
64         
65         MBeanFeatureInfo features[] = (MBeanFeatureInfo[])o;
66         for(int i = 0; i < features.length; i++)
67         {
68             //if(Boolean.getBoolean(DEBUG_PROP))
69
// System.out.println("comparing: '" +features[i].getName() +"'; to: " +featureName);
70
if(features[i].getName().equals(featureName))
71             {
72                 pageContext.setAttribute(id, features[i]);
73                 if(Boolean.getBoolean(DEBUG_PROP))
74                     pageContext.getServletContext().log("setting attribute: " +id +"; to: " +features[i]);
75                 break;
76             }
77         }
78         return (EVAL_PAGE);
79     }
80     
81     /** Getter for property id.
82      * @return Value of property id.
83      */

84     public String JavaDoc getId() {
85         return id;
86     }
87     
88     /** Setter for property id.
89      * @param id New value of property id.
90      */

91     public void setId(String JavaDoc id) {
92         this.id = id;
93     }
94     
95     /** Getter for property name.
96      * @return Value of property name.
97      */

98     public String JavaDoc getName() {
99         return name;
100     }
101     
102     /** Setter for property name.
103      * @param name New value of property name.
104      */

105     public void setName(String JavaDoc name) {
106         this.name = name;
107     }
108     
109     /** Getter for property property.
110      * @return Value of property property.
111      */

112     public String JavaDoc getProperty() {
113         return property;
114     }
115     
116     /** Setter for property property.
117      * @param property New value of property property.
118      */

119     public void setProperty(String JavaDoc property) {
120         this.property = property;
121     }
122     
123     /** Getter for property featureName.
124      * @return Value of property featureName.
125      */

126     public String JavaDoc getFeatureName() {
127         return featureName;
128     }
129     
130     /** Setter for property featureName.
131      * @param featureName New value of property featureName.
132      */

133     public void setFeatureName(String JavaDoc featureName) {
134         this.featureName = featureName;
135     }
136     
137 }
138
Popular Tags