/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.0 (the
 * "License"). You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 */
package net.jini.core.entry;

/**
 * Thrown when one tries to get an <code>Entry</code> from a service,
 * but the entry is unusable (due to serialization or other errors).
 * Normally <code>partialEntry</code> points to an entry with as many
 * fields as possible filled in, with the array <code>unusableFields</code>
 * naming the fields that could not be deserialized and the array
 * <code>nestedExceptions</code> having the corresponding exception.
 * <p>
 * If the serialized <code>Entry</code> was corrupt enough that no
 * attempt could even be made to deserialize its fields,
 * <code>partialEntry</code> and <code>unusableFields</code> will be
 * <code>null</code>, and <code>nestedExceptions</code> will be an
 * array with one element that is the offending exception.  This will
 * typically be because one or more of the classes of the <code>Entry</code>
 * type itself cannot be loaded.
 * <p>
 * The names in <code>unusableFields</code> can be used together with
 * the reflection mechanisms of <code>java.lang.reflect</code> to
 * examine the full state of the object.
 * 
 * @author Sun Microsystems, Inc.
 *
 * @since 1.0
 */
public class UnusableEntryException extends Exception {
    static final long serialVersionUID = -2199083666668626172L;

    /**
     * The partial entry.  Fields that could not be deserialized
     * will be <code>null</code>.
     *
     * @serial
     */
    public Entry partialEntry;

    /**
      *	The names of the unusable fields.  If the entry was entirely
      * unusable, <code>unusableFields</code> will be <code>null</code>.
      *
      * @serial
      */
    public String[] unusableFields;

    /**
     * The exception that caused the failure for the corresponding
     * field named in unusableFields.  If the entry was entirely
     * unusable, <code>nestedExceptions</code> will be an array with
     * the one exception that prevented its use.
     *
     * @serial
     */
    public Throwable[] nestedExceptions;

    /**
     * Create an exception for the given partial entry and vectors of
     * bad field names/nested exception pairs.
     *
     * @param partial     the Entry object on which the exception occurred
     * @param badFields   a String array containing the bad field names
     * @param exceptions  an array of Throwable objects associated with the
     *                    bad field names
     */
    public UnusableEntryException(Entry partial, String[] badFields,
	Throwable[] exceptions)
    {
	super();
	partialEntry = partial;
	unusableFields = badFields;
	nestedExceptions = exceptions;
    }

    /**
     * Create an exception for a nested exception that prevented even an
     * attempt to build an entry.
     *
     * @param e a Throwable representing the nested exception
     */
    public UnusableEntryException(Throwable e) {
	partialEntry = null;
	unusableFields = null;
	nestedExceptions = new Throwable[] { e };
    }
}
