001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.management.jmx;
016    
017    import com.liferay.portal.kernel.jmx.model.MBean;
018    import com.liferay.portal.kernel.management.ManageActionException;
019    
020    import javax.management.AttributeList;
021    import javax.management.MBeanAttributeInfo;
022    import javax.management.MBeanInfo;
023    import javax.management.MBeanServer;
024    import javax.management.ObjectName;
025    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class GetAttributesAction extends BaseJMXManageAction {
030    
031            public GetAttributesAction(MBean mBean) {
032                    _mBean = mBean;
033            }
034    
035            public void action() throws ManageActionException {
036                    try {
037                            ObjectName objectName = _mBean.getObjectName();
038    
039                            MBeanServer mBeanServer = getMBeanServer();
040    
041                            MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
042    
043                            MBeanAttributeInfo[] mBeanAttributeInfos =
044                                    mBeanInfo.getAttributes();
045    
046                            String[] attributeNames = new String[mBeanAttributeInfos.length];
047    
048                            for (int i = 0; i < attributeNames.length; i++) {
049                                    attributeNames[i] = mBeanAttributeInfos[i].getName();
050                            }
051    
052                            _attributeList = mBeanServer.getAttributes(
053                                    objectName, attributeNames);
054                    }
055                    catch (Exception e) {
056                            throw new ManageActionException(e);
057                    }
058            }
059    
060            public AttributeList getAttributeList() {
061                    return _attributeList;
062            }
063    
064            private AttributeList _attributeList;
065            private MBean _mBean;
066    
067    }