KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > FileSystemCapability


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.filesystems;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 /** This class defines the capabilities of a filesystem to
29 * take part in different operations. Some filesystems are
30 * not designed to allow compilation on them, some do not want
31 * to be present in class path when executing or debugging
32 * a program.
33 * <P>
34 * Moreover there can be additional capabilities to check
35 * and this class defines ways how one can communicated with
36 * a filesystem to find out whether the system is "capable"
37 * enough to be used in the operation.
38 *
39 * @author Jaroslav Tulach
40  * @deprecated Now useless.
41 */

42 @Deprecated JavaDoc
43 public class FileSystemCapability extends Object JavaDoc {
44     /** Object that is capable of every thing.
45     */

46     public static final FileSystemCapability ALL = new FileSystemCapability() {
47             public boolean capableOf(FileSystemCapability c) {
48                 return true;
49             }
50         };
51
52     /** Well known capability of being compiled.
53      * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
54      */

55     @Deprecated JavaDoc
56     public static final FileSystemCapability COMPILE = new FileSystemCapability();
57
58     /** Well known ability to be executed.
59      * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
60      */

61     @Deprecated JavaDoc
62     public static final FileSystemCapability EXECUTE = new FileSystemCapability();
63
64     /** Well known ability to be debugged.
65      * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
66      */

67     @Deprecated JavaDoc
68     public static final FileSystemCapability DEBUG = new FileSystemCapability();
69
70     /** Well known ability to contain documentation files
71      * @deprecated Please use <a HREF="@org-netbeans-api-java@/org/netbeans/api/queries/JavadocForBinaryQuery.html"><code>JavadocForBinaryQuery</code></a> instead.
72      */

73     @Deprecated JavaDoc
74     public static final FileSystemCapability DOC = new FileSystemCapability();
75
76     public FileSystemCapability() {
77         if (DOC == null) {
78             // do not report static initializers
79
return;
80         }
81
82         assert FileUtil.assertDeprecatedMethod();
83     }
84
85     /** Basic operation that tests whether this object
86     * is capable to do different capability.
87     * <P>
88     * The default implementation claims that it is
89     * capable to handle only identical capability (==).
90     *
91     * @param c capability to test
92     * @return true if yes
93     */

94     public boolean capableOf(FileSystemCapability c) {
95         return c == this;
96     }
97
98     /** All filesystems that are capable of this capability.
99     * @return enumeration of FileSystems that satifies this capability
100     * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
101     */

102     @Deprecated JavaDoc
103     public Enumeration JavaDoc<? extends FileSystem> fileSystems() {
104         class FFS implements org.openide.util.Enumerations.Processor<FileSystem, FileSystem> {
105             @Deprecated JavaDoc
106             public FileSystem process(FileSystem fs, Collection JavaDoc<FileSystem> ignore) {
107                 return fs.getCapability().capableOf(FileSystemCapability.this) ? fs : null;
108             }
109         }
110
111         return org.openide.util.Enumerations.filter(ExternalUtil.getRepository().fileSystems(), new FFS());
112     }
113
114     /** Find a resource in repository, ignoring not capable filesystems.
115     * @param resName name of the resource
116     * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
117     */

118     @Deprecated JavaDoc
119     public FileObject findResource(String JavaDoc resName) {
120         Enumeration JavaDoc<? extends FileSystem> en = fileSystems();
121
122         while (en.hasMoreElements()) {
123             FileSystem fs = en.nextElement();
124             FileObject fo = fs.findResource(resName);
125
126             if (fo != null) {
127                 // object found
128
return fo;
129             }
130         }
131
132         return null;
133     }
134
135     /** Searches for the given resource among all filesystems
136     * that satifies this capability, returning all matches.
137     * @param name name of the resource
138     * @return enumeration of {@link FileObject}s
139     * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
140     */

141     @Deprecated JavaDoc
142     public Enumeration JavaDoc<? extends FileObject> findAllResources(String JavaDoc name) {
143         Vector JavaDoc<FileObject> v = new Vector JavaDoc<FileObject>(8);
144         Enumeration JavaDoc<? extends FileSystem> en = fileSystems();
145
146         while (en.hasMoreElements()) {
147             FileSystem fs = en.nextElement();
148             FileObject fo = fs.findResource(name);
149
150             if (fo != null) {
151                 v.addElement(fo);
152             }
153         }
154
155         return v.elements();
156     }
157
158     /** Finds file when its name is provided. It scans in the list of
159     * filesystems and asks them for the specified file by a call to
160     * {@link FileSystem#find find}. The first object that is found is returned or <CODE>null</CODE>
161     * if none of the filesystems contain such a file.
162     *
163     * @param aPackage package name where each package is separated by a dot
164     * @param name name of the file (without dots) or <CODE>null</CODE> if
165     * one wants to obtain the name of a package and not a file in it
166     * @param ext extension of the file or <CODE>null</CODE> if one needs
167     * a package and not a file name
168     *
169     * @return {@link FileObject} that represents file with given name or
170     * <CODE>null</CODE> if the file does not exist
171     * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
172     */

173     @Deprecated JavaDoc
174     public final FileObject find(String JavaDoc aPackage, String JavaDoc name, String JavaDoc ext) {
175         Enumeration JavaDoc<? extends FileSystem> en = fileSystems();
176
177         while (en.hasMoreElements()) {
178             FileSystem fs = en.nextElement();
179             FileObject fo = fs.find(aPackage, name, ext);
180
181             if (fo != null) {
182                 // object found
183
return fo;
184             }
185         }
186
187         return null;
188     }
189
190     /** Finds all files among all filesystems with this capability
191     * that match a given name, returning all matches.
192     * All filesystems are queried with {@link FileSystem#find}.
193     *
194     * @param aPackage package name where each package is separated by a dot
195     * @param name name of the file (without dots) or <CODE>null</CODE> if
196     * one wants to obtain the name of a package and not a file in it
197     * @param ext extension of the file or <CODE>null</CODE> if one needs
198     * a package and not a file name
199     *
200     * @return enumeration of {@link FileObject}s
201     * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
202     */

203     @Deprecated JavaDoc
204     public final Enumeration JavaDoc<? extends FileObject> findAll(String JavaDoc aPackage, String JavaDoc name, String JavaDoc ext) {
205         Enumeration JavaDoc<? extends FileSystem> en = fileSystems();
206         Vector JavaDoc<FileObject> ret = new Vector JavaDoc<FileObject>();
207
208         while (en.hasMoreElements()) {
209             FileSystem fs = (FileSystem) en.nextElement();
210             FileObject fo = fs.find(aPackage, name, ext);
211
212             if (fo != null) {
213                 ret.addElement(fo);
214             }
215         }
216
217         return ret.elements();
218     }
219
220     /** Adds PropertyChange listener. Every class which implements changes of capabilities
221     * has to implement it's property change support.
222     * @param l the listener to be added.
223     */

224     public synchronized void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
225     }
226
227     /** Removes PropertyChange listener. Every class which implements changes of capabilities
228     * has to implement it's property change support.
229     * @param l the listener to be removed.
230     */

231     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
232     }
233
234     /** Default implementation of capabilities, that behaves like
235     * JavaBean and allows to set whether the well known
236     * capabilities (like compile, execute) should be enabled
237     * or not.
238      * @deprecated For the same reason the whole class is.
239     */

240     @Deprecated JavaDoc
241     public static class Bean extends FileSystemCapability implements java.io.Serializable JavaDoc {
242         static final long serialVersionUID = 627905674809532736L;
243
244         /** change listeners */
245         private transient PropertyChangeSupport JavaDoc supp;
246
247         /** compilation */
248         private boolean compilation = true;
249
250         /** execution */
251         private boolean execution = true;
252
253         /** debugging */
254         private boolean debug = true;
255
256         /** doc */
257         private boolean doc = false;
258
259         /** Checks for well known capabilities and if they are allowed.
260         *
261         * @param c capability to test
262         * @return true if yes
263         */

264         public boolean capableOf(FileSystemCapability c) {
265             if (c == COMPILE) {
266                 return compilation;
267             }
268
269             if (c == EXECUTE) {
270                 return execution;
271             }
272
273             if (c == DEBUG) {
274                 return debug;
275             }
276
277             if (c == DOC) {
278                 return doc;
279             }
280
281             if (c == ALL) {
282                 return true;
283             }
284
285             if (!(c instanceof Bean)) {
286                 return false;
287             }
288
289             // try match of values
290
Bean b = (Bean) c;
291
292             return (compilation == b.compilation) && (execution == b.execution) && (debug == b.debug) &&
293             (doc == b.doc);
294         }
295
296         /** Getter for value of compiling capability.
297          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
298         */

299         @Deprecated JavaDoc
300         public boolean getCompile() {
301             return compilation;
302         }
303
304         /** Setter for allowing compiling capability.
305          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
306         */

307         @Deprecated JavaDoc
308         public void setCompile(boolean val) {
309             if (val != compilation) {
310                 compilation = val;
311
312                 if (supp != null) {
313                     supp.firePropertyChange(
314                         "compile", // NOI18N
315
(!val) ? Boolean.TRUE : Boolean.FALSE, val ? Boolean.TRUE : Boolean.FALSE
316                     );
317                 }
318             }
319         }
320
321         /** Getter for value of executiong capability.
322          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
323         */

324         @Deprecated JavaDoc
325         public boolean getExecute() {
326             return execution;
327         }
328
329         /** Setter for allowing executing capability.
330          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
331         */

332         @Deprecated JavaDoc
333         public void setExecute(boolean val) {
334             if (val != execution) {
335                 execution = val;
336
337                 if (supp != null) {
338                     supp.firePropertyChange(
339                         "execute", // NOI18N
340
(!val) ? Boolean.TRUE : Boolean.FALSE, val ? Boolean.TRUE : Boolean.FALSE
341                     );
342                 }
343             }
344         }
345
346         /** Getter for value of debugging capability.
347          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
348         */

349         @Deprecated JavaDoc
350         public boolean getDebug() {
351             return debug;
352         }
353
354         /** Setter for allowing debugging capability.
355          * @deprecated Please use the <a HREF="@org-netbeans-api-java@/org/netbeans/api/java/classpath/ClassPath.html">ClassPath API</a> instead.
356         */

357         @Deprecated JavaDoc
358         public void setDebug(boolean val) {
359             if (val != debug) {
360                 debug = val;
361
362                 if (supp != null) {
363                     supp.firePropertyChange(
364                         "debug", // NOI18N
365
(!val) ? Boolean.TRUE : Boolean.FALSE, val ? Boolean.TRUE : Boolean.FALSE
366                     );
367                 }
368             }
369         }
370
371         /** Getter for value of doc capability.
372          * @deprecated Please use <a HREF="@org-netbeans-api-java@/org/netbeans/api/queries/JavadocForBinaryQuery.html"><code>JavadocForBinaryQuery</code></a> instead.
373         */

374         @Deprecated JavaDoc
375         public boolean getDoc() {
376             return doc;
377         }
378
379         /** Setter for allowing debugging capability.
380          * @deprecated Please use <a HREF="@org-netbeans-api-java@/org/netbeans/api/queries/JavadocForBinaryQuery.html"><code>JavadocForBinaryQuery</code></a> instead.
381         */

382         @Deprecated JavaDoc
383         public void setDoc(boolean val) {
384             if (val != doc) {
385                 doc = val;
386
387                 if (supp != null) {
388                     supp.firePropertyChange(
389                         "doc", // NOI18N
390
(!val) ? Boolean.TRUE : Boolean.FALSE, val ? Boolean.TRUE : Boolean.FALSE
391                     );
392                 }
393             }
394         }
395
396         public synchronized void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
397             if (supp == null) {
398                 supp = new PropertyChangeSupport JavaDoc(this);
399             }
400
401             supp.addPropertyChangeListener(l);
402         }
403
404         public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
405             if (supp != null) {
406                 supp.removePropertyChangeListener(l);
407             }
408         }
409     }
410 }
411
Popular Tags