001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.api.queries;
043:
044: import java.io.File;
045: import org.netbeans.spi.queries.SharabilityQueryImplementation;
046: import org.openide.filesystems.FileUtil;
047: import org.openide.util.Lookup;
048:
049: // XXX perhaps should be in the Filesystems API instead of here?
050:
051: /**
052: * Determine whether files should be shared (for example in a VCS) or are intended
053: * to be unshared.
054: * Likely to be of use only to a VCS filesystem.
055: * <p>
056: * This query can be considered to obsolete {@link org.openide.filesystems.FileObject#setImportant}.
057: * Unlike that method, the information is pulled by the VCS filesystem on
058: * demand, which may be more reliable than ensuring that the information
059: * is pushed by a project type (or other implementor) eagerly.
060: * @see SharabilityQueryImplementation
061: * @author Jesse Glick
062: */
063: public final class SharabilityQuery {
064:
065: private static final Lookup.Result<SharabilityQueryImplementation> implementations = Lookup
066: .getDefault().lookupResult(
067: SharabilityQueryImplementation.class);
068:
069: /**
070: * Constant indicating that nothing is known about whether a given
071: * file should be considered sharable or not.
072: * A client should therefore behave in the safest way it can.
073: */
074: public static final int UNKNOWN = 0;
075:
076: /**
077: * Constant indicating that the file or directory is sharable.
078: * In the case of a directory, this means that all files and
079: * directories recursively contained in this directory are also
080: * sharable.
081: */
082: public static final int SHARABLE = 1;
083:
084: /**
085: * Constant indicating that the file or directory is not sharable.
086: * In the case of a directory, this means that all files and
087: * directories recursively contained in this directory are also
088: * not sharable.
089: */
090: public static final int NOT_SHARABLE = 2;
091:
092: /**
093: * Constant indicating that a directory is sharable but files and
094: * directories recursively contained in it may or may not be sharable.
095: * A client interested in children of this directory should explicitly
096: * ask about each in turn.
097: */
098: public static final int MIXED = 3;
099:
100: private SharabilityQuery() {
101: }
102:
103: /**
104: * Check whether an existing file is sharable.
105: * @param file a file or directory (may or may not already exist)
106: * @return one of the constants in this class
107: */
108: public static int getSharability(File file) {
109: if (file == null)
110: throw new IllegalArgumentException();
111: assert file.equals(FileUtil.normalizeFile(file)) : "Must pass a normalized file: "
112: + file;
113: for (SharabilityQueryImplementation sqi : implementations
114: .allInstances()) {
115: int x = sqi.getSharability(file);
116: if (x != UNKNOWN) {
117: return x;
118: }
119: }
120: return UNKNOWN;
121: }
122:
123: }
|