KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > web > taglib > MBeanSortTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.jmx.browser.web.taglib;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Arrays JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.List JavaDoc;
13
14 import javax.servlet.jsp.JspException JavaDoc;
15 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
16
17 import org.apache.struts.util.RequestUtils;
18 import org.ejtools.jmx.MBeanSorter;
19
20 /**
21  * Description of the Class
22  *
23  * @author Laurent Etiemble
24  * @version $Revision: 1.1 $
25  * @todo Javadoc to complete
26  * @jsp:tag name="mbeanSort" body-content="empty"
27  */

28 public class MBeanSortTag extends TagSupport JavaDoc
29 {
30    /** Description of the Field */
31    protected String JavaDoc id = null;
32    /** Description of the Field */
33    protected String JavaDoc name = null;
34    /** Description of the Field */
35    protected String JavaDoc property = null;
36    /** Description of the Field */
37    protected String JavaDoc scope = null;
38
39
40    /**
41     * Description of the Method
42     *
43     * @return Description of the Returned Value
44     * @exception JspException Description of Exception
45     */

46    public int doStartTag()
47       throws JspException JavaDoc
48    {
49       Object JavaDoc object = null;
50
51       // Look up the requested bean (if necessary)
52
if (property != null)
53       {
54          object = RequestUtils.lookup(pageContext, name, property, scope);
55       }
56       else
57       {
58          object = RequestUtils.lookup(pageContext, name, scope);
59       }
60
61       if (object == null)
62       {
63          throw new JspException JavaDoc("Unable to find bean " + name + " or its property " + property);
64       }
65
66       List JavaDoc content = null;
67       if (object.getClass().isArray())
68       {
69          content = Arrays.asList((Object JavaDoc[]) object);
70          MBeanSorter.sortByName(content);
71       }
72       else
73       {
74          if (object instanceof Collection JavaDoc)
75          {
76             content = new ArrayList JavaDoc((Collection JavaDoc) object);
77          }
78          if (object instanceof List JavaDoc)
79          {
80             content = (List JavaDoc) object;
81          }
82          if (content != null)
83          {
84             MBeanSorter.sortByName(content);
85          }
86       }
87
88       // Put the sorted result in the pagecontext
89
if (content != null)
90       {
91          pageContext.setAttribute(id, content);
92       }
93       else
94       {
95          throw new JspException JavaDoc("Cannot sort input " + object);
96       }
97
98       // Continue processing this page
99
return (SKIP_BODY);
100    }
101
102
103    /**
104     * Gets the id attribute of the HiddenObjectTag object
105     *
106     * @return The id value
107     * @jsp:attribute name="id" required="true" rtexprvalue="true"
108     */

109    public String JavaDoc getId()
110    {
111       return (this.id);
112    }
113
114
115    /**
116     * Getter for the name attribute
117     *
118     * @return The value of name attribute
119     * @jsp:attribute name="name" required="true" rtexprvalue="true"
120     */

121    public String JavaDoc getName()
122    {
123       return (this.name);
124    }
125
126
127    /**
128     * Gets the property attribute of the HiddenObjectTag object
129     *
130     * @return The property value
131     * @jsp:attribute name="property" required="false" rtexprvalue="true"
132     */

133    public String JavaDoc getProperty()
134    {
135       return (this.property);
136    }
137
138
139    /**
140     * Getter for the scope attribute
141     *
142     * @return The value of scope attribute
143     * @jsp:attribute name="scope" required="false" rtexprvalue="true"
144     */

145    public String JavaDoc getScope()
146    {
147       return (this.scope);
148    }
149
150
151    /** Release all allocated resources. */
152    public void release()
153    {
154       super.release();
155       id = null;
156       name = null;
157       property = null;
158       scope = null;
159    }
160
161
162    /**
163     * Sets the id attribute of the HiddenObjectTag object
164     *
165     * @param id The new id value
166     */

167    public void setId(String JavaDoc id)
168    {
169       this.id = id;
170    }
171
172
173    /**
174     * Setter for the name attribute
175     *
176     * @param name The new value for name attribute
177     */

178    public void setName(String JavaDoc name)
179    {
180       this.name = name;
181    }
182
183
184    /**
185     * Sets the property attribute of the HiddenObjectTag object
186     *
187     * @param property The new property value
188     */

189    public void setProperty(String JavaDoc property)
190    {
191       this.property = property;
192    }
193
194
195    /**
196     * Setter for the scope attribute
197     *
198     * @param scope The new value for scope attribute
199     */

200    public void setScope(String JavaDoc scope)
201    {
202       this.scope = scope;
203    }
204 }
205
206
Popular Tags