KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > ResourceAttributes


1 /*******************************************************************************
2  * Copyright (c) 2004 Red Hat Incorporated
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/org/documents/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API
10  * Red Hat Incorporated - initial implementation
11  *******************************************************************************/

12
13 package org.eclipse.core.resources;
14
15 import org.eclipse.core.filesystem.EFS;
16 import org.eclipse.core.internal.utils.FileUtil;
17 import org.eclipse.core.runtime.CoreException;
18
19 /**
20  * This class represents platform specific attributes of files.
21  * Any attributes can be added, but only the attributes that are
22  * supported by the platform will be used. These methods do not set the
23  * attributes in the file system.
24  * <p>
25  * This class is not intended to be subclassed. This class may be instantiated.
26  * </p>
27  *
28  * @author Red Hat Incorporated
29  * @see IResource#getResourceAttributes()
30  * @see IResource#setResourceAttributes(ResourceAttributes)
31  * @since 3.1
32  */

33 public class ResourceAttributes {
34     private int attributes;
35
36     /**
37      * Creates a new resource attributes instance with attributes
38      * taken from the specified file in the file system. If the specified
39      * file does not exist or is not accessible, this method has the
40      * same effect as calling the default constructor.
41      *
42      * @param file The file to get attributes from
43      * @return A resource attributes object
44      */

45     public static ResourceAttributes fromFile(java.io.File JavaDoc file) {
46         try {
47             return FileUtil.fileInfoToAttributes(EFS.getStore(file.toURI()).fetchInfo());
48         } catch (CoreException e) {
49             //file could not be accessed
50
return new ResourceAttributes();
51         }
52     }
53
54     /**
55      * Creates a new instance of <code>ResourceAttributes</code>.
56      */

57     public ResourceAttributes() {
58         super();
59     }
60
61     /**
62      * Returns whether this ResourceAttributes object is marked archive.
63      *
64      * @return <code>true</code> if this resource is marked archive,
65      * <code>false</code> otherwise
66      * @see #setArchive(boolean)
67      */

68     public boolean isArchive() {
69         return (attributes & EFS.ATTRIBUTE_ARCHIVE) != 0;
70     }
71
72     /**
73      * Returns whether this ResourceAttributes object is marked executable.
74      *
75      * @return <code>true</code> if this resource is marked executable,
76      * <code>false</code> otherwise
77      * @see #setExecutable(boolean)
78      */

79     public boolean isExecutable() {
80         return (attributes & EFS.ATTRIBUTE_EXECUTABLE) != 0;
81     }
82
83     /**
84      * Returns whether this ResourceAttributes object is marked hidden.
85      *
86      * @return <code>true</code> if this resource is marked hidden,
87      * <code>false</code> otherwise
88      * @see #setHidden(boolean)
89      * @since 3.2
90      */

91     public boolean isHidden() {
92         return (attributes & EFS.ATTRIBUTE_HIDDEN) != 0;
93     }
94
95     /**
96      * Returns whether this ResourceAttributes object is marked read only.
97      *
98      * @return <code>true</code> if this resource is marked as read only,
99      * <code>false</code> otherwise
100      * @see #setReadOnly(boolean)
101      */

102     public boolean isReadOnly() {
103         return (attributes & EFS.ATTRIBUTE_READ_ONLY) != 0;
104     }
105
106     /**
107      * Sets or unsets whether this ResourceAttributes object is marked archive.
108      *
109      * @param archive <code>true</code> to set it to be archive,
110      * <code>false</code> to unset
111      * @see #isArchive()
112      */

113     public void setArchive(boolean archive) {
114         set(EFS.ATTRIBUTE_ARCHIVE, archive);
115     }
116
117     /**
118      * Clears all of the bits indicated by the mask.
119      */

120     private void set(int mask, boolean value) {
121         if (value)
122             attributes |= mask;
123         else
124             attributes &= ~mask;
125     }
126
127     /**
128      * Sets or unsets whether this ResourceAttributes object is marked executable.
129      *
130      * @param executable <code>true</code> to set it to be executable,
131      * <code>false</code> to unset
132      * @see #isExecutable()
133      */

134     public void setExecutable(boolean executable) {
135         set(EFS.ATTRIBUTE_EXECUTABLE, executable);
136     }
137
138     /**
139      * Sets or unsets whether this ResourceAttributes object is marked hidden
140      *
141      * @param hidden <code>true</code> to set it to be marked hidden,
142      * <code>false</code> to unset
143      * @see #isHidden()
144      * @since 3.2
145      */

146     public void setHidden(boolean hidden) {
147         set(EFS.ATTRIBUTE_HIDDEN, hidden);
148     }
149
150     /**
151      * Sets or unsets whether this ResourceAttributes object is marked read only.
152      *
153      * @param readOnly <code>true</code> to set it to be marked read only,
154      * <code>false</code> to unset
155      * @see #isReadOnly()
156      */

157     public void setReadOnly(boolean readOnly) {
158         set(EFS.ATTRIBUTE_READ_ONLY, readOnly);
159     }
160
161     /**
162      * Returns a string representation of the attributes, suitable
163      * for debugging purposes only.
164      */

165     public String JavaDoc toString() {
166         return "ResourceAttributes(" + attributes + ')'; //$NON-NLS-1$
167
}
168 }
Popular Tags