KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > queries > SharabilityQuery


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.netbeans.api.queries;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.spi.queries.SharabilityQueryImplementation;
24 import org.openide.filesystems.FileUtil;
25 import org.openide.util.Lookup;
26
27 // XXX perhaps should be in the Filesystems API instead of here?
28

29 /**
30  * Determine whether files should be shared (for example in a VCS) or are intended
31  * to be unshared.
32  * Likely to be of use only to a VCS filesystem.
33  * <p>
34  * This query can be considered to obsolete {@link org.openide.filesystems.FileObject#setImportant}.
35  * Unlike that method, the information is pulled by the VCS filesystem on
36  * demand, which may be more reliable than ensuring that the information
37  * is pushed by a project type (or other implementor) eagerly.
38  * @see SharabilityQueryImplementation
39  * @author Jesse Glick
40  */

41 public final class SharabilityQuery {
42     
43     private static final Lookup.Result<SharabilityQueryImplementation> implementations =
44         Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class);
45
46     /**
47      * Constant indicating that nothing is known about whether a given
48      * file should be considered sharable or not.
49      * A client should therefore behave in the safest way it can.
50      */

51     public static final int UNKNOWN = 0;
52     
53     /**
54      * Constant indicating that the file or directory is sharable.
55      * In the case of a directory, this means that all files and
56      * directories recursively contained in this directory are also
57      * sharable.
58      */

59     public static final int SHARABLE = 1;
60     
61     /**
62      * Constant indicating that the file or directory is not sharable.
63      * In the case of a directory, this means that all files and
64      * directories recursively contained in this directory are also
65      * not sharable.
66      */

67     public static final int NOT_SHARABLE = 2;
68     
69     /**
70      * Constant indicating that a directory is sharable but files and
71      * directories recursively contained in it may or may not be sharable.
72      * A client interested in children of this directory should explicitly
73      * ask about each in turn.
74      */

75     public static final int MIXED = 3;
76     
77     private SharabilityQuery() {}
78     
79     /**
80      * Check whether an existing file is sharable.
81      * @param file a file or directory (may or may not already exist)
82      * @return one of the constants in this class
83      */

84     public static int getSharability(File JavaDoc file) {
85         if (file == null) throw new IllegalArgumentException JavaDoc();
86         File JavaDoc normFile = FileUtil.normalizeFile(file);
87         for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
88             int x = sqi.getSharability(normFile);
89             if (x != UNKNOWN) {
90                 return x;
91             }
92         }
93         return UNKNOWN;
94     }
95     
96 }
97
Popular Tags