KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.ObjectInstance JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.jboss.console.manager.interfaces.ManageableResource;
28 import org.jboss.console.manager.interfaces.ResourceTreeNode;
29 import org.jboss.console.manager.interfaces.TreeNode;
30 import org.jboss.console.manager.interfaces.impl.MBeanResource;
31 import org.jboss.console.manager.interfaces.impl.SimpleTreeNode;
32 import org.jboss.console.plugins.helpers.AbstractPluginWrapper;
33
34 /**
35  *
36  *
37  */

38 public class JMSLister extends AbstractPluginWrapper
39 {
40    private static final long serialVersionUID = -2428954274429502892L;
41
42    protected final static String JavaDoc JMX_JSR77_DOMAIN = "jboss.management.local";
43
44    public JMSLister()
45    {
46       super();
47    }
48
49    protected TreeNode getTreeForResource(String JavaDoc profile, ManageableResource resource)
50    {
51       try
52       {
53          ObjectName JavaDoc objName = ((MBeanResource) resource).getObjectName();
54          SimpleTreeNode node = createTreeNode(objName.getKeyProperty("name"), // name
55
"", // description
56
"images/spirale.gif", // Icon URL
57
null, // Default URL
58
null, createDestinations(), // sub nodes
59
null // Sub-Resources
60
);
61          node.setMasterNode(true);
62          return node;
63
64       }
65       catch (Exception JavaDoc e)
66       {
67          e.printStackTrace();
68          System.out.println(checker);
69          return null;
70
71       }
72    }
73
74    private TreeNode[] createDestinations() throws Exception JavaDoc
75    {
76       TreeNode[] destinations = new TreeNode[2];
77
78       destinations[0] = createTreeNode("Queues", "", "images/spirale.gif", null, null, null,
79             createDestinationItems("Queue"));
80       destinations[1] = createTreeNode("Topics", "", "images/spirale.gif", null, null, null,
81             createDestinationItems("Topic"));
82
83       return destinations;
84    }
85
86    /**
87     *
88     * @return
89     * @throws Exception
90     */

91    private ResourceTreeNode[] createDestinationItems(String JavaDoc type) throws Exception JavaDoc
92    {
93       ObjectInstance JavaDoc[] insts = getMBeansForQuery("jboss.mq.destination:service=" + type + ",*", null);
94       ResourceTreeNode[] destinations = new ResourceTreeNode[insts.length];
95       //JMSDestinationManager jmsServer = (JMSDestinationManager)this.mbeanServer.getAttribute(new ObjectName("jboss.mq:service=DestinationManager"), "Interceptor");
96
for (int i = 0; i < insts.length; i++)
97       {
98          ObjectName JavaDoc objName = insts[i].getObjectName();
99          destinations[i] = createDestinationItem(objName);
100       }
101       return destinations;
102    }
103
104    /**
105     * @param objName
106     * @return
107     */

108    private ResourceTreeNode createDestinationItem(ObjectName JavaDoc objName) throws Exception JavaDoc
109    {
110       String JavaDoc destinationName = objName.getKeyProperty("name");
111       String JavaDoc type = objName.getKeyProperty("service");
112       String JavaDoc className = this.mbeanServer.getMBeanInfo(objName).getClassName();
113       String JavaDoc fileName = "";
114       if (type.equalsIgnoreCase("Queue"))
115       {
116          fileName = "Queue.jsp";
117       }
118       else if (type.equalsIgnoreCase("Topic"))
119       {
120          fileName = "Topic.jsp";
121       }
122
123       ResourceTreeNode item = this.createResourceNode(destinationName, type, //Description Tooltip
124
"images/serviceset.gif", fileName + "?ObjectName=" + encode(objName.toString()), null, //menus
125
null, //sub-nodes
126
null, //sub-resources
127
objName.toString(), className);
128       return item;
129    }
130
131 }
132
Popular Tags