KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > modules > fs > FileAttributes


1 /*
2  * Copyright 1999-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 org.apache.naming.modules.fs;
18
19 import java.io.File JavaDoc;
20
21 import javax.naming.directory.Attribute JavaDoc;
22 import javax.naming.directory.BasicAttribute JavaDoc;
23 import javax.naming.directory.BasicAttributes JavaDoc;
24
25 /**
26  * This specialized resource attribute implementation does some lazy
27  * reading (to speed up simple checks, like checking the last modified
28  * date).
29  */

30 public class FileAttributes extends BasicAttributes JavaDoc {
31     // -------------------------------------------------------- Constructor
32

33     public FileAttributes(File JavaDoc file) {
34         this.file = file;
35     }
36     
37     // --------------------------------------------------- Member Variables
38

39     
40     protected File JavaDoc file;
41     
42     
43     protected boolean accessed = false;
44         
45         
46     // ----------------------------------------- ResourceAttributes Methods
47
public static String JavaDoc CONTENT_LENGTH="contentLength";
48     
49     public Attribute JavaDoc get(String JavaDoc attrId) {
50         if( CONTENT_LENGTH.equalsIgnoreCase(attrId) ) {
51             // XXX use our own att, with long support
52
return new BasicAttribute JavaDoc(CONTENT_LENGTH, new Long JavaDoc( getContentLength() ));
53         }
54     return (super.get(attrId));
55     }
56
57         
58     /**
59      * Is collection.
60      */

61 // public boolean isCollection() {
62
// if (!accessed) {
63
// collection = file.isDirectory();
64
// accessed = true;
65
// }
66
// return super.isCollection();
67
// }
68

69     // Those methods avoid using an Attribute and return the real value.
70
// There is no caching at this level - use the higher level caching.
71

72     /**
73      * Get content length.
74      *
75      * @return content length value
76      */

77     public long getContentLength() {
78         long contentLength = file.length();
79         return contentLength;
80     }
81         
82         
83     /**
84      * Get creation time.
85      *
86      * @return creation time value
87      */

88     public long getCreation() {
89         long creation = file.lastModified();
90         return creation;
91     }
92     
93     /**
94      * Get last modified time.
95      *
96      * @return lastModified time value
97      */

98     public long getLastModified() {
99         long lastModified = file.lastModified();
100         return lastModified;
101     }
102     
103     /**
104      * Get resource type.
105      *
106      * @return String resource type
107      */

108     // public String getResourceType() {
109
// if (!accessed) {
110
// //collection = file.isDirectory();
111
// accessed = true;
112
// }
113
// return super.getResourceType();
114
// }
115
}
116
117
Popular Tags