//______________________________________________________________________________
//   |       |
//   | knipp |           Knipp Medien und Kommunikation GmbH
//    -------
//
//
//     Knipp RRI Toolkit
//
//
//     Copyright (C) 2005 by Knipp Medien und Kommunikation GmbH
//
//     This library 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 any later version.
// 
//     This library 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 library; if not, write to the 
//     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
//     Boston, MA 02111-1307 USA 
//
//
//     initial author:    Klaus Malorny
//
//     version:           1.4 (15127), 2011/06/03 14:52:49
//                        $Revision: 14936 $ 
//                        $Date: 2010-11-05 15:57:40 +0100 (Fri, 05 Nov 2010) $
//                        $Author: Klaus.Malorny $
//

package de.knipp.rritoolkit.request;

import java.io.IOException;

import org.w3c.dom.DOMException;

import de.knipp.rritoolkit.KVList;
import de.knipp.rritoolkit.Port;
import de.knipp.rritoolkit.XmlBuilder;
import de.knipp.rritoolkit.EncodeException;

import de.knipp.rritoolkit.response.DomainInfoResponse;


/**
 *  request to retrieve information about a given domain
 *
 *  @version  $Revision: 14936 $
 *  @author   Klaus Malorny
 */

public class DomainInfoRequest extends DomainSimpleRequest
{
  
  /** flag whether recurision is desired */
  
  private boolean withRecursion;
  
  
  /** flag whether provider information is desired */
  
  private boolean withProvider;
  
  
  
  /**
   *  constructor
   */
  
  public DomainInfoRequest ()
  {
    // empty
  }
  
  
  /**
   *  constructor
   *
   *  @param theDomainName          the domain name
   *  @param theEncodedDomainName   the encoded domain name, may be {@code null}
   *                                for ASCII only domains
   *  @param recursion              if {@code true}, full contact data
   *                                is retrieved also
   *  @param provider               if {@code true}, provider
   *                                information is included
   */
  
  public DomainInfoRequest (String theDomainName, String theEncodedDomainName,
    boolean recursion, boolean provider)
  {
    super (theDomainName, theEncodedDomainName);
    withRecursion = recursion;
    withProvider = provider;
  }


  /**
   *  constructor
   *
   *  @param theDomainName          the domain name
   *  @param theEncodedDomainName   the encoded domain name, may be {@code null}
   *                                for ASCII only domains
   */
  
  public DomainInfoRequest (String theDomainName, String theEncodedDomainName)
  {
    this (theDomainName, theEncodedDomainName, false, false);
  }


  
  /**
   *  constructor
   *
   *  @param theDomainName             the domain name
   */
  
  public DomainInfoRequest (String theDomainName)
  {
    this (theDomainName, null);
  }
  
  
  //--- implementation of Request ----------------------------------------------

  /**
   *  execute the this request on the given port. 
   *
   *  @param port                 the port on which this request shall
   *                              be executed
   *  @return                     the response
   *  @throws IOException         if the execution failed
   */

  @Override
  public DomainInfoResponse execute (Port port)
    throws IOException
  {
    return (DomainInfoResponse) super.execute (port);
  }
  
  
    
  /**
   *  return the XML element name
   *
   *  @return                      the element name
   */

  @Override
  protected String getRequestElementName ()
  {
    return "info";
  }
  
  

  /**
   *  allow the addition of attributes to the request. The default 
   *  implementation is empty and should not be called by implementing 
   *  subclasses
   *
   *  @param xb                   the XML builder
   *  @throws DOMException        on DOM exceptions
   *  @throws EncodeException     if the encoding fails for some reason
   */
  
  @Override
  protected void addAttributes (XmlBuilder xb)
    throws DOMException, EncodeException
  {
    xb.
      attf ("recursive", withRecursion).
      attf ("withProvider", withProvider);
  }
  
  
  
  
  /**
   *  return the action string for this request
   *
   *  @return                     the action string
   */

  @Override
  protected String getActionCode ()
  {
    return "info";
  }
  

  
  /**
   *  method that needs to be implemented by subclasses for the 
   *  key-value list conversion
   *
   *  @param list                   the list that has to be filled
   *  @throws EncodeException       if the encoding fails for some reason
   */
  
  @Override
  protected void requestToKVList (KVList list)
    throws EncodeException
  {
    super.requestToKVList (list);
    list.set ("withprovider", withProvider ? "true" : "false");
    list.set ("recursive", withRecursion ? "true" : "false");
  }
  
  
  
  
  /**
   *  return a string representation for debugging purposes
   *
   *  @return                 the representation
   */
  
  @Override
  public String toString ()
  {
    return super.toString () + "  with provider: " + withProvider + 
      "\n  with recursion: " + withRecursion +
      "\n";
  }
  
  
  //--- access methods ---------------------------------------------------------
  
  /**
   *  return whether the provider information shall be returned or not
   *
   *  @return                      {@code true} if provider information
   *                               shall be returned
   */
  
  public boolean withProvider ()
  {
    return withProvider;
  }
  
  
  /**
   *  set whether the provider information shall be returned or not
   *
   *  @param provider              {@code true} if provider information
   *                               shall be returned
   */
  
  public void setWithProvider (boolean provider)
  {
    withProvider = provider;
  }
  
  
  
  /**
   *  return whether contact data shall be retrieved also
   *
   *  @return                      {@code true} if so
   */
  
  public boolean withRecursion ()
  {
    return withRecursion;
  }
  
  
  /**
   *  set whether contact data shall be retrieved also
   *
   *  @param recursion             {@code true} if contact data shall be
   *                               retrieved
   */
  
  public void setWithRecursion (boolean recursion)
  {
    withRecursion = recursion;
  }
}


