001package Torello.Java;
002
003/**
004 * Thrown when a <CODE>FileNode</CODE> operation has been invoked on an instance that represents
005 * an Operating-System <B><CODE>Directory</CODE></B>, but that invoked-method may only be applied
006 * to Operating-System <B><CODE>File</CODE></B> instances.  This is a {@code RuntimeException},
007 * not a checked-exception.
008 *
009 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=EXPM>
010 */
011public class FileExpectedException extends RuntimeException
012{
013    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX>  */
014    public static final long serialVersionUID = 1;
015
016    /**
017     * <EMBED CLASS='external-html' DATA-FILE-ID=EXPF>
018     * 
019     * <BR /><BR />This public final field contains the {@code FileNode} that caused an exception
020     * to throw.
021     */
022    public final FileNode fn;
023
024    /**
025     * Constructs a new exception with the specified detail message, and one {@code public, final} 
026     * parameter: {@code fn}.
027     * 
028     * @param message This is any message informing the user what has occurred.
029     * 
030     * @param fn This is the instance of {@code class FileNode} that was involved in the mistake.
031     * 
032     * <EMBED CLASS='external-html' DATA-FILE-ID=EXPF_PARAM>
033     * 
034     * @throws ExceptionCheckError If parameter {@code 'fn'} is passed null
035     * 
036     * @see #fn
037     */
038    public FileExpectedException(String message, FileNode fn)
039    {
040        super(message);
041        this.fn = fn;
042
043        if (this.fn == null) throw new ExceptionCheckError
044            ("FileExpectedException constructor parameter 'fn' was passed null");
045    }
046
047    /**
048     * Constructs a new exception with the specified detail message, cause-chain 
049     * {@code Throwable}, and one {@code public, final} parameter: {@code fn}.
050     * 
051     * @param message This is any message informing the user what has occurred.
052     * 
053     * @param cause This parameter may be used when generating "multiple-exceptions" that are 
054     * modified as they are thrown.
055     * 
056     * @param fn This is the instance of {@code class FileNode} that was involved in the mistake.
057     * 
058     * <EMBED CLASS='external-html' DATA-FILE-ID=EXPF_PARAM>
059     * 
060     * @throws ExceptionCheckError If parameter {@code 'fn'} is passed null
061     * 
062     * @see #fn
063     */
064    public FileExpectedException(String message, Throwable cause, FileNode fn)
065    {
066        super(message, cause);
067        this.fn = fn;
068
069        if (this.fn == null) throw new ExceptionCheckError
070            ("FileExpectedException constructor parameter 'fn' was passed null");
071    }
072
073    /**
074     * Checks whether or not the {@code FileNode} parameter passed is actually one representing a
075     * file, not a directory.
076     * 
077     * @param fn This may be any instance of {@code FileNode} however if it is not one that is
078     * meaning to represent an operating-system file, then this method will automatically throw an
079     * exception.
080     * 
081     * @throws FileExpectedException If parameter {@code 'fn'} is a file, not a directory.
082     */
083    public static void check(FileNode fn)
084    {
085        if (fn.isDirectory) throw new FileExpectedException(
086            "The invocation of the previous method on a FileNode that is, itself, a directory " +
087            "and not a file instead cannot proceed.",
088            fn
089        );
090    }
091}