1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package Torello.Java;

/**
 * Thrown when a <CODE>FileNode</CODE> operation has been invoked on an instance that represents
 * an Operating-System <B><CODE>Directory</CODE></B>, but that invoked-method may only be applied
 * to Operating-System <B><CODE>File</CODE></B> instances.  This is a {@code RuntimeException},
 * not a checked-exception.
 *
 * <BR /><BR /><EMBED CLASS="external-html" DATA-FILE-ID="EXPM">
 */
public class FileExpectedException extends RuntimeException
{
    /** <EMBED CLASS="external-html" DATA-FILE-ID="SVUIDEX">  */
    public static final long serialVersionUID = 1;

    /**
     * <EMBED CLASS="external-html" DATA-FILE-ID="EXPF">
     * 
     * <BR /><BR />This public final field contains the {@code FileNode} that caused an exception
     * to throw.
     */
    public final FileNode fn;

    /**
     * Constructs a new exception with the specified detail message, and one {@code public, final} 
     * parameter: {@code fn}.
     * 
     * @param message This is any message informing the user what has occurred.
     * 
     * @param fn This is the instance of {@code class FileNode} that was involved in the mistake.
     * <B><I>This parameter should not be left null.</I></B>  If it were accidentally left null,
     * this could force exception-handling code to to throw exceptions while checking exceptions!
     * 
     * @see #fn
     */
    public FileExpectedException(String message, FileNode fn)
    { super(message); this.fn = fn; }

    /**
     * Constructs a new exception with the specified detail message, cause-chain 
     * {@code Throwable}, and one {@code public, final} parameter: {@code fn}.
     * 
     * @param message This is any message informing the user what has occurred.
     * 
     * @param fn This is the instance of {@code class FileNode} that was involved in the mistake.
     * <B><I>This parameter should not be left null.</I></B>  If it were accidentally left null,
     * this could force exception-handling code to to throw exceptions while checking exceptions!
     * 
     * @param cause This parameter may be used when generating "multiple-exceptions" that are 
     * modified as they are thrown.
     * 
     * @see #fn
     */
    public FileExpectedException(String message, Throwable cause, FileNode fn)
    { super(message, cause); this.fn = fn; }


    /**
     * Checks whether or not the {@code FileNode} parameter passed is actually one representing a
     * file, not a directory.
     * 
     * @param fn This may be any instance of {@code FileNode} however if it is not one that is
     * meaning to represent an operating-system file, then this method will automatically throw an
     * exception.
     * 
     * @throws FileExpectedException If parameter {@code 'fn'} is a file, not a directory.
     */
    public static void check(FileNode fn)
    {
        if (fn.isDirectory) throw new FileExpectedException(
            "The invocation of the previous method on a FileNode that is, itself, a directory " +
            "and not a file instead cannot proceed.",
            fn
        );
    }
}