KickJava   Java API By Example, From Geeks To Geeks.

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


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  * FormParameterTag.java
10  *
11  * Created on December 10, 2001, 4:23 PM
12  */

13
14 package org.webjmx.tags;
15
16 import java.util.*;
17 import javax.management.*;
18 import javax.servlet.jsp.*;
19 import javax.servlet.jsp.tagext.*;
20
21 /** This tag writes an HTML form input tag to the output stream.
22  *
23  * @author John Aronson
24  */

25 public class FormParameterTag extends TagSupport
26     implements JMXTaglibConstants
27 {
28     /** Holds value of property name. Name of the form parameter this input field holds. Used to order parameter list passed in to the MBeanServer. */
29     private String JavaDoc name;
30     
31     /** Holds value of property type. Fully qualified Java classname for the parameter, passed in to the MBeanServer. */
32     private String JavaDoc type;
33     
34     /** Holds value of property value. Initial value of the form input field. */
35     private String JavaDoc value;
36     
37     /** Holds value of property mbeanName. */
38     private String JavaDoc mbeanName;
39     
40     /** Holds value of property parameterInfo. */
41     private String JavaDoc parameterInfo;
42     
43     /** Holds value of property count. */
44     private String JavaDoc count;
45     
46     /** Creates new FormParameterTag */
47     public FormParameterTag()
48     { }
49
50     /** Process the start tag for this instance.
51      * @throws JspException
52      */

53     public int doStartTag()
54         throws JspException
55     {
56         Object JavaDoc o = getParent();
57         while(o != null && !(o instanceof FormMBeanTag))
58             o = ((Tag)o).getParent();
59
60         if(!(o instanceof FormMBeanTag))
61             throw new JspException("enclosing tag must be of type formMBean.");
62         FormMBeanTag parent = (FormMBeanTag)o;
63         
64         if(parameterInfo != null)
65         {
66             o = pageContext.getAttribute(parameterInfo);
67             if( o == null || !(o instanceof MBeanParameterInfo))
68                 throw new JspException("tag attribute paramterInfo must point a page attribute of type MBeanParameterInfo, found: " +o);
69                 
70             MBeanParameterInfo pInfo = (MBeanParameterInfo)o;
71             name = pInfo.getName();
72             type = pInfo.getType();
73             if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("got name [" +name +"] and type[" +type +"] from parameterInfo.");
74         }
75         
76         if(count != null &&(name == null || name.length() == 0))
77             name = pageContext.getAttribute(count).toString();
78         
79         MBeanServer server = GetServerTag.getMBeanServer(parent.getLocator());
80
81         try
82         {
83             //get the type of the parameter
84
String JavaDoc pType = type;
85             
86             //should check for an "Enumerated" and do a select element in that case
87

88             StringBuffer JavaDoc results = new StringBuffer JavaDoc("<INPUT");
89             if(pType != null && pType.equalsIgnoreCase("java.lang.Boolean"))
90                 results.append(" TYPE=CHECKBOX");
91             else
92                 results.append(" TYPE=TEXT");
93             //could also check for numeric attributes and attach some javascript to validate
94

95             results.append(" NAME=\"");
96             if(name != null)
97                 results.append(name);
98             else if(mbeanName != null)
99                 results.append(TAGLIB_NAME);
100
101             if(value != null)
102             {
103                 results.append("\" VALUE=\"");
104                 results.append(value);
105             }
106             results.append("\"/>");
107             
108             if(type != null)
109             {
110                 results.append("\n<INPUT TYPE=HIDDEN NAME=\"");
111                 results.append(TAGLIB_TYPE_PREFIX);
112                 results.append(name);
113                 results.append("\" VALUE=\"");
114                 results.append(type);
115                 results.append("\"/>");
116             }
117             
118             pageContext.getOut().write(results.toString());
119         }catch(Exception JavaDoc ex)
120         {
121             ex.printStackTrace();
122             throw new JspException(ex.getMessage());
123         }
124         return (SKIP_BODY);
125     }
126     
127     /** Getter for property name.
128      * @return Value of property name.
129      */

130     public String JavaDoc getName()
131     {
132         return name;
133     }
134     
135     /** Setter for property name.
136      * @param name New value of property name.
137      */

138     public void setName(String JavaDoc name)
139     {
140         this.name = name;
141     }
142     
143     /** Getter for property type.
144      * @return Value of property type.
145      */

146     public String JavaDoc getType()
147     {
148         return type;
149     }
150     
151     /** Setter for property type.
152      * @param type New value of property type.
153      */

154     public void setType(String JavaDoc type)
155     {
156         this.type = type;
157     }
158     
159     /** Getter for property value.
160      * @return Value of property value.
161      */

162     public String JavaDoc getValue()
163     {
164         return value;
165     }
166     
167     /** Setter for property value.
168      * @param value New value of property value.
169      */

170     public void setValue(String JavaDoc value)
171     {
172         this.value = value;
173     }
174     
175     /** Called on a Tag handler to release state
176      *
177      */

178     public void release()
179     {
180         name = type = value = null;
181     }
182     
183     /** Getter for property mbeanName.
184      * @return Value of property mbeanName.
185      */

186     public String JavaDoc getMbeanName() {
187         return mbeanName;
188     }
189     
190     /** Setter for property mbeanName.
191      * @param mbeanName New value of property mbeanName.
192      */

193     public void setMbeanName(String JavaDoc mbeanName) {
194         this.mbeanName = mbeanName;
195     }
196     
197     /** Getter for property parameterInfo.
198      * @return Value of property parameterInfo.
199      */

200     public String JavaDoc getParameterInfo()
201     {
202         return parameterInfo;
203     }
204     
205     /** Setter for property parameterInfo.
206      * @param parameterInfo New value of property parameterInfo.
207      */

208     public void setParameterInfo(String JavaDoc parameterInfo)
209     {
210         this.parameterInfo = parameterInfo;
211     }
212     
213     /** Getter for property count.
214      * @return Value of property count.
215      */

216     public String JavaDoc getCount()
217     {
218         return count;
219     }
220     
221     /** Setter for property count.
222      * @param count New value of property count.
223      */

224     public void setCount(String JavaDoc count)
225     {
226         this.count = count;
227     }
228     
229 }
230
Popular Tags