KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > ant > zip > Resource


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package net.sourceforge.groboutils.codecoverage.v2.ant.zip;
18
19 /**
20  * describes a File or a ZipEntry
21  *
22  * this class is meant to be used by classes needing to record path
23  * and date/time information about a file, a zip entry or some similar
24  * resource (URL, archive in a version control repository, ...)
25  *
26  * @author <a HREF="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
27  * @since Ant 1.5.2
28  */

29 public class Resource implements Cloneable JavaDoc, Comparable JavaDoc {
30     private String JavaDoc name = null;
31     private boolean exists = true;
32     private long lastmodified = 0;
33     private boolean directory = false;
34
35     /**
36      * default constructor
37      */

38     public Resource() {
39     }
40
41     /**
42      * only sets the name.
43      *
44      * <p>This is a dummy, used for not existing resources.</p>
45      *
46      * @param name relative path of the resource. Expects
47      * &quot;/&quot; to be used as the directory separator.
48      */

49     public Resource(String JavaDoc name) {
50         this(name, false, 0, false);
51     }
52
53     /**
54      * sets the name, lastmodified flag, and exists flag
55      *
56      * @param name relative path of the resource. Expects
57      * &quot;/&quot; to be used as the directory separator.
58      */

59     public Resource(String JavaDoc name, boolean exists, long lastmodified) {
60         this(name, exists, lastmodified, false);
61     }
62
63     /**
64      * @param name relative path of the resource. Expects
65      * &quot;/&quot; to be used as the directory separator.
66      */

67     public Resource(String JavaDoc name, boolean exists, long lastmodified,
68                     boolean directory) {
69         this.name = name;
70         this.exists = exists;
71         this.lastmodified = lastmodified;
72         this.directory = directory;
73     }
74
75     /**
76      * name attribute will contain the path of a file relative to the
77      * root directory of its fileset or the recorded path of a zip
78      * entry.
79      *
80      * <p>example for a file with fullpath /var/opt/adm/resource.txt
81      * in a file set with root dir /var/opt it will be
82      * adm/resource.txt.</p>
83      *
84      * <p>&quot;/&quot; will be used as the directory separator.</p>
85      */

86     public String JavaDoc getName() {
87         return name;
88     }
89
90     /**
91      * @param name relative path of the resource. Expects
92      * &quot;/&quot; to be used as the directory separator.
93      */

94     public void setName(String JavaDoc name) {
95         this.name = name;
96     }
97     /**
98      * the exists attribute tells whether a file exists
99      */

100     public boolean isExists() {
101         return exists;
102     }
103
104     public void setExists(boolean exists) {
105         this.exists = exists;
106     }
107
108     /**
109      * tells the modification time in milliseconds since 01.01.1970 of
110      *
111      * @return 0 if the resource does not exist to mirror the behavior
112      * of {@link java.io.File File}.
113      */

114     public long getLastModified() {
115         return !exists || lastmodified < 0 ? 0 : lastmodified;
116     }
117
118     public void setLastModified(long lastmodified) {
119         this.lastmodified = lastmodified;
120     }
121     /**
122      * tells if the resource is a directory
123      * @return boolean flag indicating if the resource is a directory
124      */

125     public boolean isDirectory() {
126         return directory;
127     }
128
129     public void setDirectory(boolean directory) {
130         this.directory = directory;
131     }
132
133     /**
134      * @return copy of this
135      */

136     public Object JavaDoc clone() {
137         try {
138             return super.clone();
139         } catch (CloneNotSupportedException JavaDoc e) {
140             throw new Error JavaDoc("CloneNotSupportedException for a "
141                             + "Clonable Resource caught?");
142         }
143     }
144
145     /**
146      * delegates to a comparison of names.
147      *
148      * @since Ant 1.6
149      */

150     public int compareTo(Object JavaDoc other) {
151         if (!(other instanceof Resource)) {
152             throw new IllegalArgumentException JavaDoc("Can only be compared with "
153                                                + "Resources");
154         }
155         Resource r = (Resource) other;
156         return getName().compareTo(r.getName());
157     }
158 }
159
Popular Tags