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 javax.management.AttributeList;
21  import javax.management.MBeanAttributeInfo;
22  import javax.management.MBeanInfo;
23  import javax.management.MBeanServer;
24  import javax.management.ObjectName;
25  
26  /**
27   * <a href="GetAttributesAction.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Shuyang Zhou
30   */
31  public class GetAttributesAction extends BaseJMXManageAction<AttributeList> {
32  
33      public GetAttributesAction(MBean mBean) {
34          _mBean = mBean;
35      }
36  
37      public AttributeList action() throws ManageActionException {
38          try {
39              ObjectName objectName = _mBean.getObjectName();
40  
41              MBeanServer mBeanServer = getMBeanServer();
42  
43              MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
44  
45              MBeanAttributeInfo[] mBeanAttributeInfos =
46                  mBeanInfo.getAttributes();
47  
48              String[] attributeNames = new String[mBeanAttributeInfos.length];
49  
50              for (int i = 0; i < attributeNames.length; i++) {
51                  attributeNames[i] = mBeanAttributeInfos[i].getName();
52              }
53  
54              return mBeanServer.getAttributes(objectName, attributeNames);
55          }
56          catch (Exception e) {
57              throw new ManageActionException(e);
58          }
59      }
60  
61      private MBean _mBean;
62  
63  }