/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

// $Id: MBeanParameterInfoDeser.java,v 1.5.6.1 2005/03/02 14:19:55 tdiesler Exp $

package org.jboss.net.jmx.adaptor;

import org.jboss.axis.encoding.DeserializationContext;
import org.jboss.axis.encoding.Deserializer;
import org.jboss.axis.encoding.DeserializerImpl;
import org.jboss.axis.encoding.DeserializerTarget;
import org.jboss.axis.message.SOAPHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import javax.management.MBeanParameterInfo;
import javax.xml.namespace.QName;

/**
 * An <code>MBeanParameterInfoDeser</code> is be used to deserialize
 * MBeanParameterInfo using the <code>SOAP-ENC</code>
 * encoding style.<p>
 *
 * @author <a href="mailto:a_taherkordi@users.sourceforge.net">Alireza Taherkordi</a>
 * @version $Revision: 1.5.6.1 $
 */
public class MBeanParameterInfoDeser extends DeserializerImpl
{

   private String name;
   private String type;
   private String description;

   public void onStartElement(String namespace, String localName,
                              String prefix, Attributes attributes,
                              DeserializationContext context)
           throws SAXException
   {

      if (context.isNil(attributes))
      {
         return;
      }

      //nothing to do

   }

   public SOAPHandler onStartChild(String namespace,
                                   String localName,
                                   String prefix,
                                   Attributes attributes,
                                   DeserializationContext context)
           throws SAXException
   {


      // Get the type
      QName itemType = context.getTypeFromAttributes(namespace,
              localName,
              attributes);
      // Get the deserializer
      Deserializer dSer = null;
      if (itemType != null)
      {
         dSer = context.getDeserializerForType(itemType);
      }
      if (dSer == null)
      {
         dSer = new DeserializerImpl();
      }

      // When the value is deserialized, inform us.
      // Need to pass the localName as a hint
      dSer.registerValueTarget(new DeserializerTarget(this, localName));

      addChildDeserializer(dSer);

      return (SOAPHandler)dSer;
   }

   public void setChildValue(Object value, Object hint) throws SAXException
   {
      if (hint.equals("name"))
         name = (String)value;
      else if (hint.equals("type"))
         type = (String)value;
      else if (hint.equals("description"))
         description = (String)value;

   }

   public void onEndElement(String s, String s1, DeserializationContext deserializationcontext)
   {
      try
      {
         super.value = new MBeanParameterInfo(name, type, description);
      }
      catch (Exception exception)
      {
         exception.printStackTrace();
      }
   }


}