1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.management.jmx;
16  
17  import com.liferay.portal.kernel.jmx.model.MBean;
18  import com.liferay.portal.kernel.management.ManageActionException;
19  
20  import java.util.HashSet;
21  import java.util.Set;
22  
23  import javax.management.MBeanServer;
24  import javax.management.MalformedObjectNameException;
25  import javax.management.ObjectName;
26  
27  /**
28   * <a href="ListMBeansAction.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Shuyang Zhou
31   */
32  public class ListMBeansAction extends BaseJMXManageAction<Set<MBean>> {
33  
34      public ListMBeansAction(String domainName) {
35          _domainName = domainName;
36      }
37  
38      public Set<MBean> action() throws ManageActionException {
39          try {
40              MBeanServer mBeanServer = getMBeanServer();
41  
42              Set<ObjectName> objectNames = mBeanServer.queryNames(
43                  null, new ObjectName(_domainName.concat(":*")));
44  
45              Set<MBean> mBeans = new HashSet<MBean>(objectNames.size());
46  
47              for (ObjectName objectName : objectNames) {
48                  mBeans.add(new MBean(objectName));
49              }
50  
51              return mBeans;
52          }
53          catch (MalformedObjectNameException mone) {
54              throw new ManageActionException(mone);
55          }
56      }
57  
58      private String _domainName;
59  
60  }