KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > plugins > EJBModuleLister


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;
23
24 import org.jboss.console.manager.interfaces.ManageableResource;
25 import org.jboss.console.manager.interfaces.ResourceTreeNode;
26 import org.jboss.console.manager.interfaces.TreeNode;
27 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry;
28 import org.jboss.console.manager.interfaces.impl.HttpLinkTreeAction;
29 import org.jboss.console.manager.interfaces.impl.MBeanResource;
30 import org.jboss.console.manager.interfaces.impl.SimpleTreeNodeMenuEntryImpl;
31 import org.jboss.console.plugins.helpers.AbstractPluginWrapper;
32
33 import javax.management.ObjectInstance JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35 /**
36  * As the number of MBeans is very big, we use a real Java class which is far
37  * faster than beanshell
38  *
39  * @see <related>
40  *
41  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
42  * @version $Revision: 37459 $
43  *
44  * <p><b>Revisions:</b>
45  *
46  * <p><b>2 janv. 2003 Sacha Labourey:</b>
47  * <ul>
48  * <li> First implementation </li>
49  * </ul>
50  */

51 public class EJBModuleLister
52    extends AbstractPluginWrapper
53 {
54
55    protected final static String JavaDoc JMX_JSR77_DOMAIN = "jboss.management.local";
56    
57    public EJBModuleLister () { super(); }
58       
59    ResourceTreeNode[] createBeans (ObjectName JavaDoc parent) throws Exception JavaDoc
60    {
61       // there is a bug in the current jsr77 implementation with regard to naming
62
// of EJBModule that are part of EARs => I've used a workaround
63
//
64
ObjectInstance JavaDoc[] insts = getMBeansForQuery(JMX_JSR77_DOMAIN +
65          ":EJBModule="+parent.getKeyProperty("name")+",*", null);
66
67       ResourceTreeNode[] ejbs = new ResourceTreeNode[insts.length];
68       for (int i=0; i<insts.length; i++)
69       {
70          ObjectName JavaDoc objName = insts[i].getObjectName();
71          String JavaDoc type = objName.getKeyProperty("j2eeType");
72
73          String JavaDoc ejbName = objName.getKeyProperty("name");
74          String JavaDoc containerUrl = "jboss.j2ee:service=EJB,jndiName=" + ejbName;
75          containerUrl = java.net.URLEncoder.encode(containerUrl);
76          containerUrl = "/jmx-console/HtmlAdaptor?action=inspectMBean&name=" + containerUrl;
77
78          TreeNodeMenuEntry[] menus = new TreeNodeMenuEntry[]
79             {
80                new SimpleTreeNodeMenuEntryImpl ("View container in other window",
81                   new HttpLinkTreeAction (containerUrl, "_blank")
82                )
83             };
84             
85          String JavaDoc j2eeType = objName.getKeyProperty ("j2eeType");
86          String JavaDoc filename = "EJB.jsp";
87          if (j2eeType.equalsIgnoreCase ("StatelessSessionBean"))
88          {
89             filename = "StatelessEjb.jsp";
90          }
91          else if (j2eeType.equalsIgnoreCase ("StatefulSessionBean"))
92          {
93             filename = "StatefulEjb.jsp";
94          }
95          else if (j2eeType.equalsIgnoreCase ("EntityBean"))
96          {
97             filename = "EntityEjb.jsp";
98          }
99          else if (j2eeType.equalsIgnoreCase ("MessageDrivenBean"))
100          {
101             filename = "MdbEjb.jsp";
102          }
103          
104          ejbs[i] = createResourceNode(
105                ejbName, // name
106
type, // description
107
"images/bean.gif", // Icon URL
108
filename+"?ObjectName=" + encode(objName.toString()), // Default URL
109
menus,
110                null, // sub nodes
111
null, // Sub-Resources
112
objName.toString(),
113                insts[i].getClassName()
114             );
115          
116       }
117           
118       return ejbs;
119    }
120
121    protected TreeNode getTreeForResource(String JavaDoc profile, ManageableResource resource)
122    {
123       try
124       {
125          ObjectName JavaDoc objName = ((MBeanResource)resource).getObjectName();
126
127          return createTreeNode
128             (
129                objName.getKeyProperty("name"), // name
130
"", // description
131
"images/beans.gif", // Icon URL
132
"EJBModule.jsp?ObjectName=" + encode(objName.toString()), // Default URL
133
null,
134                null, // sub nodes
135
createBeans (objName) // Sub-Resources
136
).setMasterNode(true);
137          
138       }
139       catch (Exception JavaDoc e)
140       {
141          e.printStackTrace ();
142          System.out.println (checker);
143          return null;
144          
145       }
146    }
147
148 }
149
Popular Tags