站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 5.5.0

ProjectManager (NetBeans Project API) - NetBeans API Javadoc 5.5.0

org.netbeans.modules.projectapi/1 1.9.22

org.netbeans.api.project
Class ProjectManager

java.lang.Object
  extended by org.netbeans.api.project.ProjectManager

public final class ProjectManager
extends Object

Manages loaded projects.


Method Summary
 void clearNonProjectCache()
          Clear the cached list of folders thought not to be projects.
 Project findProject(FileObject projectDirectory)
          Find an open project corresponding to a given project directory.
static ProjectManager getDefault()
          Returns the singleton project manager instance.
 Set getModifiedProjects()
          Get a list of all projects which are modified and need to be saved.
 boolean isModified(Project p)
          Check whether a given project is current modified.
 boolean isProject(FileObject projectDirectory)
          Check whether a given directory is likely to contain a project without actually loading it.
 boolean isValid(Project p)
          Check whether a given project is still valid (ie.
static Mutex mutex()
          Get a read/write lock to be used for all project metadata accesses.
 void saveAllProjects()
          Save all modified projects.
 void saveProject(Project p)
          Save one project (if it was in fact modified).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDefault

public static ProjectManager getDefault()
Returns the singleton project manager instance.


mutex

public static Mutex mutex()
Get a read/write lock to be used for all project metadata accesses. All methods relating to recognizing and loading projects, saving them, getting or setting their metadata, etc. should be controlled by this mutex and be marked as read operations or write operations. Unless otherwise stated, project-related methods automatically acquire the mutex for you, so you do not necessarily need to pay attention to it; but you may directly acquire the mutex in order to ensure that a block of reads does not have any interspersed writes, or in order to ensure that a write is not clobbering an unrelated write, etc.

Returns:
a general read/write lock for project metadata operations of all sorts

findProject

public Project findProject(FileObject projectDirectory)
                    throws IOException,
                           IllegalArgumentException
Find an open project corresponding to a given project directory. Will be created in memory if necessary.

Acquires read access.

It is not guaranteed that the returned instance will be identical to that which is created by the appropriate ProjectFactory. In particular, the project manager is free to return only wrapper Project instances which delegate to the factory's implementation. If you know your factory created a particular project, you cannot safely cast the return value of this method to your project type implementation class; you should instead place an implementation of some suitable private interface into your project's lookup, which would be safely proxied.

Parameters:
projectDirectory - the project top directory
Returns:
the project (object identity may or may not vary between calls) or null if the directory is not recognized as a project by any registered ProjectFactory (might be null even if isProject(org.openide.filesystems.FileObject) returns true)
Throws:
IOException - if the project was recognized but could not be loaded
IllegalArgumentException - if the supplied file object is null or not a folder

isProject

public boolean isProject(FileObject projectDirectory)
                  throws IllegalArgumentException
Check whether a given directory is likely to contain a project without actually loading it. Should be faster and use less memory than findProject(org.openide.filesystems.FileObject) when called on a large number of directories.

The result is not guaranteed to be accurate; there may be false positives (directories for which isProject is true but findProject(org.openide.filesystems.FileObject) will return false), for example if there is trouble loading the project. False negatives are possible only if there are bugs in the project factory.

Acquires read access.

You do not need to call this method if you just plan to call findProject(org.openide.filesystems.FileObject) afterwards. It is intended for only those clients which would discard the result of findProject(org.openide.filesystems.FileObject) other than to check for null, and which can also tolerate false positives.

Parameters:
projectDirectory - a directory which may be some project's top directory
Returns:
true if the directory is likely to contain a project according to some registered ProjectFactory
Throws:
IllegalArgumentException - if the supplied file object is null or not a folder

clearNonProjectCache

public void clearNonProjectCache()
Clear the cached list of folders thought not to be projects. This may be useful after creating project metadata in a folder, etc. Cached project objects, i.e. folders that are known to be projects, are not affected.


getModifiedProjects

public Set getModifiedProjects()
Get a list of all projects which are modified and need to be saved.

Acquires read access.

Returns:
an immutable set of Projects

isModified

public boolean isModified(Project p)
                   throws IllegalArgumentException
Check whether a given project is current modified.

Acquires read access.

Parameters:
p - a project loaded by this manager
Throws:
IllegalArgumentException - if the project was not created through this manager

saveProject

public void saveProject(Project p)
                 throws IOException,
                        IllegalArgumentException
Save one project (if it was in fact modified).

Acquires write access.

Although the project infrastructure permits a modified project to be saved at any time, current UI principles dictate that the "save project" concept should be internal only - i.e. a project customizer should automatically save the project when it is closed e.g. with an "OK" button. Currently there is no UI display of modified projects; this module does not ensure that modified projects are saved at system exit time the way modified files are, though the Project UI implementation module currently does this check.

Parameters:
p - the project to save
Throws:
IOException - if it cannot be saved
IllegalArgumentException - if the project was not created through this manager

saveAllProjects

public void saveAllProjects()
                     throws IOException
Save all modified projects.

Acquires write access.

Throws:
IOException - if any of them cannot be saved

isValid

public boolean isValid(Project p)
Check whether a given project is still valid (ie. not deleted).

Acquires read access.

Parameters:
p - a project loaded by this manager
Since:
1.6

org.netbeans.modules.projectapi/1 1.9.22

Built on May 28 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.