/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.test.jbossnet.jmx.server;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ReflectionException;

/**
 * A test dynamic mbean that will be provided as a web-service
 * @jmx.mbean name="jboss.net:service=JMXDynamicTestMBean"
 * @jboss-net.web-service urn="JMXDynamicTest" expose-all="true"
 * @author jung
 * @version $Revision: 1.1.1.1.4.2 $
 * @since 18.02.04
 */

public class JMXDynamicTest implements DynamicMBean
{

   /* Member variables */
   private String testString = "JMX_TEST_STRING";

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
    */
   public Object getAttribute(String attribute)
      throws AttributeNotFoundException, MBeanException, ReflectionException
   {
      return testString;
   }

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
    */
   public void setAttribute(Attribute attribute)
      throws
         AttributeNotFoundException,
         InvalidAttributeValueException,
         MBeanException,
         ReflectionException
   {
      testString = (String) attribute.getValue();
   }

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
    */
   public AttributeList getAttributes(String[] attributes)
   {
      return null;
   }

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
    */
   public AttributeList setAttributes(AttributeList attributes)
   {
      return null;
   }

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[], java.lang.String[])
    */
   public Object invoke(String actionName, Object[] params, String[] signature)
      throws MBeanException, ReflectionException
   {
      return null;
   }

   /* (non-Javadoc)
    * @see javax.management.DynamicMBean#getMBeanInfo()
    */
   public MBeanInfo getMBeanInfo()
   {
      MBeanAttributeInfo[] attrs =
         new MBeanAttributeInfo[] {
             new MBeanAttributeInfo(
               "TestString",
               "java.lang.String",
               "shit",
               true,
               true,
               false)};
      MBeanOperationInfo[] ops =
         new MBeanOperationInfo[] {
             new MBeanOperationInfo(
               "noopOperation",
               "shit",
               new MBeanParameterInfo[0],
               "void",
               MBeanOperationInfo.UNKNOWN)};
      MBeanInfo result =
         new MBeanInfo(
            getClass().getName(),
            "shit",
            attrs,
            new MBeanConstructorInfo[0],
            ops,
            new MBeanNotificationInfo[0]);
      return result;
   }
}
