KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > plugins > helpers > servlet > MBeanTag


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.console.plugins.helpers.servlet;
23
24 import org.jboss.console.plugins.helpers.jmx.Server;
25 import org.jboss.mx.util.MBeanProxy;
26
27 import javax.management.ObjectName JavaDoc;
28 import javax.servlet.jsp.JspTagException JavaDoc;
29 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
30
31 /**
32  * <description>
33  *
34  * @see <related>
35  *
36  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
37  * @version $Revision: 37459 $
38  *
39  * <p><b>Revisions:</b>
40  *
41  * <p><b>4 janv. 2003 Sacha Labourey:</b>
42  * <ul>
43  * <li> First implementation </li>
44  * </ul>
45  */

46 public class MBeanTag
47    extends TagSupport JavaDoc
48 {
49    protected String JavaDoc interfaceName = null;
50    protected String JavaDoc variableName = null;
51    protected String JavaDoc mbeanName = null;
52    
53    public String JavaDoc getIntf () { return this.interfaceName; }
54    public void setIntf (String JavaDoc intf) { this.interfaceName = intf; }
55    
56    public String JavaDoc getId () { return this.variableName; }
57    public void setId (String JavaDoc var) { this.variableName = var; }
58    
59    public String JavaDoc getMbean () { return this.mbeanName; }
60    public void setMbean (String JavaDoc mbean) { this.mbeanName = mbean; }
61    
62
63    public int doStartTag () throws JspTagException JavaDoc
64    {
65       try
66       {
67          // Who do we proxy?
68
//
69
ObjectName JavaDoc objName = null;
70          if (mbeanName == null)
71          {
72             objName = new ObjectName JavaDoc (pageContext.getRequest().getParameter("ObjectName"));
73          }
74          else
75          {
76             objName = new ObjectName JavaDoc (mbeanName);
77          }
78          
79          // Which type do we proxy?
80
//
81
Class JavaDoc type = Thread.currentThread().getContextClassLoader().loadClass(this.interfaceName);
82          
83          // we build the proxy
84
//
85
Object JavaDoc result = MBeanProxy.get(type, objName, Server.getMBeanServer());
86          
87          // we assign the proxy to the variable
88
//
89
pageContext.setAttribute(variableName, result);
90          
91          return EVAL_BODY_INCLUDE;
92       }
93       catch (Exception JavaDoc e)
94       {
95          throw new JspTagException JavaDoc (e.toString());
96       }
97    }
98
99    public int doEndTag () throws JspTagException JavaDoc
100    {
101       return EVAL_PAGE;
102    }
103 }
104
Popular Tags