KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GetKeyTag.java
10  *
11  * Created on October 24, 2001, 1:36 AM
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 /** This tag writes value of a key property to the generated page.
22  * CALL -> name.getKeyProperty(key)
23  *
24  * @author John Aronson
25  */

26 public class GetKeyTag
27     extends TagSupport
28 {
29     /** name is the ID of a page attribute of type ObjectName */
30     private String JavaDoc name;
31     
32     /** Holds value of property key. */
33     private String JavaDoc key;
34     
35     /** Creates new GetKeyTag */
36     public GetKeyTag()
37     { }
38
39     /** Process the start tag for this instance.
40      * @throws JspException
41      */

42     public int doStartTag()
43         throws JspException
44     {
45         Object JavaDoc o = pageContext.getAttribute(name);
46         if(o == null ||!(o instanceof ObjectName))
47             throw new JspException("GetKeyTag requires type ObjectName, Illegal name: " +o);
48         ObjectName name = (ObjectName)o;
49         o = name.getKeyProperty(key);
50         try{ pageContext.getOut().write(o != null ? o.toString() : "null"); }
51         /*try
52         {
53             if(o != null)
54                 pageContext.getOut().write(o.toString());
55         }*/
catch(IOException ie) { ie.printStackTrace(); }
56         return (SKIP_BODY);
57     }
58
59     /** Getter for property name.
60      * @return Value of property name.
61      */

62     public String JavaDoc getName()
63     {
64         return name;
65     }
66     
67     /** Setter for property name.
68      * @param name New value of property name.
69      */

70     public void setName(String JavaDoc name)
71     {
72         this.name = name;
73     }
74     
75     /** Getter for property key.
76      * @return Value of property key.
77      */

78     public String JavaDoc getKey()
79     {
80         return key;
81     }
82     
83     /** Setter for property key.
84      * @param key New value of property key.
85      */

86     public void setKey(String JavaDoc key)
87     {
88         this.key = key;
89     }
90     
91     /** Called on a Tag handler to release state
92      *
93      */

94     public void release()
95     {
96         name = key = null;
97     }
98     
99 }
100
Popular Tags