KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > io > FileSource


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * FileSource.java
26  *
27  * Created on December 11, 2001, 12:46 AM
28  */

29
30 package com.sun.enterprise.util.io;
31
32 import java.io.*;
33
34 /**
35  *
36  * @author bnevins
37  * @version
38  */

39 public class FileSource
40 {
41     public FileSource(File f)
42     {
43         if(f == null)
44             throw new IllegalArgumentException JavaDoc("null File argument.");
45         else if(!f.exists())
46             throw new IllegalArgumentException JavaDoc("File doesn't exist: " + FileUtils.safeGetCanonicalPath(f));
47         
48         if(f.isDirectory())
49             isDir = true;
50         else
51             isDir = false;
52         
53         fileSource = f;
54     }
55     
56     ///////////////////////////////////////////////////////////////////////////
57

58     public boolean exists()
59     {
60         return fileSource != null && fileSource.exists();
61     }
62     
63     ///////////////////////////////////////////////////////////////////////////
64

65     public File getSource()
66     {
67         return fileSource;
68     }
69     
70     ///////////////////////////////////////////////////////////////////////////
71

72     public File getFile()
73     {
74         return fileSource;
75     }
76     
77     ///////////////////////////////////////////////////////////////////////////
78

79     public boolean isArchive()
80     {
81         return !isDir;
82     }
83     
84     ///////////////////////////////////////////////////////////////////////////
85

86     public boolean isDirectory()
87     {
88         return isDir;
89     }
90     
91     ///////////////////////////////////////////////////////////////////////////
92

93     public boolean isDir()
94     {
95         return isDirectory();
96     }
97     
98     ///////////////////////////////////////////////////////////////////////////
99

100     public String JavaDoc toString()
101     {
102         if(fileSource == null)
103             return "null FileSource";
104     
105         return FileUtils.safeGetCanonicalPath(fileSource);
106     }
107     
108     ///////////////////////////////////////////////////////////////////////////
109

110     private File fileSource = null;
111     private boolean isDir = false;
112 }
113
Popular Tags