KickJava   Java API By Example, From Geeks To Geeks.

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


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  * FindServerTag.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 put a single MBeanServer instance in the page context under the given ID.
24  * CALL -> MBeanServerFactory.findMBeanServer(locator)
25  *
26  * @author John Aronson
27  */

28 public class GetServerTag extends TagSupport
29     implements ILocatorTag, JMXTaglibConstants
30 {
31     
32     /** Holds value of property id. Name of the pageContext attribute to be added. */
33     private String JavaDoc id;
34     
35     /** Holds value of property agentID. Search paramter for the finMBeanServer call. */
36     private String JavaDoc locator;
37     
38     /** Holds value of property attribute. */
39     private String JavaDoc attribute;
40     
41     /** Creates new GetServerTag */
42     public GetServerTag()
43     { }
44
45     /** Process the start tag for this instance.
46      * @throws JspException
47      * @return
48      */

49     public int doStartTag()
50         throws JspException
51     {
52         return (EVAL_BODY_INCLUDE);
53     }
54
55     /** Process the end tag for this instance.
56      * @throws JspException
57      * @return
58      */

59     public int doEndTag()
60         throws JspException
61     {
62         if(attribute != null && locator == null)
63             locator = pageContext.getAttribute(attribute).toString();
64         
65         pageContext.setAttribute(id, getMBeanServer(locator));
66         
67         return (EVAL_PAGE);
68     }
69     
70     /** static utility method which calls MBeanServerFactory.findMBeanServer and then returns the first server in that returned group which has a matching defaultDomain.
71      * @param locator search parameter for the FindMBeanServer call
72      * @throws JspException when an MBeanServer can not be found with a matching defaultDomain
73      * @return a single MBeanServer with a matching defaultDomain
74      */

75     public static MBeanServer getMBeanServer(String JavaDoc locator)
76         throws JspException
77     {
78         //System.out.println("getMBeanServer[" +locator +"]");
79
List l = AdapterFactory.findMBeanServer(locator);
80         if(l.size() == 1)
81             return (MBeanServer)l.get(0);
82         else if(l.size() > 1)
83             throw new JspException("multiple MBeanServers found, defaultDomain parameter is required to chose one");
84         else
85             throw new JspException("no MBeanServer found for locator: " +locator);
86     }
87     
88     /** Getter for property id.
89      * @return Value of property id.
90      */

91     public String JavaDoc getId()
92     {
93         return id;
94     }
95     
96     /** Setter for property id.
97      * @param id New value of property id.
98      */

99     public void setId(String JavaDoc id)
100     {
101         this.id = id;
102     }
103     
104     /** Getter for property locator.
105      * @return Value of property locator.
106      */

107     public String JavaDoc getLocator()
108     {
109         return locator;
110     }
111     
112     /** Setter for property locator.
113      * @param locator New value of property locator.
114      */

115     public void setLocator(String JavaDoc locator)
116     {
117         this.locator = locator;
118     }
119     
120     /** Called on a Tag handler to release state
121      *
122      */

123     public void release()
124     {
125         attribute = locator = id = null;
126     }
127
128     /** Getter for property attribute.
129      * @return Value of property attribute.
130      */

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

139     public void setAttribute(String JavaDoc attribute)
140     {
141         this.attribute = attribute;
142     }
143     
144 }
145
Popular Tags