KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ObjectNameTag.java
10  *
11  * Created on October 24, 2001, 11:10 AM
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 import org.webjmx.adapter.*;
22
23 /** This tag puts an ObjectName instance in the page context under the name given
24  * in the id property. The name information comes from the page attribute given in
25  * the attribute property of from the request parameter given in the paramter property.
26  *
27  * @author John Aronson
28  */

29 public class ObjectNameTag extends TagSupport
30     implements JMXTaglibConstants
31 {
32     
33     /** Holds value of property attribute. */
34     private String JavaDoc attribute;
35     
36     /** Holds value of property parameter. */
37     private String JavaDoc parameter;
38     
39     /** Holds value of property id. */
40     private String JavaDoc id;
41     
42     /** Creates new FindServerTag */
43     public ObjectNameTag()
44     { }
45
46     /** Process the start tag for this instance.
47      * @throws JspException
48      * @return
49      */

50     public int doStartTag()
51         throws JspException
52     {
53         String JavaDoc s = null;
54         if(attribute != null)
55             s = pageContext.getAttribute(attribute).toString();
56         else if(parameter != null)
57         {
58             /*pageContext.getServletContext().log("context: " +pageContext);
59             pageContext.getServletContext().log("request: " +pageContext.getRequest());
60             pageContext.getServletContext().log("parameter: " +pageContext.getRequest().getParameter(parameter));
61             pageContext.getServletContext().log("parameter name : " +parameter);
62             Enumeration e = pageContext.getRequest().getParameterNames();
63             while(e.hasMoreElements())
64             {
65                 String pname = (String)e.nextElement();
66                 pageContext.getServletContext().log("parameter [" +pname +"]: " +pageContext.getRequest().getParameter(pname));
67             }*/

68             
69             s = pageContext.getRequest().getParameter(parameter).toString();
70         }
71
72         if(s == null)
73             throw new JspException("tag ObjectName requires either the parameter or attribute to be set.");
74
75         if(id == null)
76             throw new JspException("tag ObjectName requires either the id attribute to be set.");
77
78         ObjectName name = null;
79         try{ name = new ObjectName(s); }
80         catch(Exception JavaDoc ex) { throw new JspException("tag ObjectName exception: " +ex.toString()); }
81         
82         pageContext.setAttribute(id, name);
83         
84         return (SKIP_BODY);
85     }
86        
87     /** Called on a Tag handler to release state
88      *
89      */

90     public void release()
91     {
92         attribute = parameter = id = null;
93     }
94
95     /** Getter for property attribute.
96      * @return Value of property attribute.
97      */

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

106     public void setAttribute(String JavaDoc attribute)
107     {
108         this.attribute = attribute;
109     }
110     
111     /** Getter for property parameter.
112      * @return Value of property parameter.
113      */

114     public String JavaDoc getParameter()
115     {
116         return parameter;
117     }
118     
119     /** Setter for property parameter.
120      * @param parameter New value of property parameter.
121      */

122     public void setParameter(String JavaDoc parameter)
123     {
124         this.parameter = parameter;
125     }
126     
127     /** Getter for property id.
128      * @return Value of property id.
129      */

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

138     public void setId(String JavaDoc id)
139     {
140         this.id = id;
141     }
142 }
143
Popular Tags