/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package org.jboss.security.auth.login;

import javax.xml.namespace.QName;

import org.jboss.xb.binding.GenericValueContainer;

/**
 * ModuleOption declares a constructor that takes name as a parameter while the
 * value should be set with the setter. This use-case is not supported
 * out-of-the-box by jbxb, so, we use this container.
 * 
 * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
 * @version <tt>$Revision: 1.1.2.1 $</tt>
 */
public class ModuleOptionContainer
   implements GenericValueContainer
{
   private String name;
   private Object value;


   /**
    @return - the option value
    */
   public Object getValue()
   {
      return value;
   }

   /**
    Setter used when the module option is passed as the text body of the
    module-option element.

    @param value - text value
    */
   public void setValue(Object value)
   {
      this.value = value;
   }

   /**
    Add attributes or nested element content.

    @param name - the attribute or element name  
    @param value - the attribute or element value
    */
   public void addChild(QName name, Object value)
   {
      if("name".equals(name.getLocalPart()))
      {
         this.name = (String)value;
      }
      else
      {
         this.value = value;
      }
   }

   public Object instantiate()
   {
      ModuleOption option = new ModuleOption(name);
      option.setValue(value);
      return option;
   }
}
