alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.api.queries;

import java.io.File;
import java.util.Iterator;
import org.netbeans.spi.queries.SharabilityQueryImplementation;
import org.openide.filesystems.FileUtil;
import org.openide.util.Lookup;

// XXX perhaps should be in the Filesystems API instead of here?

/**
 * Determine whether files should be shared (for example in a VCS) or are intended
 * to be unshared.
 * Likely to be of use only to a VCS filesystem.
 * 

* This query can be considered to obsolete {@link org.openide.filesystems.FileObject#setImportant}. * Unlike that method, the information is pulled by the VCS filesystem on * demand, which may be more reliable than ensuring that the information * is pushed by a project type (or other implementor) eagerly. * @see SharabilityQueryImplementation * @author Jesse Glick */ public final class SharabilityQuery { private static final Lookup.Result/**/ implementations = Lookup.getDefault().lookup(new Lookup.Template(SharabilityQueryImplementation.class)); /** * Constant indicating that nothing is known about whether a given * file should be considered sharable or not. * A client should therefore behave in the safest way it can. */ public static final int UNKNOWN = 0; /** * Constant indicating that the file or directory is sharable. * In the case of a directory, this means that all files and * directories recursively contained in this directory are also * sharable. */ public static final int SHARABLE = 1; /** * Constant indicating that the file or directory is not sharable. * In the case of a directory, this means that all files and * directories recursively contained in this directory are also * not sharable. */ public static final int NOT_SHARABLE = 2; /** * Constant indicating that a directory is sharable but files and * directories recursively contained in it may or may not be sharable. * A client interested in children of this directory should explicitly * ask about each in turn. */ public static final int MIXED = 3; private SharabilityQuery() {} /** * Check whether an existing file is sharable. * @param file a file or directory (may or may not already exist) * @return one of the constants in this class */ public static int getSharability(File file) { if (file == null) throw new IllegalArgumentException(); File normFile = FileUtil.normalizeFile(file); Iterator it = implementations.allInstances().iterator(); while (it.hasNext()) { SharabilityQueryImplementation sqi = (SharabilityQueryImplementation)it.next(); int x = sqi.getSharability(normFile); if (x != UNKNOWN) { return x; } } return UNKNOWN; } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.