/*
 * @(#)DnsResponse.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */


package com.jscape.inet.dns;


import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;


/**
 * Implements the basic functionality of a DNS response.
 * <p/>
 * Example Usage:<P>
 * <pre>
 * // create new instance
 * Dns dns = new Dns();
 *
 * // creates DNS request with nameserver and domain as arguments
 * DnsRequest request = new DnsRequest("ns.myserver.com","myserver.com");
 * // retrieve only MX (mail exchanger) records
 * request.setRecordType(Dns.TYPE_MX);
 *
 * // gets DNS response
 * DnsResponse response = dns.getResponse(request);
 *
 * // print out records for response to console
 *
 * Enumeration e = response.getAnswers();
 * while(e.hasMoreElements()) {
 *   DnsRecord record = (DnsRecord) e.nextElement();
 *   System.out.println(record);
 * }
 * </pre>
 */
public class DnsResponse
        implements Serializable {

    /**
     * a <code>Vector</code> of <code>DnsRecord</code> indicating authoritative nameserver(s) for this <code>DnsResponse</code>.
     */
    protected Vector authorities;

    /**
     * a <code>Vector</code> of <code>DnsRecord</code> returned in response to <code>DnsRequest</code>.
     */
    protected Vector answers;

    /**
     * a <code>Vector</code> of <code>DnsRecord</code> containing additional information about this <code>DnsResponse</code>.
     */
    protected Vector additional;

    /**
     * the <code>DnsRequest</code> used to generated this <code>DnsResponse</code>.
     */
    protected DnsRequest request;

    /**
     * whether response was issued by authoritive DNS nameserver.
     */
    protected boolean authoritative;

    /**
     * whether response is recursive.
     */
    protected boolean recursive;

    /**
     * whether response is truncated.
     */
    protected boolean truncated;

    /**
     * Constructs a new <code>DnsResponse</code> instance.
     */
    public DnsResponse() {
        authorities = new Vector();
        answers = new Vector();
        additional = new Vector();
    }

    /**
     * Constructs a new <code>DnsResponse</code> instance.
     *
     * @param request     the <code>DnsRequest</code> used to generated this <code>DnsResponse</code>
     * @param answers     a <code>Vector</code> of <code>DnsRecord</code> returned in response to <code>DnsRequest</code>
     * @param authorities a <code>Vector</code> of <code>DnsRecord</code> indicating authoritative nameserver(s) for this <code>DnsResponse</code>
     * @param additional  a <code>Vector</code> of <code>DnsRecord</code> containing additional information about this <code>DnsResponse</code>
     *
     * @see com.jscape.inet.dns.record.DnsRecord
     * @see DnsRequest
     */
    public DnsResponse(DnsRequest request, Vector answers, Vector authorities, Vector additional) {
        this.request = request;
        this.answers = answers;
        this.authorities = authorities;
        this.additional = additional;
    }

    /**
     * Gets authoritative nameservers for query.
     * Returns an Enumeration of <code>DnsRecord</code>.
     *
     * @return Enumeration of DnsRecord
     *
     * @see com.jscape.inet.dns.record.DnsRecord
     */
    public Enumeration getAuthorities() {
        return authorities.elements();
    }

    /**
     * Gets answers to query.
     * Returns an Enumeration of <code>DnsRecord</code>.
     *
     * @return Enumeration of DnsRecord
     *
     * @see com.jscape.inet.dns.record.DnsRecord
     */
    public Enumeration getAnswers() {
        return answers.elements();
    }

    /**
     * Gets additional information about query.
     * Returns an Enumeration of <code>DnsRecord</code>.
     *
     * @return Enumeration of DnsRecord
     *
     * @see com.jscape.inet.dns.record.DnsRecord
     */
    public Enumeration getAdditional() {
        return additional.elements();
    }

    /**
     * Gets the <code>DnsRequest</code> used to generated this <code>DnsResponse</code>.
     *
     * @return a <code>DnsRequest</code>
     *
     * @see DnsRequest
     */
    public DnsRequest getRequest() {
        return request;
    }

    /**
     * Checks if DNS response was issued by an authoritative DNS nameserver.
     *
     * @return <code>true</code> if authoritative <code>false</code> otherwise
     */
    public boolean isAuthoritative() {
        return authoritative;
    }

    /**
     * Checks if query response is truncated.
     *
     * @return <code>true</code> if reponse is truncated <code>false</code> otherwise
     */
    public boolean isTruncated() {
        return truncated;
    }

    /**
     * Checks if query response is recursive.
     *
     * @return <code>true</code> if response is recursive <code>false</code> otherwise
     */
    public boolean isRecursive() {
        return recursive;
    }

}

