//______________________________________________________________________________
//   |       |
//   | 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.3 (15112), 2011/05/27 16:00:14
//                        $Revision: 14936 $
//                        $Date: 2010-11-05 15:57:40 +0100 (Fri, 05 Nov 2010) $
//                        $Author: Klaus.Malorny $
//

package de.knipp.rritoolkit.message;


import org.w3c.dom.DOMException;
import org.w3c.dom.Element;

import de.knipp.rritoolkit.ResponseParseException;
import de.knipp.rritoolkit.KVList;

import static de.knipp.rritoolkit.DenicConstants.NS_MESSAGE;

import static de.knipp.rritoolkit.XmlHelper.getFirstElement;
import static de.knipp.rritoolkit.XmlHelper.getFirstElementText;

/**
 *  class that represents the AuthInfo2 notify message
 *
 *  @version  $Revision: 14936 $
 *  @author   Klaus Malorny
 */

public class AuthInfo2NotifyMessage extends Message
{
  /** the domain name */

  private String domainName;


  /** the encoded domain name */

  private String encodedDomainName;





  /**
   *  setup the object's data from the given XML element.
   *
   *  @param el                       the element
   *  @throws DOMException            on DOM exceptions
   *  @throws ResponseParseException  if the data was not recognized
   */

  @Override
  protected void dataFromXml (Element el)
    throws DOMException, ResponseParseException
  {
    Element elDomain = getFirstElement (el, NS_MESSAGE, "domain");

    if (elDomain == null)
      throw new ResponseParseException ("domain element missing", el);

    domainName = getFirstElementText (elDomain, NS_MESSAGE, "handle");
    encodedDomainName = getFirstElementText (elDomain, NS_MESSAGE, "ace");

    if (domainName == null || encodedDomainName == null)
      throw new ResponseParseException ("domain name elements missing",
        elDomain);
  }




  /**
   *  setup the object's data from the given list.
   *
   *  @param list                     the list
   *  @throws ResponseParseException  if the list does not contain the
   *                                  expected content
   */

  @Override
  protected void dataFromList (KVList list)
    throws ResponseParseException
  {
    domainName = list.getFirst ("domain");
    encodedDomainName = list.getFirst ("domain-ace");

    if (domainName == null)
      throw new ResponseParseException ("domain name missing", "domain",
        (String) null);

    if (encodedDomainName == null)
      throw new ResponseParseException ("encoded domain name missing",
        "domain-ace", (String) null);
  }


  /**
   *  call the suitable method of the given visitor
   *
   *  @param visitor               the visitor
   */

  @Override
  public void accept (MessageVisitor visitor)
  {
    visitor.visit (this);
  }




  /**
   *  return a string representation for debugging purposes
   *
   *  @return                      the string representation
   */

  @Override
  public String toString ()
  {
    StringBuilder sb = new StringBuilder ();
    sb.append (super.toString ());
    sb.append ("  domain name: ");
    sb.append (domainName);
    sb.append ("\n  encoded domain name: ");
    sb.append (encodedDomainName);
    sb.append ("\n");

    return sb.toString ();
  }


  //--- access methods ---------------------------------------------------------

  /**
   *  return the domain name
   *
   *  @return                        the domain name
   */

  public String getDomainName ()
  {
    return domainName;
  }



  /**
   *  return the encoded domain name
   *
   *  @return                       the encoded domain name
   */

  public String getEncodedDomainName ()
  {
    return encodedDomainName;
  }


}


