KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > config > FileOption


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.config;
35
36 import java.io.*;
37
38 /** Class representing all configuration options with values of type File.
39  * @version $Id: FileOption.java 3799 2006-04-18 16:36:51Z dlsmith $
40  */

41 public class FileOption extends Option<File> {
42   
43   /** Special sentinal file indicating that this option is not set. */
44   public static final File NULL_FILE = new File("") {
45     public boolean canRead() { return false; }
46     public boolean canWrite() { return false; }
47     public int compareTo(File f) { return (f == this) ? 0 : -1; }
48     public boolean createNewFile() { return false; }
49     public boolean delete() { return false; }
50     public void deleteOnExit() {}
51     public boolean equals(Object JavaDoc o) { return o == this; }
52     public boolean exists() { return true; }
53     public File getAbsoluteFile() { return this; }
54     public String JavaDoc getAbsolutePath() { return ""; }
55     public File getCanonicalFile() { return this; }
56     public String JavaDoc getCanonicalPath() { return ""; }
57     public String JavaDoc getName() { return ""; }
58     public String JavaDoc getParent() { return null; }
59     public File getParentFile() { return null; }
60     public String JavaDoc getPath() { return ""; }
61     public int hashCode() { return getClass().hashCode(); }
62     public boolean isAbsolute() { return false; }
63     public boolean isDirectory() { return false; }
64     public boolean isFile() { return false; }
65     public boolean isHidden() { return false; }
66     public long lastModified() { return 0L; }
67     public long length() { return 0L; }
68     public String JavaDoc[] list() { return null; }
69     public String JavaDoc[] list(FilenameFilter filter) { return null; }
70     public File[] listFiles() { return null; }
71     public File[] listFiles(FileFilter filter) { return null; }
72     public File[] listFiles(FilenameFilter filter) { return null; }
73     public boolean mkdir() { return false; }
74     public boolean mkdirs() { return false; }
75     public boolean renameTo(File dest) { return false; }
76     public boolean setLastModified(long time) { return false; }
77     public boolean setReadOnly() { return false; }
78     public String JavaDoc toString() { return ""; }
79     //public URI toURI() {} (Defer to super implementation.)
80
//public URL toURL() {} (Defer to super implementation.)
81
};
82   
83   /** @param key The name of this option. */
84   public FileOption(String JavaDoc key, File def) { super(key,def); }
85   
86   /** @param s The String to be parsed, must represent a legal file path for the File to be created.
87    * @return The absolute File object corresponding to the input path string.
88    */

89   public File parse(String JavaDoc s) {
90     if (s.trim().equals("")) return NULL_FILE;
91     
92     try { return new File(s).getAbsoluteFile(); }
93     catch (NullPointerException JavaDoc e) { throw new OptionParseException(name, s, "Must have a legal filename."); }
94   }
95
96   /** @param f The instance of class File to be formatted.
97    * @return A String representing the absolute path of "f".
98    */

99   public String JavaDoc format(File f) { return f.getAbsolutePath(); }
100 }
Popular Tags